1
- import Box from "@material-ui/core/Box"
2
- import Button from "@material-ui/core/Button"
3
- import Table from "@material-ui/core/Table"
4
- import TableBody from "@material-ui/core/TableBody"
5
- import TableCell from "@material-ui/core/TableCell"
6
- import TableHead from "@material-ui/core/TableHead"
7
- import TableRow from "@material-ui/core/TableRow"
8
1
import React from "react"
9
- import { Link , useNavigate , useParams } from "react-router-dom"
2
+ import { useNavigate , useParams } from "react-router-dom"
10
3
import useSWR from "swr"
11
4
import * as TypesGen from "../../../../api/typesGenerated"
12
- import { EmptyState } from "../../../../components/EmptyState/EmptyState"
13
5
import { ErrorSummary } from "../../../../components/ErrorSummary/ErrorSummary"
14
6
import { Header } from "../../../../components/Header/Header"
15
7
import { Margins } from "../../../../components/Margins/Margins"
16
8
import { Stack } from "../../../../components/Stack/Stack"
17
- import { TableHeaderRow } from "../../../../components/TableHeaders/TableHeaders"
18
- import { TableLoader } from "../../../../components/TableLoader/TableLoader"
19
- import { TableTitle } from "../../../../components/TableTitle/TableTitle"
9
+ import { WorkspacesTable } from "../../../../components/WorkspacesTable/WorkspacesTable"
20
10
import { unsafeSWRArgument } from "../../../../util"
21
11
import { firstOrItem } from "../../../../util/array"
22
12
23
13
export const Language = {
24
- tableTitle : "Workspaces" ,
25
- nameLabel : "Name" ,
26
- emptyMessage : "No workspaces have been created yet" ,
27
- emptyDescription : "Create a workspace to get started" ,
28
- totalLabel : "total" ,
29
- ctaAction : "Create workspace" ,
30
- subtitlePosfix : "workspaces" ,
14
+ subtitle : "workspaces" ,
31
15
}
32
16
33
17
export const TemplatePage : React . FC = ( ) => {
@@ -44,13 +28,11 @@ export const TemplatePage: React.FC = () => {
44
28
45
29
// This just grabs all workspaces... and then later filters them to match the
46
30
// current template.
47
-
48
31
const { data : workspaces , error : workspacesError } = useSWR < TypesGen . Workspace [ ] , Error > (
49
32
( ) => `/api/v2/organizations/${ unsafeSWRArgument ( organizationInfo ) . id } /workspaces` ,
50
33
)
51
34
52
35
const hasError = organizationError || templateError || workspacesError
53
- const isLoading = ! templateInfo || ! workspaces
54
36
55
37
const createWorkspace = ( ) => {
56
38
navigate ( `/templates/${ organizationName } /${ templateName } /create` )
@@ -68,7 +50,7 @@ export const TemplatePage: React.FC = () => {
68
50
< Header
69
51
title = { firstOrItem ( templateName , "" ) }
70
52
description = { firstOrItem ( organizationName , "" ) }
71
- subTitle = { perTemplateWorkspaces ? `${ perTemplateWorkspaces . length } ${ Language . subtitlePosfix } ` : "" }
53
+ subTitle = { perTemplateWorkspaces ? `${ perTemplateWorkspaces . length } ${ Language . subtitle } ` : "" }
72
54
action = { {
73
55
text : "Create Workspace" ,
74
56
onClick : createWorkspace ,
@@ -80,43 +62,7 @@ export const TemplatePage: React.FC = () => {
80
62
{ templateError && < ErrorSummary error = { templateError } /> }
81
63
{ workspacesError && < ErrorSummary error = { workspacesError } /> }
82
64
{ ! hasError && (
83
- < Table >
84
- < TableHead >
85
- < TableTitle title = { Language . tableTitle } />
86
- < TableHeaderRow >
87
- < TableCell size = "small" > { Language . nameLabel } </ TableCell >
88
- </ TableHeaderRow >
89
- </ TableHead >
90
- < TableBody >
91
- { isLoading && < TableLoader /> }
92
- { workspaces &&
93
- workspaces . map ( ( w ) => (
94
- < TableRow key = { w . id } >
95
- < TableCell >
96
- < Link to = { `/workspaces/${ w . id } ` } > { w . name } </ Link >
97
- </ TableCell >
98
- </ TableRow >
99
- ) ) }
100
-
101
- { workspaces && workspaces . length === 0 && (
102
- < TableRow >
103
- < TableCell colSpan = { 999 } >
104
- < Box p = { 4 } >
105
- < EmptyState
106
- message = { Language . emptyMessage }
107
- description = { Language . emptyDescription }
108
- cta = {
109
- < Button variant = "contained" color = "primary" onClick = { createWorkspace } >
110
- { Language . ctaAction }
111
- </ Button >
112
- }
113
- />
114
- </ Box >
115
- </ TableCell >
116
- </ TableRow >
117
- ) }
118
- </ TableBody >
119
- </ Table >
65
+ < WorkspacesTable templateInfo = { templateInfo } workspaces = { workspaces } onCreateWorkspace = { createWorkspace } />
120
66
) }
121
67
</ Margins >
122
68
</ Stack >
0 commit comments