@@ -16,12 +16,12 @@ import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight"
16
16
import RefreshIcon from "@material-ui/icons/Refresh"
17
17
import SearchIcon from "@material-ui/icons/Search"
18
18
import useTheme from "@material-ui/styles/useTheme"
19
+ import { useActor } from "@xstate/react"
19
20
import dayjs from "dayjs"
20
21
import relativeTime from "dayjs/plugin/relativeTime"
21
22
import { FormikErrors , useFormik } from "formik"
22
23
import { FC , useState } from "react"
23
24
import { Link as RouterLink , useNavigate } from "react-router-dom"
24
- import * as TypesGen from "../../api/typesGenerated"
25
25
import { AvatarData } from "../../components/AvatarData/AvatarData"
26
26
import { CloseDropdown , OpenDropdown } from "../../components/DropdownArrows/DropdownArrows"
27
27
import { EmptyState } from "../../components/EmptyState/EmptyState"
@@ -39,6 +39,7 @@ import { Stack } from "../../components/Stack/Stack"
39
39
import { TableLoader } from "../../components/TableLoader/TableLoader"
40
40
import { getFormHelpers , onChangeTrimmed } from "../../util/formUtils"
41
41
import { getDisplayStatus , workspaceFilterQuery } from "../../util/workspace"
42
+ import { WorkspaceItemMachineRef } from "../../xServices/workspaces/workspacesXService"
42
43
43
44
dayjs . extend ( relativeTime )
44
45
@@ -97,6 +98,64 @@ const OutdatedHelpTooltip: React.FC<{ onUpdateVersion: () => void }> = ({ onUpda
97
98
)
98
99
}
99
100
101
+ const WorkspaceRow : React . FC < { workspaceRef : WorkspaceItemMachineRef } > = ( { workspaceRef } ) => {
102
+ const styles = useStyles ( )
103
+ const navigate = useNavigate ( )
104
+ const theme : Theme = useTheme ( )
105
+ const [ workspaceState , send ] = useActor ( workspaceRef )
106
+ const { data : workspace } = workspaceState . context
107
+ const status = getDisplayStatus ( theme , workspace . latest_build )
108
+ const navigateToWorkspacePage = ( ) => {
109
+ navigate ( `/@${ workspace . owner_name } /${ workspace . name } ` )
110
+ }
111
+ return (
112
+ < TableRow
113
+ hover
114
+ data-testid = { `workspace-${ workspace . id } ` }
115
+ tabIndex = { 0 }
116
+ onClick = { navigateToWorkspacePage }
117
+ onKeyDown = { ( event ) => {
118
+ if ( event . key === "Enter" ) {
119
+ navigateToWorkspacePage ( )
120
+ }
121
+ } }
122
+ className = { styles . clickableTableRow }
123
+ >
124
+ < TableCell >
125
+ < AvatarData title = { workspace . name } subtitle = { workspace . owner_name } />
126
+ </ TableCell >
127
+ < TableCell > { workspace . template_name } </ TableCell >
128
+ < TableCell >
129
+ { workspace . outdated ? (
130
+ < span className = { styles . outdatedLabel } >
131
+ { Language . outdatedLabel }
132
+ < OutdatedHelpTooltip
133
+ onUpdateVersion = { ( ) => {
134
+ send ( "UPDATE_VERSION" )
135
+ } }
136
+ />
137
+ </ span >
138
+ ) : (
139
+ < span style = { { color : theme . palette . text . secondary } } > { Language . upToDateLabel } </ span >
140
+ ) }
141
+ </ TableCell >
142
+ < TableCell >
143
+ < span data-chromatic = "ignore" style = { { color : theme . palette . text . secondary } } >
144
+ { dayjs ( ) . to ( dayjs ( workspace . latest_build . created_at ) ) }
145
+ </ span >
146
+ </ TableCell >
147
+ < TableCell >
148
+ < span style = { { color : status . color } } > { status . status } </ span >
149
+ </ TableCell >
150
+ < TableCell >
151
+ < div className = { styles . arrowCell } >
152
+ < KeyboardArrowRight className = { styles . arrowRight } />
153
+ </ div >
154
+ </ TableCell >
155
+ </ TableRow >
156
+ )
157
+ }
158
+
100
159
interface FilterFormValues {
101
160
query : string
102
161
}
@@ -105,15 +164,13 @@ export type FilterFormErrors = FormikErrors<FilterFormValues>
105
164
106
165
export interface WorkspacesPageViewProps {
107
166
loading ?: boolean
108
- workspaces ?: TypesGen . Workspace [ ]
167
+ workspaceRefs ?: WorkspaceItemMachineRef [ ]
109
168
filter ?: string
110
169
onFilter : ( query : string ) => void
111
170
}
112
171
113
- export const WorkspacesPageView : FC < WorkspacesPageViewProps > = ( { loading, workspaces , filter, onFilter } ) => {
172
+ export const WorkspacesPageView : FC < WorkspacesPageViewProps > = ( { loading, workspaceRefs , filter, onFilter } ) => {
114
173
const styles = useStyles ( )
115
- const navigate = useNavigate ( )
116
- const theme : Theme = useTheme ( )
117
174
118
175
const form = useFormik < FilterFormValues > ( {
119
176
enableReinitialize : true ,
@@ -216,17 +273,17 @@ export const WorkspacesPageView: FC<WorkspacesPageViewProps> = ({ loading, works
216
273
< Table >
217
274
< TableHead >
218
275
< TableRow >
219
- < TableCell > Name</ TableCell >
220
- < TableCell > Template</ TableCell >
221
- < TableCell > Version</ TableCell >
222
- < TableCell > Last Built</ TableCell >
223
- < TableCell > Status</ TableCell >
276
+ < TableCell width = "35%" > Name</ TableCell >
277
+ < TableCell width = "15%" > Template</ TableCell >
278
+ < TableCell width = "15%" > Version</ TableCell >
279
+ < TableCell width = "20%" > Last Built</ TableCell >
280
+ < TableCell width = "15%" > Status</ TableCell >
224
281
< TableCell width = "1%" > </ TableCell >
225
282
</ TableRow >
226
283
</ TableHead >
227
284
< TableBody >
228
- { ! workspaces && loading && < TableLoader /> }
229
- { workspaces && workspaces . length === 0 && (
285
+ { ! workspaceRefs && loading && < TableLoader /> }
286
+ { workspaceRefs && workspaceRefs . length === 0 && (
230
287
< >
231
288
{ filter === workspaceFilterQuery . me || filter === workspaceFilterQuery . all ? (
232
289
< TableRow >
@@ -251,60 +308,8 @@ export const WorkspacesPageView: FC<WorkspacesPageViewProps> = ({ loading, works
251
308
) }
252
309
</ >
253
310
) }
254
- { workspaces &&
255
- workspaces . map ( ( workspace ) => {
256
- const status = getDisplayStatus ( theme , workspace . latest_build )
257
- const navigateToWorkspacePage = ( ) => {
258
- navigate ( `/@${ workspace . owner_name } /${ workspace . name } ` )
259
- }
260
- return (
261
- < TableRow
262
- key = { workspace . id }
263
- hover
264
- data-testid = { `workspace-${ workspace . id } ` }
265
- tabIndex = { 0 }
266
- onClick = { navigateToWorkspacePage }
267
- onKeyDown = { ( event ) => {
268
- if ( event . key === "Enter" ) {
269
- navigateToWorkspacePage ( )
270
- }
271
- } }
272
- className = { styles . clickableTableRow }
273
- >
274
- < TableCell >
275
- < AvatarData title = { workspace . name } subtitle = { workspace . owner_name } />
276
- </ TableCell >
277
- < TableCell > { workspace . template_name } </ TableCell >
278
- < TableCell >
279
- { workspace . outdated ? (
280
- < span className = { styles . outdatedLabel } >
281
- { Language . outdatedLabel }
282
- < OutdatedHelpTooltip
283
- onUpdateVersion = { ( ) => {
284
- console . log ( "UPDATE!!" )
285
- } }
286
- />
287
- </ span >
288
- ) : (
289
- < span style = { { color : theme . palette . text . secondary } } > { Language . upToDateLabel } </ span >
290
- ) }
291
- </ TableCell >
292
- < TableCell >
293
- < span data-chromatic = "ignore" style = { { color : theme . palette . text . secondary } } >
294
- { dayjs ( ) . to ( dayjs ( workspace . latest_build . created_at ) ) }
295
- </ span >
296
- </ TableCell >
297
- < TableCell >
298
- < span style = { { color : status . color } } > { status . status } </ span >
299
- </ TableCell >
300
- < TableCell >
301
- < div className = { styles . arrowCell } >
302
- < KeyboardArrowRight className = { styles . arrowRight } />
303
- </ div >
304
- </ TableCell >
305
- </ TableRow >
306
- )
307
- } ) }
311
+ { workspaceRefs &&
312
+ workspaceRefs . map ( ( workspaceRef ) => < WorkspaceRow workspaceRef = { workspaceRef } key = { workspaceRef . id } /> ) }
308
313
</ TableBody >
309
314
</ Table >
310
315
</ Margins >
0 commit comments