@@ -34,6 +34,7 @@ import DeleteModal from '~/shared/components/DeleteModal';
34
34
import { buildKindLogoDictionary } from '~/app/actions/WorkspaceKindsActions' ;
35
35
import useWorkspaceKinds from '~/app/hooks/useWorkspaceKinds' ;
36
36
import { WorkspaceConnectAction } from '~/app/pages/Workspaces/WorkspaceConnectAction' ;
37
+ import { WorkspaceAggregatedDetails } from '~/app/pages/Workspaces/DetailsAggregated/WorkspaceAggregatedDetails' ;
37
38
import Filter , { FilteredColumn } from 'shared/components/Filter' ;
38
39
import { formatRam } from 'shared/utilities/WorkspaceResources' ;
39
40
@@ -170,7 +171,7 @@ export const Workspaces: React.FunctionComponent = () => {
170
171
lastActivity : 'Last Activity' ,
171
172
} ;
172
173
173
- const filterableColumns : WorkspacesColumnNames = {
174
+ const filterableColumns = {
174
175
name : 'Name' ,
175
176
kind : 'Kind' ,
176
177
image : 'Image' ,
@@ -387,22 +388,49 @@ export const Workspaces: React.FunctionComponent = () => {
387
388
setPage ( newPage ) ;
388
389
} ;
389
390
390
- const workspaceDetailsContent = (
391
- < >
392
- { selectedWorkspace && (
393
- < WorkspaceDetails
394
- workspace = { selectedWorkspace }
395
- onCloseClick = { ( ) => selectWorkspace ( null ) }
396
- onEditClick = { ( ) => editAction ( selectedWorkspace ) }
397
- onDeleteClick = { ( ) => handleDeleteClick ( selectedWorkspace ) }
398
- />
399
- ) }
400
- </ >
401
- ) ;
391
+ const [ selectedWorkspaceNames , setSelectedWorkspaceNames ] = React . useState < string [ ] > ( [ ] ) ;
392
+ const setWorkspaceSelected = ( workspace : Workspace , isSelecting = true ) =>
393
+ setSelectedWorkspaceNames ( ( prevSelected ) => {
394
+ const otherSelectedWorkspaceNames = prevSelected . filter ( ( w ) => w !== workspace . name ) ;
395
+ return isSelecting
396
+ ? [ ...otherSelectedWorkspaceNames , workspace . name ]
397
+ : otherSelectedWorkspaceNames ;
398
+ } ) ;
399
+ const selectAllWorkspaces = ( isSelecting = true ) =>
400
+ setSelectedWorkspaceNames ( isSelecting ? sortedWorkspaces . map ( ( r ) => r . name ) : [ ] ) ;
401
+ const areAllWorkspacesSelected = selectedWorkspaceNames . length === sortedWorkspaces . length ;
402
+ const isWorkspaceSelected = ( workspace : Workspace ) =>
403
+ selectedWorkspaceNames . includes ( workspace . name ) ;
404
+
405
+ const workspaceDetailsContent = ( ) => {
406
+ const selectedWorkspaceForDetails =
407
+ selectedWorkspaceNames . length === 1
408
+ ? sortedWorkspaces . find ( ( w ) => w . name === selectedWorkspaceNames [ 0 ] )
409
+ : undefined ;
410
+ return (
411
+ < >
412
+ { selectedWorkspaceForDetails && (
413
+ < WorkspaceDetails
414
+ workspace = { selectedWorkspaceForDetails }
415
+ onCloseClick = { ( ) => selectAllWorkspaces ( false ) }
416
+ onEditClick = { ( ) => editAction ( selectedWorkspaceForDetails ) }
417
+ onDeleteClick = { ( ) => handleDeleteClick ( selectedWorkspaceForDetails ) }
418
+ />
419
+ ) }
420
+ { selectedWorkspaceNames . length > 1 && (
421
+ < WorkspaceAggregatedDetails
422
+ workspaceNames = { selectedWorkspaceNames }
423
+ onCloseClick = { ( ) => selectAllWorkspaces ( false ) }
424
+ onDeleteClick = { ( ) => console . log ( 'Delete selected workspaces' ) }
425
+ />
426
+ ) }
427
+ </ >
428
+ ) ;
429
+ } ;
402
430
403
431
return (
404
- < Drawer isInline isExpanded = { selectedWorkspace != null } >
405
- < DrawerContent panelContent = { workspaceDetailsContent } >
432
+ < Drawer isInline isExpanded = { selectedWorkspaceNames . length >= 1 } >
433
+ < DrawerContent panelContent = { workspaceDetailsContent ( ) } >
406
434
< DrawerContentBody >
407
435
< PageSection isFilled >
408
436
< Content >
@@ -420,6 +448,13 @@ export const Workspaces: React.FunctionComponent = () => {
420
448
< Thead >
421
449
< Tr >
422
450
< Th />
451
+ < Th
452
+ select = { {
453
+ onSelect : ( _event , isSelecting ) => selectAllWorkspaces ( isSelecting ) ,
454
+ isSelected : areAllWorkspacesSelected ,
455
+ } }
456
+ aria-label = "Row select"
457
+ />
423
458
{ Object . values ( columnNames ) . map ( ( columnName , index ) => (
424
459
< Th key = { `${ columnName } -col-name` } sort = { getSortParams ( index ) } >
425
460
{ columnName }
@@ -444,6 +479,14 @@ export const Workspaces: React.FunctionComponent = () => {
444
479
setWorkspaceExpanded ( workspace , ! isWorkspaceExpanded ( workspace ) ) ,
445
480
} }
446
481
/>
482
+ < Td
483
+ select = { {
484
+ rowIndex,
485
+ onSelect : ( _event , isSelecting ) =>
486
+ setWorkspaceSelected ( workspace , isSelecting ) ,
487
+ isSelected : isWorkspaceSelected ( workspace ) ,
488
+ } }
489
+ />
447
490
< Td dataLabel = { columnNames . name } > { workspace . name } </ Td >
448
491
< Td dataLabel = { columnNames . kind } >
449
492
{ kindLogoDict [ workspace . kind ] ? (
@@ -491,7 +534,7 @@ export const Workspaces: React.FunctionComponent = () => {
491
534
</ Td >
492
535
</ Tr >
493
536
{ isWorkspaceExpanded ( workspace ) && (
494
- < ExpandedWorkspaceRow workspace = { workspace } columnNames = { columnNames } />
537
+ < ExpandedWorkspaceRow workspace = { workspace } />
495
538
) }
496
539
</ Tbody >
497
540
) ) }
0 commit comments