5
5
*/
6
6
7
7
import { useContext , useEffect , useState } from "react" ;
8
- import { Project , Team , WhitelistedRepository , Workspace , WorkspaceInfo } from "@gitpod/gitpod-protocol" ;
8
+ import { WhitelistedRepository , Workspace , WorkspaceInfo } from "@gitpod/gitpod-protocol" ;
9
9
import Header from "../components/Header" ;
10
10
import DropDown from "../components/DropDown" ;
11
11
import { WorkspaceModel } from "./workspace-model" ;
@@ -15,8 +15,6 @@ import { StartWorkspaceModal, WsStartEntry } from "./StartWorkspaceModal";
15
15
import { ItemsList } from "../components/ItemsList" ;
16
16
import { getCurrentTeam , TeamsContext } from "../teams/teams-context" ;
17
17
import { useLocation , useRouteMatch } from "react-router" ;
18
- import { toRemoteURL } from "../projects/render-utils" ;
19
- import { Link , useHistory } from "react-router-dom" ;
20
18
21
19
export interface WorkspacesProps {
22
20
}
@@ -29,64 +27,24 @@ export interface WorkspacesState {
29
27
30
28
export default function ( ) {
31
29
const location = useLocation ( ) ;
32
- const history = useHistory ( ) ;
33
30
34
31
const { teams } = useContext ( TeamsContext ) ;
35
32
const team = getCurrentTeam ( location , teams ) ;
36
33
const match = useRouteMatch < { team : string , resource : string } > ( "/(t/)?:team/:resource" ) ;
37
34
const projectSlug = match ?. params ?. resource !== 'workspaces' ? match ?. params ?. resource : undefined ;
38
- const [ projects , setProjects ] = useState < Project [ ] > ( [ ] ) ;
39
35
const [ activeWorkspaces , setActiveWorkspaces ] = useState < WorkspaceInfo [ ] > ( [ ] ) ;
40
36
const [ inactiveWorkspaces , setInactiveWorkspaces ] = useState < WorkspaceInfo [ ] > ( [ ] ) ;
41
37
const [ repos , setRepos ] = useState < WhitelistedRepository [ ] > ( [ ] ) ;
42
38
const [ isTemplateModelOpen , setIsTemplateModelOpen ] = useState < boolean > ( false ) ;
43
39
const [ workspaceModel , setWorkspaceModel ] = useState < WorkspaceModel > ( ) ;
44
- const [ teamsProjects , setTeamsProjects ] = useState < Project [ ] > ( [ ] ) ;
45
- const [ teamsWorkspaceModel , setTeamsWorkspaceModel ] = useState < WorkspaceModel | undefined > ( ) ;
46
- const [ teamsActiveWorkspaces , setTeamsActiveWorkspaces ] = useState < WorkspaceInfo [ ] > ( [ ] ) ;
47
-
48
- const newProjectUrl = ! ! team ? `/new?team=${ team . slug } ` : '/new?user=1' ;
49
- const onNewProject = ( ) => {
50
- history . push ( newProjectUrl ) ;
51
- }
52
-
53
- const fetchTeamsProjects = async ( ) => {
54
- const projectsPerTeam = await Promise . all ( ( teams || [ ] ) . map ( t => getGitpodService ( ) . server . getTeamProjects ( t . id ) ) ) ;
55
- const allTeamsProjects = projectsPerTeam . flat ( 1 ) ;
56
- setTeamsProjects ( allTeamsProjects ) ;
57
- return allTeamsProjects ;
58
- }
59
40
60
41
useEffect ( ( ) => {
61
42
// only show example repos on the global user context
62
43
if ( ! team && ! projectSlug ) {
63
44
getGitpodService ( ) . server . getFeaturedRepositories ( ) . then ( setRepos ) ;
64
45
}
65
46
( async ( ) => {
66
- const projects = ( ! ! team
67
- ? await getGitpodService ( ) . server . getTeamProjects ( team . id )
68
- : await getGitpodService ( ) . server . getUserProjects ( ) ) ;
69
-
70
- let project : Project | undefined = undefined ;
71
- if ( projectSlug ) {
72
- project = projects . find ( p => p . slug ? p . slug === projectSlug : p . name === projectSlug ) ;
73
- if ( project ) {
74
- setProjects ( [ project ] ) ;
75
- }
76
- } else {
77
- setProjects ( projects ) ;
78
- }
79
- let workspaceModel ;
80
- if ( ! ! project ) {
81
- workspaceModel = new WorkspaceModel ( setActiveWorkspaces , setInactiveWorkspaces , Promise . resolve ( [ project . id ] ) , false ) ;
82
- } else if ( ! ! team ) {
83
- workspaceModel = new WorkspaceModel ( setActiveWorkspaces , setInactiveWorkspaces , getGitpodService ( ) . server . getTeamProjects ( team ?. id ) . then ( projects => projects . map ( p => p . id ) ) , false ) ;
84
- } else {
85
- workspaceModel = new WorkspaceModel ( setActiveWorkspaces , setInactiveWorkspaces , getGitpodService ( ) . server . getUserProjects ( ) . then ( projects => projects . map ( p => p . id ) ) , true ) ;
86
- // Don't await
87
- const teamsProjectIdsPromise = fetchTeamsProjects ( ) . then ( tp => tp . map ( p => p . id ) ) ;
88
- setTeamsWorkspaceModel ( new WorkspaceModel ( setTeamsActiveWorkspaces , ( ) => { } , teamsProjectIdsPromise , false ) ) ;
89
- }
47
+ const workspaceModel = new WorkspaceModel ( setActiveWorkspaces , setInactiveWorkspaces ) ;
90
48
setWorkspaceModel ( workspaceModel ) ;
91
49
} ) ( ) ;
92
50
} , [ teams , location ] ) ;
@@ -95,16 +53,6 @@ export default function () {
95
53
const hideStartWSModal = ( ) => setIsTemplateModelOpen ( false ) ;
96
54
97
55
const getRecentSuggestions : ( ) => WsStartEntry [ ] = ( ) => {
98
- if ( projectSlug || team ) {
99
- return projects . map ( p => {
100
- const remoteUrl = toRemoteURL ( p . cloneUrl ) ;
101
- return {
102
- title : ( team ? team . name + '/' : '' ) + p . name ,
103
- description : remoteUrl ,
104
- startUrl : gitpodHostUrl . withContext ( remoteUrl ) . toString ( )
105
- } ;
106
- } ) ;
107
- }
108
56
if ( workspaceModel ) {
109
57
const all = workspaceModel . getAllFetchedWorkspaces ( ) ;
110
58
if ( all && all . size > 0 ) {
@@ -169,9 +117,6 @@ export default function () {
169
117
</ div >
170
118
< ItemsList className = "app-container pb-40" >
171
119
< div className = "border-t border-gray-200 dark:border-gray-800" > </ div >
172
- {
173
- teamsWorkspaceModel ?. initialized && < ActiveTeamWorkspaces teams = { teams } teamProjects = { teamsProjects } teamWorkspaces = { teamsActiveWorkspaces } />
174
- }
175
120
{
176
121
activeWorkspaces . map ( e => {
177
122
return < WorkspaceEntry key = { e . workspace . id } desc = { e } model = { workspaceModel } stopWorkspace = { wsId => getGitpodService ( ) . server . stopWorkspace ( wsId ) } />
@@ -193,23 +138,14 @@ export default function () {
193
138
:
194
139
< div className = "app-container flex flex-col space-y-2" >
195
140
< div className = "px-6 py-3 flex flex-col text-gray-400 border-t border-gray-200 dark:border-gray-800" >
196
- { teamsWorkspaceModel ?. initialized && < ActiveTeamWorkspaces teams = { teams } teamProjects = { teamsProjects } teamWorkspaces = { teamsActiveWorkspaces } /> }
197
141
< div className = "flex flex-col items-center justify-center h-96 w-96 mx-auto" >
198
- { ! ! team && projects . length === 0
199
- ?< >
200
- < h3 className = "text-center pb-3 text-gray-500 dark:text-gray-400" > No Projects</ h3 >
201
- < div className = "text-center pb-6 text-gray-500" > This team doesn't have any projects, yet.</ div >
202
- < span >
203
- < button onClick = { onNewProject } > New Project</ button >
204
- </ span >
205
- </ >
206
- :< >
142
+ < >
207
143
< h3 className = "text-center pb-3 text-gray-500 dark:text-gray-400" > No Workspaces</ h3 >
208
144
< div className = "text-center pb-6 text-gray-500" > Prefix any Git repository URL with { window . location . host } /# or create a new workspace for a recently used project. < a className = "gp-link" href = "https://www.gitpod.io/docs/getting-started/" > Learn more</ a > </ div >
209
145
< span >
210
146
< button onClick = { showStartWSModal } > New Workspace</ button >
211
147
</ span >
212
- </ > }
148
+ </ >
213
149
</ div >
214
150
</ div >
215
151
</ div >
@@ -229,25 +165,3 @@ export default function () {
229
165
230
166
}
231
167
232
- function ActiveTeamWorkspaces ( props : { teams ?: Team [ ] , teamProjects : Project [ ] , teamWorkspaces : WorkspaceInfo [ ] } ) {
233
- if ( ! props . teams || props . teamWorkspaces . length === 0 ) {
234
- return < > </ > ;
235
- }
236
- return < div className = "p-3 text-gray-400 bg-gray-50 dark:bg-gray-800 rounded-xl text-sm flex items-center justify-center space-x-1" >
237
- < div className = "mr-2 rounded-full w-3 h-3 bg-green-500" />
238
- < span > There are currently more active workspaces in the following teams:</ span >
239
- < span > {
240
- props . teams
241
- . map ( t => {
242
- const projects = props . teamProjects . filter ( p => p . teamId === t . id ) ;
243
- const count = props . teamWorkspaces . filter ( w => projects . some ( p => p . id === w . workspace . projectId ) ) . length ;
244
- if ( count < 1 ) {
245
- return undefined ;
246
- }
247
- return < Link className = "gp-link" to = { `/t/${ t . slug } /workspaces` } > { t . name } </ Link > ;
248
- } )
249
- . filter ( t => ! ! t )
250
- . map ( ( t , i ) => < > { i > 0 && < span > , </ span > } { t } </ > )
251
- } </ span >
252
- </ div > ;
253
- }
0 commit comments