@@ -56,9 +56,9 @@ import { WorkspacesColumnNames } from '~/app/types';
56
56
import CustomEmptyState from '~/shared/components/CustomEmptyState' ;
57
57
import Filter , { FilteredColumn , FilterRef } from '~/shared/components/Filter' ;
58
58
import { extractCpuValue , extractMemoryValue } from '~/shared/utilities/WorkspaceUtils' ;
59
+ import { WorkspaceAggregatedDetails } from '~/app/pages/Workspaces/DetailsAggregated/WorkspaceAggregatedDetails' ;
59
60
60
61
export enum ActionType {
61
- ViewDetails ,
62
62
Edit ,
63
63
Delete ,
64
64
Start ,
@@ -139,17 +139,6 @@ export const Workspaces: React.FunctionComponent = () => {
139
139
} ) ;
140
140
} , [ activeActionType , navigate , selectedWorkspace ] ) ;
141
141
142
- const selectWorkspace = React . useCallback (
143
- ( newSelectedWorkspace : Workspace | null ) => {
144
- if ( selectedWorkspace ?. name === newSelectedWorkspace ?. name ) {
145
- setSelectedWorkspace ( null ) ;
146
- } else {
147
- setSelectedWorkspace ( newSelectedWorkspace ) ;
148
- }
149
- } ,
150
- [ selectedWorkspace ] ,
151
- ) ;
152
-
153
142
const setWorkspaceExpanded = ( workspace : Workspace , isExpanding = true ) =>
154
143
setExpandedWorkspacesNames ( ( prevExpanded ) => {
155
144
const newExpandedWorkspacesNames = prevExpanded . filter ( ( wsName ) => wsName !== workspace . name ) ;
@@ -274,11 +263,6 @@ export const Workspaces: React.FunctionComponent = () => {
274
263
275
264
// Actions
276
265
277
- const viewDetailsClick = React . useCallback ( ( workspace : Workspace ) => {
278
- setSelectedWorkspace ( workspace ) ;
279
- setActiveActionType ( ActionType . ViewDetails ) ;
280
- } , [ ] ) ;
281
-
282
266
// TODO: Uncomment when edit action is fully supported
283
267
// const editAction = React.useCallback((workspace: Workspace) => {
284
268
// setSelectedWorkspace(workspace);
@@ -328,11 +312,6 @@ export const Workspaces: React.FunctionComponent = () => {
328
312
329
313
const workspaceDefaultActions = ( workspace : Workspace ) : IActions => {
330
314
const workspaceActions = [
331
- {
332
- id : 'view-details' ,
333
- title : 'View Details' ,
334
- onClick : ( ) => viewDetailsClick ( workspace ) ,
335
- } ,
336
315
// TODO: Uncomment when edit action is fully supported
337
316
// {
338
317
// id: 'edit',
@@ -501,26 +480,50 @@ export const Workspaces: React.FunctionComponent = () => {
501
480
setPage ( newPage ) ;
502
481
} ;
503
482
504
- const workspaceDetailsContent = (
505
- < >
506
- { selectedWorkspace && (
507
- < WorkspaceDetails
508
- workspace = { selectedWorkspace }
509
- onCloseClick = { ( ) => selectWorkspace ( null ) }
510
- // TODO: Uncomment when edit action is fully supported
511
- // onEditClick={() => editAction(selectedWorkspace)}
512
- onDeleteClick = { ( ) => handleDeleteClick ( selectedWorkspace ) }
513
- />
514
- ) }
515
- </ >
516
- ) ;
483
+ const [ selectedWorkspaceNames , setSelectedWorkspaceNames ] = React . useState < string [ ] > ( [ ] ) ;
484
+ const setWorkspaceSelected = ( workspace : Workspace , isSelecting = true ) =>
485
+ setSelectedWorkspaceNames ( ( prevSelected ) => {
486
+ const otherSelectedWorkspaceNames = prevSelected . filter ( ( w ) => w !== workspace . name ) ;
487
+ return isSelecting
488
+ ? [ ...otherSelectedWorkspaceNames , workspace . name ]
489
+ : otherSelectedWorkspaceNames ;
490
+ } ) ;
491
+ const selectAllWorkspaces = ( isSelecting = true ) =>
492
+ setSelectedWorkspaceNames ( isSelecting ? sortedWorkspaces . map ( ( r ) => r . name ) : [ ] ) ;
493
+ const areAllWorkspacesSelected = selectedWorkspaceNames . length === sortedWorkspaces . length ;
494
+ const isWorkspaceSelected = ( workspace : Workspace ) =>
495
+ selectedWorkspaceNames . includes ( workspace . name ) ;
496
+
497
+ const workspaceDetailsContent = ( ) => {
498
+ const selectedWorkspaceForDetails =
499
+ selectedWorkspaceNames . length === 1
500
+ ? sortedWorkspaces . find ( ( w ) => w . name === selectedWorkspaceNames [ 0 ] )
501
+ : undefined ;
502
+ return (
503
+ < >
504
+ { selectedWorkspaceForDetails && (
505
+ < WorkspaceDetails
506
+ workspace = { selectedWorkspaceForDetails }
507
+ onCloseClick = { ( ) => selectAllWorkspaces ( false ) }
508
+ // TODO: Uncomment when edit action is fully supported
509
+ // onEditClick={() => editAction(selectedWorkspaceForDetails)}
510
+ onDeleteClick = { ( ) => handleDeleteClick ( selectedWorkspaceForDetails ) }
511
+ />
512
+ ) }
513
+ { selectedWorkspaceNames . length > 1 && (
514
+ < WorkspaceAggregatedDetails
515
+ workspaceNames = { selectedWorkspaceNames }
516
+ onCloseClick = { ( ) => selectAllWorkspaces ( false ) }
517
+ onDeleteClick = { ( ) => console . log ( 'Delete selected workspaces' ) }
518
+ />
519
+ ) }
520
+ </ >
521
+ ) ;
522
+ } ;
517
523
518
524
return (
519
- < Drawer
520
- isInline
521
- isExpanded = { selectedWorkspace != null && activeActionType === ActionType . ViewDetails }
522
- >
523
- < DrawerContent panelContent = { workspaceDetailsContent } >
525
+ < Drawer isExpanded = { selectedWorkspaceNames . length >= 1 } >
526
+ < DrawerContent panelContent = { workspaceDetailsContent ( ) } >
524
527
< DrawerContentBody >
525
528
< PageSection isFilled >
526
529
< Content >
@@ -545,6 +548,13 @@ export const Workspaces: React.FunctionComponent = () => {
545
548
< Thead >
546
549
< Tr >
547
550
< Th screenReaderText = "expand-action" />
551
+ < Th
552
+ select = { {
553
+ onSelect : ( _event , isSelecting ) => selectAllWorkspaces ( isSelecting ) ,
554
+ isSelected : areAllWorkspacesSelected ,
555
+ } }
556
+ aria-label = "Row select"
557
+ />
548
558
{ Object . values ( columnNames ) . map ( ( columnName , index ) => (
549
559
< Th
550
560
key = { `${ columnName } -col-name` }
@@ -576,6 +586,15 @@ export const Workspaces: React.FunctionComponent = () => {
576
586
setWorkspaceExpanded ( workspace , ! isWorkspaceExpanded ( workspace ) ) ,
577
587
} }
578
588
/>
589
+ < Td
590
+ select = { {
591
+ rowIndex,
592
+ onSelect : ( _event , isSelecting ) =>
593
+ setWorkspaceSelected ( workspace , isSelecting ) ,
594
+ isSelected : isWorkspaceSelected ( workspace ) ,
595
+ } }
596
+ data-testid = "workspace-select"
597
+ />
579
598
< Td dataLabel = { columnNames . redirectStatus } >
580
599
{ workspaceRedirectStatus [ workspace . workspaceKind . name ]
581
600
? getRedirectStatusIcon (
@@ -640,7 +659,7 @@ export const Workspaces: React.FunctionComponent = () => {
640
659
</ Td >
641
660
</ Tr >
642
661
{ isWorkspaceExpanded ( workspace ) && (
643
- < ExpandedWorkspaceRow workspace = { workspace } columnNames = { columnNames } />
662
+ < ExpandedWorkspaceRow workspace = { workspace } />
644
663
) }
645
664
</ Tbody >
646
665
) ) }
0 commit comments