@@ -44,6 +44,8 @@ import Icon from "@patternfly/react-icons/dist/esm/icons/clipboard-list-icon"
44
44
45
45
import "../../web/scss/components/ProfileExplorer/_index.scss"
46
46
47
+ import LockIcon from "@patternfly/react-icons/dist/esm/icons/lock-icon"
48
+ import LockOpenIcon from "@patternfly/react-icons/dist/esm/icons/lock-open-icon"
47
49
import PlusSquareIcon from "@patternfly/react-icons/dist/esm/icons/plus-square-icon"
48
50
import EraserIcon from "@patternfly/react-icons/dist/esm/icons/eraser-icon"
49
51
import TrashIcon from "@patternfly/react-icons/dist/esm/icons/trash-icon"
@@ -253,40 +255,35 @@ type ProfileCardProps = Partial<Diff> &
253
255
}
254
256
255
257
type ProfileCardState = {
256
- isOpen : boolean
257
-
258
- /** Is the kebab action dropdown open? */
259
- isKebabOpen ?: boolean
258
+ /** Are we in editable mode? */
259
+ editable : boolean
260
260
}
261
261
262
262
class ProfileCard extends React . PureComponent < ProfileCardProps , ProfileCardState > {
263
263
public constructor ( props : ProfileCardProps ) {
264
264
super ( props )
265
265
this . state = {
266
- isOpen : false ,
266
+ editable : false ,
267
267
}
268
268
}
269
269
270
270
/** Create new profile */
271
- private readonly _handleNew = async ( ) => {
271
+ private readonly _onNew = async ( ) => {
272
272
if ( this . props . profile ) {
273
273
const newProfile = await handleNew ( this . props . profile , this . props . profiles )
274
274
this . props . onSelectProfile ( newProfile )
275
275
}
276
276
}
277
277
278
278
/** Delete selected profile */
279
- private readonly _handleDelete = async ( ) => {
279
+ private readonly _onDelete = async ( ) => {
280
280
if ( this . props . profile ) {
281
281
await handleDelete ( this . props . profile )
282
282
this . props . onSelectProfile ( null )
283
283
}
284
284
}
285
285
286
- private readonly _handleReset = ( ) => this . props . profile && handleReset ( this . props . profile )
287
- // private readonly _handleBoot = () => handleBoot(this.props.profile)
288
- // private readonly _handleShutdown = () => handleShutdown(this.props.profile)
289
- private readonly _onToggle = ( ) => this . setState ( { isOpen : ! this . state . isOpen } )
286
+ private readonly _onReset = ( ) => this . props . profile && handleReset ( this . props . profile )
290
287
291
288
private title ( ) {
292
289
return (
@@ -331,15 +328,15 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
331
328
private readonly groups : Record < string , Group > = {
332
329
Application : {
333
330
title : "Application" ,
334
- name : "Properties of your workload" ,
331
+ name : "" , // " Properties of your workload",
335
332
} ,
336
333
Compute : {
337
334
title : "Compute" ,
338
- name : "Properties of your workers" ,
335
+ name : "" , // " Properties of your workers",
339
336
} ,
340
337
Storage : {
341
338
title : "Storage" ,
342
- name : "Properties of your data" ,
339
+ name : "" , // " Properties of your data",
343
340
} ,
344
341
}
345
342
@@ -471,7 +468,11 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
471
468
}
472
469
}
473
470
474
- private readonly onEdit = ( evt : React . MouseEvent ) => {
471
+ /** User has clicked to toggle editable mode */
472
+ private readonly _onToggleEditable = ( ) => this . setState ( ( curState ) => ( { editable : ! curState . editable } ) )
473
+
474
+ /** User has clicked to edit a particular choice */
475
+ private readonly _onEdit = ( evt : React . MouseEvent ) => {
475
476
const guidebook = evt . currentTarget . getAttribute ( "data-guidebook" )
476
477
if ( guidebook ) {
477
478
if ( this . props . onSelectGuidebook ) {
@@ -482,39 +483,25 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
482
483
}
483
484
}
484
485
486
+ /** @return a `TreeViewDataItem` wrapper around `node` that adds an edit button */
485
487
private editable < T extends TreeViewDataItem > ( guidebook : string , node : T ) {
486
- return Object . assign ( node , {
487
- title : (
488
- < React . Fragment >
489
- { node . title } { " " }
490
- < Tooltip content = "Update this choice" >
491
- < span
492
- aria-label = "Edit"
493
- data-guidebook = { guidebook }
494
- onClick = { this . onEdit }
495
- className = "codeflare--profile-explorer-edit-button small-left-pad"
496
- >
497
- < Icons icon = "Edit" />
498
- </ span >
499
- </ Tooltip >
500
- </ React . Fragment >
501
- ) ,
502
- } )
503
- /* return Object.assign(node, {
504
- action: (
505
- <Tooltip markdown={`### Update\n#### ${guidebook}\n\nClick to update this choice`}>
506
- <Button
507
- variant="plain"
508
- aria-label="Edit"
509
- data-guidebook={guidebook}
510
- onClick={this.onEdit}
511
- className="codeflare--profile-explorer-edit-button"
512
- >
513
- <Icons icon="Edit" />
514
- </Button>
515
- </Tooltip>
516
- ),
517
- }) */
488
+ return ! this . state . editable
489
+ ? node
490
+ : Object . assign ( node , {
491
+ action : (
492
+ < Tooltip markdown = { `### Update\n#### ${ guidebook } \n\nClick to update this choice` } >
493
+ < Button
494
+ variant = "plain"
495
+ aria-label = "Edit"
496
+ data-guidebook = { guidebook }
497
+ onClick = { this . _onEdit }
498
+ className = "codeflare--profile-explorer-edit-button"
499
+ >
500
+ < Icons icon = "Edit" />
501
+ </ Button >
502
+ </ Tooltip >
503
+ ) ,
504
+ } )
518
505
}
519
506
520
507
private body ( ) {
@@ -555,7 +542,7 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
555
542
}
556
543
this . sort ( data )
557
544
558
- return < TreeView hasGuides defaultAllExpanded data = { data } variant = "compactNoBackground" />
545
+ return < TreeView hasGuides defaultAllExpanded data = { data } variant = "compact" toolbar = { this . title ( ) } />
559
546
}
560
547
561
548
return < Loading />
@@ -583,16 +570,31 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
583
570
< Flex flexWrap = { this . nowrap } justifyContent = { this . flexEnd } >
584
571
< FlexItem flex = { this . flex1 } >
585
572
< Tooltip position = "top" content = "Create a new profile" >
586
- < Button variant = "link" className = "larger-text" icon = { < PlusSquareIcon /> } onClick = { this . _handleNew } />
573
+ < Button variant = "link" className = "larger-text" icon = { < PlusSquareIcon /> } onClick = { this . _onNew } />
587
574
</ Tooltip >
588
575
</ FlexItem >
589
576
590
577
< FlexItem >
578
+ < Tooltip
579
+ position = "top"
580
+ content = {
581
+ this . state . editable
582
+ ? "Exit editable mode (disallow choices to be modified)"
583
+ : "Enter editable mode (allow choices to be modified)"
584
+ }
585
+ >
586
+ < Button
587
+ variant = "link"
588
+ className = "larger-text"
589
+ icon = { this . state . editable ? < LockOpenIcon /> : < LockIcon /> }
590
+ onClick = { this . _onToggleEditable }
591
+ />
592
+ </ Tooltip >
591
593
< Tooltip position = "top" content = "Reset the choices in this profile" >
592
- < Button variant = "link" className = "larger-text" icon = { < EraserIcon /> } onClick = { this . _handleReset } />
594
+ < Button variant = "link" className = "larger-text" icon = { < EraserIcon /> } onClick = { this . _onReset } />
593
595
</ Tooltip >
594
596
< Tooltip position = "top" content = "Delete this profile" >
595
- < Button variant = "link" className = "larger-text" icon = { < TrashIcon /> } onClick = { this . _handleDelete } />
597
+ < Button variant = "link" className = "larger-text" icon = { < TrashIcon /> } onClick = { this . _onDelete } />
596
598
</ Tooltip >
597
599
</ FlexItem >
598
600
</ Flex >
@@ -610,10 +612,7 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
610
612
</ CardTitle >
611
613
< CardActions hasNoOffset > { this . actions ( ) } </ CardActions >
612
614
</ CardHeader >
613
- < CardBody >
614
- { this . title ( ) }
615
- { this . body ( ) }
616
- </ CardBody >
615
+ < CardBody > { this . body ( ) } </ CardBody >
617
616
< CardFooter > { this . footer ( ) } </ CardFooter >
618
617
</ Card >
619
618
)
0 commit comments