@@ -46,11 +46,11 @@ import { WorkspaceConnectAction } from '~/app/pages/Workspaces/WorkspaceConnectA
46
46
import { WorkspaceStartActionModal } from '~/app/pages/Workspaces/workspaceActions/WorkspaceStartActionModal' ;
47
47
import { WorkspaceRestartActionModal } from '~/app/pages/Workspaces/workspaceActions/WorkspaceRestartActionModal' ;
48
48
import { WorkspaceStopActionModal } from '~/app/pages/Workspaces/workspaceActions/WorkspaceStopActionModal' ;
49
+ import { WorkspaceAggregatedDetails } from '~/app/pages/Workspaces/DetailsAggregated/WorkspaceAggregatedDetails' ;
49
50
import Filter , { FilteredColumn } from 'shared/components/Filter' ;
50
51
import { formatRam } from 'shared/utilities/WorkspaceUtils' ;
51
52
52
53
export enum ActionType {
53
- ViewDetails ,
54
54
Edit ,
55
55
Delete ,
56
56
Start ,
@@ -225,17 +225,6 @@ export const Workspaces: React.FunctionComponent = () => {
225
225
const [ isActionAlertModalOpen , setIsActionAlertModalOpen ] = React . useState ( false ) ;
226
226
const [ activeActionType , setActiveActionType ] = React . useState < ActionType | null > ( null ) ;
227
227
228
- const selectWorkspace = React . useCallback (
229
- ( newSelectedWorkspace ) => {
230
- if ( selectedWorkspace ?. name === newSelectedWorkspace ?. name ) {
231
- setSelectedWorkspace ( null ) ;
232
- } else {
233
- setSelectedWorkspace ( newSelectedWorkspace ) ;
234
- }
235
- } ,
236
- [ selectedWorkspace ] ,
237
- ) ;
238
-
239
228
const setWorkspaceExpanded = ( workspace : Workspace , isExpanding = true ) =>
240
229
setExpandedWorkspacesNames ( ( prevExpanded ) => {
241
230
const newExpandedWorkspacesNames = prevExpanded . filter ( ( wsName ) => wsName !== workspace . name ) ;
@@ -341,11 +330,6 @@ export const Workspaces: React.FunctionComponent = () => {
341
330
342
331
// Actions
343
332
344
- const viewDetailsClick = React . useCallback ( ( workspace : Workspace ) => {
345
- setSelectedWorkspace ( workspace ) ;
346
- setActiveActionType ( ActionType . ViewDetails ) ;
347
- } , [ ] ) ;
348
-
349
333
const editAction = React . useCallback ( ( workspace : Workspace ) => {
350
334
setSelectedWorkspace ( workspace ) ;
351
335
setActiveActionType ( ActionType . Edit ) ;
@@ -383,11 +367,6 @@ export const Workspaces: React.FunctionComponent = () => {
383
367
const workspaceDefaultActions = ( workspace : Workspace ) : IActions => {
384
368
const workspaceState = workspace . status . state ;
385
369
const workspaceActions = [
386
- {
387
- id : 'view-details' ,
388
- title : 'View Details' ,
389
- onClick : ( ) => viewDetailsClick ( workspace ) ,
390
- } ,
391
370
{
392
371
id : 'edit' ,
393
372
title : 'Edit' ,
@@ -526,25 +505,49 @@ export const Workspaces: React.FunctionComponent = () => {
526
505
setPage ( newPage ) ;
527
506
} ;
528
507
529
- const workspaceDetailsContent = (
530
- < >
531
- { selectedWorkspace && (
532
- < WorkspaceDetails
533
- workspace = { selectedWorkspace }
534
- onCloseClick = { ( ) => selectWorkspace ( null ) }
535
- onEditClick = { ( ) => editAction ( selectedWorkspace ) }
536
- onDeleteClick = { ( ) => handleDeleteClick ( selectedWorkspace ) }
537
- />
538
- ) }
539
- </ >
540
- ) ;
508
+ const [ selectedWorkspaceNames , setSelectedWorkspaceNames ] = React . useState < string [ ] > ( [ ] ) ;
509
+ const setWorkspaceSelected = ( workspace : Workspace , isSelecting = true ) =>
510
+ setSelectedWorkspaceNames ( ( prevSelected ) => {
511
+ const otherSelectedWorkspaceNames = prevSelected . filter ( ( w ) => w !== workspace . name ) ;
512
+ return isSelecting
513
+ ? [ ...otherSelectedWorkspaceNames , workspace . name ]
514
+ : otherSelectedWorkspaceNames ;
515
+ } ) ;
516
+ const selectAllWorkspaces = ( isSelecting = true ) =>
517
+ setSelectedWorkspaceNames ( isSelecting ? sortedWorkspaces . map ( ( r ) => r . name ) : [ ] ) ;
518
+ const areAllWorkspacesSelected = selectedWorkspaceNames . length === sortedWorkspaces . length ;
519
+ const isWorkspaceSelected = ( workspace : Workspace ) =>
520
+ selectedWorkspaceNames . includes ( workspace . name ) ;
521
+
522
+ const workspaceDetailsContent = ( ) => {
523
+ const selectedWorkspaceForDetails =
524
+ selectedWorkspaceNames . length === 1
525
+ ? sortedWorkspaces . find ( ( w ) => w . name === selectedWorkspaceNames [ 0 ] )
526
+ : undefined ;
527
+ return (
528
+ < >
529
+ { selectedWorkspaceForDetails && (
530
+ < WorkspaceDetails
531
+ workspace = { selectedWorkspaceForDetails }
532
+ onCloseClick = { ( ) => selectAllWorkspaces ( false ) }
533
+ onEditClick = { ( ) => editAction ( selectedWorkspaceForDetails ) }
534
+ onDeleteClick = { ( ) => handleDeleteClick ( selectedWorkspaceForDetails ) }
535
+ />
536
+ ) }
537
+ { selectedWorkspaceNames . length > 1 && (
538
+ < WorkspaceAggregatedDetails
539
+ workspaceNames = { selectedWorkspaceNames }
540
+ onCloseClick = { ( ) => selectAllWorkspaces ( false ) }
541
+ onDeleteClick = { ( ) => console . log ( 'Delete selected workspaces' ) }
542
+ />
543
+ ) }
544
+ </ >
545
+ ) ;
546
+ } ;
541
547
542
548
return (
543
- < Drawer
544
- isInline
545
- isExpanded = { selectedWorkspace != null && activeActionType === ActionType . ViewDetails }
546
- >
547
- < DrawerContent panelContent = { workspaceDetailsContent } >
549
+ < Drawer isExpanded = { selectedWorkspaceNames . length >= 1 } >
550
+ < DrawerContent panelContent = { workspaceDetailsContent ( ) } >
548
551
< DrawerContentBody >
549
552
< PageSection isFilled >
550
553
< Content >
@@ -562,6 +565,13 @@ export const Workspaces: React.FunctionComponent = () => {
562
565
< Thead >
563
566
< Tr >
564
567
< Th />
568
+ < Th
569
+ select = { {
570
+ onSelect : ( _event , isSelecting ) => selectAllWorkspaces ( isSelecting ) ,
571
+ isSelected : areAllWorkspacesSelected ,
572
+ } }
573
+ aria-label = "Row select"
574
+ />
565
575
{ Object . values ( columnNames ) . map ( ( columnName , index ) => (
566
576
< Th
567
577
key = { `${ columnName } -col-name` }
@@ -589,6 +599,14 @@ export const Workspaces: React.FunctionComponent = () => {
589
599
setWorkspaceExpanded ( workspace , ! isWorkspaceExpanded ( workspace ) ) ,
590
600
} }
591
601
/>
602
+ < Td
603
+ select = { {
604
+ rowIndex,
605
+ onSelect : ( _event , isSelecting ) =>
606
+ setWorkspaceSelected ( workspace , isSelecting ) ,
607
+ isSelected : isWorkspaceSelected ( workspace ) ,
608
+ } }
609
+ />
592
610
< Td dataLabel = { columnNames . redirectStatus } >
593
611
{ workspaceRedirectStatus [ workspace . kind ]
594
612
? getRedirectStatusIcon (
@@ -644,9 +662,7 @@ export const Workspaces: React.FunctionComponent = () => {
644
662
/>
645
663
</ Td >
646
664
</ Tr >
647
- { isWorkspaceExpanded ( workspace ) && (
648
- < ExpandedWorkspaceRow workspace = { workspace } columnNames = { columnNames } />
649
- ) }
665
+ { isWorkspaceExpanded ( workspace ) && < ExpandedWorkspaceRow workspace = { workspace } /> }
650
666
</ Tbody >
651
667
) ) }
652
668
</ Table >
0 commit comments