@@ -81,6 +81,54 @@ function addProjectsToTeams(teams: Team[], projects: Project[]): TeamWithProject
81
81
} ) ) ;
82
82
}
83
83
84
+ function getFilteredProjectsBasedOnTeams ( {
85
+ allTeams,
86
+ userTeams,
87
+ selectedTeams,
88
+ isAllTeams,
89
+ showNonMemberProjects,
90
+ projects,
91
+ projectQuery,
92
+ } : {
93
+ allTeams : Team [ ] ;
94
+ isAllTeams : boolean ;
95
+ projectQuery : string ;
96
+ projects : Project [ ] ;
97
+ selectedTeams : string [ ] ;
98
+ showNonMemberProjects : boolean ;
99
+ userTeams : Team [ ] ;
100
+ } ) : Project [ ] {
101
+ const myTeamIds = new Set ( userTeams . map ( team => team . id ) ) ;
102
+ const includeMyTeams = isAllTeams || selectedTeams . includes ( 'myteams' ) ;
103
+ const selectedOtherTeamIds = new Set (
104
+ selectedTeams . filter ( teamId => teamId !== 'myteams' )
105
+ ) ;
106
+ const myTeams = includeMyTeams ? allTeams . filter ( team => myTeamIds . has ( team . id ) ) : [ ] ;
107
+ const otherTeams = isAllTeams
108
+ ? allTeams
109
+ : allTeams . filter ( team => selectedOtherTeamIds . has ( String ( team . id ) ) ) ;
110
+
111
+ const visibleTeams = [ ...myTeams , ...otherTeams ] . filter ( team => {
112
+ if ( showNonMemberProjects ) {
113
+ return true ;
114
+ }
115
+ return team . isMember ;
116
+ } ) ;
117
+ const teamsWithProjects = addProjectsToTeams ( visibleTeams , projects ) ;
118
+ const currentProjects = uniqBy (
119
+ teamsWithProjects . flatMap ( team => team . projects ) ,
120
+ 'id'
121
+ ) ;
122
+ const currentProjectIds = new Set ( currentProjects . map ( p => p . id ) ) ;
123
+ const unassignedProjects =
124
+ isAllTeams && showNonMemberProjects
125
+ ? projects . filter ( project => ! currentProjectIds . has ( project . id ) )
126
+ : [ ] ;
127
+ return [ ...currentProjects , ...unassignedProjects ] . filter ( project =>
128
+ project . slug . includes ( projectQuery )
129
+ ) ;
130
+ }
131
+
84
132
function Dashboard ( ) {
85
133
const navigate = useNavigate ( ) ;
86
134
const location = useLocation ( ) ;
@@ -123,33 +171,18 @@ function Dashboard() {
123
171
return < LoadingError message = { t ( 'An error occurred while fetching your projects' ) } /> ;
124
172
}
125
173
126
- const includeMyTeams = isAllTeams || selectedTeams . includes ( 'myteams' ) ;
127
- const hasOtherTeams = selectedTeams . some ( team => team !== 'myteams' ) ;
128
- const myTeams = includeMyTeams ? userTeams : [ ] ;
129
- const otherTeams = isAllTeams
130
- ? allTeams
131
- : hasOtherTeams
132
- ? allTeams . filter ( team => selectedTeams . includes ( `${ team . id } ` ) )
133
- : [ ] ;
134
- const filteredTeams = [ ...myTeams , ...otherTeams ] . filter ( team => {
135
- if ( showNonMemberProjects ) {
136
- return true ;
137
- }
138
-
139
- return team . isMember ;
174
+ const filteredProjects = getFilteredProjectsBasedOnTeams ( {
175
+ allTeams,
176
+ userTeams,
177
+ selectedTeams,
178
+ isAllTeams,
179
+ showNonMemberProjects,
180
+ projects,
181
+ projectQuery,
140
182
} ) ;
141
- const filteredTeamsWithProjects = addProjectsToTeams ( filteredTeams , projects ) ;
142
183
143
- const currentProjects = uniqBy (
144
- filteredTeamsWithProjects . flatMap ( team => team . projects ) ,
145
- 'id'
146
- ) ;
147
184
setGroupedEntityTag ( 'projects.total' , 1000 , projects . length ) ;
148
185
149
- const filteredProjects = currentProjects . filter ( project =>
150
- project . slug . includes ( projectQuery )
151
- ) ;
152
-
153
186
const showResources = projects . length === 1 && ! projects [ 0 ] ! . firstEvent ;
154
187
155
188
const canJoinTeam = organization . access . includes ( 'team:read' ) ;
0 commit comments