@@ -5,7 +5,7 @@ import Link from "next/link"
5
5
import { useRouter } from "next/router"
6
6
import useSWR from "swr"
7
7
8
- import { Project , Workspace } from "../../../../api"
8
+ import { Organization , Project , Workspace } from "../../../../api"
9
9
import { Header } from "../../../../components/Header"
10
10
import { FullScreenLoader } from "../../../../components/Loader/FullScreenLoader"
11
11
import { Navbar } from "../../../../components/Navbar"
@@ -15,21 +15,32 @@ import { useUser } from "../../../../contexts/UserContext"
15
15
import { ErrorSummary } from "../../../../components/ErrorSummary"
16
16
import { firstOrItem } from "../../../../util/array"
17
17
import { EmptyState } from "../../../../components/EmptyState"
18
+ import { unsafeSWRArgument } from "../../../../util"
18
19
19
20
const ProjectPage : React . FC = ( ) => {
20
21
const styles = useStyles ( )
21
22
const { me, signOut } = useUser ( true )
22
23
23
24
const router = useRouter ( )
24
- const { project, organization } = router . query
25
+ const { project : projectName , organization : organizationName } = router . query
25
26
26
- const { data : projectInfo , error : projectError } = useSWR < Project , Error > (
27
- ( ) => `/api/v2/projects/ ${ organization } / ${ project } ` ,
27
+ const { data : organizationInfo , error : organizationError } = useSWR < Organization , Error > (
28
+ ( ) => `/api/v2/users/me/organizations/ ${ organizationName } ` ,
28
29
)
29
- const { data : workspaces , error : workspacesError } = useSWR < Workspace [ ] , Error > (
30
- ( ) => `/api/v2/projects/${ organization } /${ project } /workspaces` ,
30
+
31
+ const { data : projectInfo , error : projectError } = useSWR < Project , Error > (
32
+ ( ) => `/api/v2/organizations/${ unsafeSWRArgument ( organizationInfo ) . id } /projects/${ projectName } ` ,
31
33
)
32
34
35
+ // TODO: The workspaces endpoint was recently changed, so that we can't get
36
+ // workspaces per-project. This just grabs all workspaces... and then
37
+ // later filters them to match the current project.
38
+ const { data : workspaces , error : workspacesError } = useSWR < Workspace [ ] , Error > ( ( ) => `/api/v2/users/me/workspaces` )
39
+
40
+ if ( organizationError ) {
41
+ return < ErrorSummary error = { organizationError } />
42
+ }
43
+
33
44
if ( projectError ) {
34
45
return < ErrorSummary error = { projectError } />
35
46
}
@@ -43,7 +54,7 @@ const ProjectPage: React.FC = () => {
43
54
}
44
55
45
56
const createWorkspace = ( ) => {
46
- void router . push ( `/projects/${ organization } /${ project } /create` )
57
+ void router . push ( `/projects/${ organizationName } /${ projectName } /create` )
47
58
}
48
59
49
60
const emptyState = (
@@ -61,26 +72,30 @@ const ProjectPage: React.FC = () => {
61
72
{
62
73
key : "name" ,
63
74
name : "Name" ,
64
- renderer : ( nameField : string ) => {
65
- return < Link href = { `/workspaces/me/ ${ nameField } ` } > { nameField } </ Link >
75
+ renderer : ( nameField : string , workspace : Workspace ) => {
76
+ return < Link href = { `/workspaces/${ workspace . id } ` } > { nameField } </ Link >
66
77
} ,
67
78
} ,
68
79
]
69
80
81
+ const perProjectWorkspaces = workspaces . filter ( ( workspace ) => {
82
+ return workspace . project_id === projectInfo . id
83
+ } )
84
+
70
85
const tableProps = {
71
86
title : "Workspaces" ,
72
87
columns,
73
- data : workspaces ,
88
+ data : perProjectWorkspaces ,
74
89
emptyState : emptyState ,
75
90
}
76
91
77
92
return (
78
93
< div className = { styles . root } >
79
94
< Navbar user = { me } onSignOut = { signOut } />
80
95
< Header
81
- title = { firstOrItem ( project , "" ) }
82
- description = { firstOrItem ( organization , "" ) }
83
- subTitle = { `${ workspaces . length } workspaces` }
96
+ title = { firstOrItem ( projectName , "" ) }
97
+ description = { firstOrItem ( organizationName , "" ) }
98
+ subTitle = { `${ perProjectWorkspaces . length } workspaces` }
84
99
action = { {
85
100
text : "Create Workspace" ,
86
101
onClick : createWorkspace ,
0 commit comments