Skip to content

Commit f99f56d

Browse files
committed
fix: ProfileExplorer should only show edit buttons when in an editable/unlocked mode
1 parent fdf9b5e commit f99f56d

File tree

2 files changed

+54
-66
lines changed

2 files changed

+54
-66
lines changed

Diff for: plugins/plugin-codeflare/src/components/ProfileExplorer.tsx

+54-55
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ import Icon from "@patternfly/react-icons/dist/esm/icons/clipboard-list-icon"
4444

4545
import "../../web/scss/components/ProfileExplorer/_index.scss"
4646

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"
4749
import PlusSquareIcon from "@patternfly/react-icons/dist/esm/icons/plus-square-icon"
4850
import EraserIcon from "@patternfly/react-icons/dist/esm/icons/eraser-icon"
4951
import TrashIcon from "@patternfly/react-icons/dist/esm/icons/trash-icon"
@@ -253,40 +255,35 @@ type ProfileCardProps = Partial<Diff> &
253255
}
254256

255257
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
260260
}
261261

262262
class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState> {
263263
public constructor(props: ProfileCardProps) {
264264
super(props)
265265
this.state = {
266-
isOpen: false,
266+
editable: false,
267267
}
268268
}
269269

270270
/** Create new profile */
271-
private readonly _handleNew = async () => {
271+
private readonly _onNew = async () => {
272272
if (this.props.profile) {
273273
const newProfile = await handleNew(this.props.profile, this.props.profiles)
274274
this.props.onSelectProfile(newProfile)
275275
}
276276
}
277277

278278
/** Delete selected profile */
279-
private readonly _handleDelete = async () => {
279+
private readonly _onDelete = async () => {
280280
if (this.props.profile) {
281281
await handleDelete(this.props.profile)
282282
this.props.onSelectProfile(null)
283283
}
284284
}
285285

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)
290287

291288
private title() {
292289
return (
@@ -331,15 +328,15 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
331328
private readonly groups: Record<string, Group> = {
332329
Application: {
333330
title: "Application",
334-
name: "Properties of your workload",
331+
name: "", // "Properties of your workload",
335332
},
336333
Compute: {
337334
title: "Compute",
338-
name: "Properties of your workers",
335+
name: "", // "Properties of your workers",
339336
},
340337
Storage: {
341338
title: "Storage",
342-
name: "Properties of your data",
339+
name: "", // "Properties of your data",
343340
},
344341
}
345342

@@ -471,7 +468,11 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
471468
}
472469
}
473470

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) => {
475476
const guidebook = evt.currentTarget.getAttribute("data-guidebook")
476477
if (guidebook) {
477478
if (this.props.onSelectGuidebook) {
@@ -482,39 +483,25 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
482483
}
483484
}
484485

486+
/** @return a `TreeViewDataItem` wrapper around `node` that adds an edit button */
485487
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+
})
518505
}
519506

520507
private body() {
@@ -555,7 +542,7 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
555542
}
556543
this.sort(data)
557544

558-
return <TreeView hasGuides defaultAllExpanded data={data} variant="compactNoBackground" />
545+
return <TreeView hasGuides defaultAllExpanded data={data} variant="compact" toolbar={this.title()} />
559546
}
560547

561548
return <Loading />
@@ -583,16 +570,31 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
583570
<Flex flexWrap={this.nowrap} justifyContent={this.flexEnd}>
584571
<FlexItem flex={this.flex1}>
585572
<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} />
587574
</Tooltip>
588575
</FlexItem>
589576

590577
<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>
591593
<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} />
593595
</Tooltip>
594596
<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} />
596598
</Tooltip>
597599
</FlexItem>
598600
</Flex>
@@ -610,10 +612,7 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
610612
</CardTitle>
611613
<CardActions hasNoOffset>{this.actions()}</CardActions>
612614
</CardHeader>
613-
<CardBody>
614-
{this.title()}
615-
{this.body()}
616-
</CardBody>
615+
<CardBody>{this.body()}</CardBody>
617616
<CardFooter>{this.footer()}</CardFooter>
618617
</Card>
619618
)

Diff for: plugins/plugin-codeflare/web/scss/components/ProfileExplorer/_index.scss

-11
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ body[kui-theme-style="dark"] {
7777
color: var(--color-text-01);
7878
}
7979

80-
.pf-c-tree-view {
81-
@include EditButton {
82-
opacity: 0.25;
83-
color: var(--color-text-02);
84-
&:hover {
85-
opacity: 1;
86-
color: var(--color-text-01);
87-
}
88-
}
89-
}
90-
9180
.pf-c-card__footer {
9281
button.larger-text {
9382
font-size: 1.25rem;

0 commit comments

Comments
 (0)