Skip to content

Commit

Permalink
[TEMP]
Browse files Browse the repository at this point in the history
chore(Canvas): Improve look and feel

This commit removes the usage of `DefaultNode` and replaces it with a
custom implementation.

It makes the nodes wider, and removes the border to make more room for
the text.

It also adds a floating mini toolbar, aka contextual palette, when
hovering over the node.

feat(Canvas): Use CustomNode for collapsed groups

* hover over toolbar working
* centered toolbar for containers
* removed phantom-rect
* add disable icon within boundaries
* add exclamation mark before the label
* red-color the exclamation mark and the label
* decrease node width
* add label background to hide the edge
  • Loading branch information
lordrip committed Nov 11, 2024
1 parent 9be2b96 commit af7ba00
Show file tree
Hide file tree
Showing 45 changed files with 1,337 additions and 968 deletions.
7 changes: 7 additions & 0 deletions packages/ui/src/assets/settingsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
"default": "description",
"type": "string",
"enum": ["description", "id"]
},
"nodeToolbarTrigger": {
"title": "Open Node toolbar",
"description": "Choose when to open the Node toolbar. Can be either `onHover` or `onSelection`. If `onHover` is selected, the toolbar will be automatically open upon hoevring a node, otherwise, it will be open when selecting a node",
"default": "onHover",
"type": "string",
"enum": ["onHover", "onSelection"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,148 @@ exports[`SettingsForm should render 1`] = `
</div>
</div>
</div>
<div
class="pf-v5-c-form__group"
data-fieldname="nodeToolbarTrigger"
data-testid="wrapper-field"
options="[object Object],[object Object]"
>
<div
class="pf-v5-c-form__group-label"
>
<label
class="pf-v5-c-form__label"
for="uniforms-0000-0008"
>
<span
class="pf-v5-c-form__label-text"
>
Open Node toolbar
</span>
</label>
<div
style="display: contents;"
>
<button
aria-disabled="false"
aria-label="More info for field"
class="pf-v5-c-button pf-m-plain field-hint-button"
data-ouia-component-id="OUIA-Generated-Button-plain-4"
data-ouia-component-type="PF5/Button"
data-ouia-safe="true"
data-testid="field-hint-button"
type="button"
>
<svg
aria-hidden="true"
class="pf-v5-svg"
fill="currentColor"
height="1em"
role="img"
viewBox="0 0 1024 1024"
width="1em"
>
<path
d="M521.3,576 C627.5,576 713.7,502 713.7,413.7 C713.7,325.4 627.6,253.6 521.3,253.6 C366,253.6 334.5,337.7 329.2,407.2 C329.2,414.3 335.2,416 343.5,416 L445,416 C450.5,416 458,415.5 460.8,406.5 C460.8,362.6 582.9,357.1 582.9,413.6 C582.9,441.9 556.2,470.9 521.3,473 C486.4,475.1 447.3,479.8 447.3,521.7 L447.3,553.8 C447.3,570.8 456.1,576 472,576 C487.9,576 521.3,576 521.3,576 M575.3,751.3 L575.3,655.3 C575.313862,651.055109 573.620137,646.982962 570.6,644 C567.638831,640.947672 563.552355,639.247987 559.3,639.29884 L463.3,639.29884 C459.055109,639.286138 454.982962,640.979863 452,644 C448.947672,646.961169 447.247987,651.047645 447.29884,655.3 L447.29884,751.3 C447.286138,755.544891 448.979863,759.617038 452,762.6 C454.961169,765.652328 459.047645,767.352013 463.3,767.30116 L559.3,767.30116 C563.544891,767.313862 567.617038,765.620137 570.6,762.6 C573.659349,759.643612 575.360354,755.553963 575.3,751.3 M512,896 C300.2,896 128,723.9 128,512 C128,300.3 300.2,128 512,128 C723.8,128 896,300.2 896,512 C896,723.8 723.7,896 512,896 M512.1,0 C229.7,0 0,229.8 0,512 C0,794.2 229.8,1024 512.1,1024 C794.4,1024 1024,794.3 1024,512 C1024,229.7 794.4,0 512.1,0"
/>
</svg>
</button>
</div>
</div>
<div
class="pf-v5-c-form__group-control"
>
<div
class="pf-v5-c-menu-toggle pf-m-full-width pf-m-typeahead"
>
<div
class="pf-v5-c-text-input-group pf-m-plain"
>
<div
autocomplete="off"
class="pf-v5-c-text-input-group__main"
data-testid="create-typeahead-select-input"
id="create-typeahead-select-input"
>
<span
class="pf-v5-c-text-input-group__text"
>
<input
aria-controls="select-create-typeahead-listbox"
aria-expanded="false"
aria-label="Type to filter"
class="pf-v5-c-text-input-group__text-input"
placeholder="Select an option"
role="combobox"
type="text"
value="onHover"
/>
</span>
</div>
<div
class="pf-v5-c-text-input-group__utilities"
>
<button
aria-disabled="false"
aria-label="Clear input value"
class="pf-v5-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Button-plain-5"
data-ouia-component-type="PF5/Button"
data-ouia-safe="true"
type="button"
>
<svg
aria-hidden="true"
class="pf-v5-svg"
fill="currentColor"
height="1em"
role="img"
viewBox="0 0 352 512"
width="1em"
>
<path
d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"
/>
</svg>
</button>
</div>
</div>
<button
aria-expanded="false"
aria-label="Menu toggle"
class="pf-v5-c-menu-toggle__button"
data-ouia-component-id="OUIA-Generated-MenuToggle-typeahead-2"
data-ouia-component-type="PF5/MenuToggle"
data-ouia-safe="true"
tabindex="-1"
type="button"
>
<span
class="pf-v5-c-menu-toggle__controls"
>
<span
class="pf-v5-c-menu-toggle__toggle-icon"
>
<svg
aria-hidden="true"
class="pf-v5-svg"
fill="currentColor"
height="1em"
role="img"
viewBox="0 0 320 512"
width="1em"
>
<path
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
/>
</svg>
</span>
</span>
</button>
</div>
</div>
</div>
</div>
</form>
`;
2 changes: 1 addition & 1 deletion packages/ui/src/components/Visualization/Canvas/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const Canvas: FunctionComponent<PropsWithChildren<CanvasProps>> = ({ enti
},
};

controller.fromModel(model, true);
controller.fromModel(model, false);
setInitialized(true);
}, [controller, entities, visibleFlows]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.step-toolbar {
--custom-node-BorderColor: var(--pf-v5-global--BorderColor--100);
--custom-node-BackgroundColor: var(--pf-v5-global--BackgroundColor--100);
--custom-node-BorderRadius: 10px;
--custom-node-Shadow: var(--pf-v5-global--BoxShadow--md);

display: inline-block;
position: relative;
border: 2px solid var(--custom-node-BorderColor);
border-radius: var(--custom-node-BorderRadius);
box-shadow: var(--custom-node-Shadow);
background-color: var(--custom-node-BackgroundColor);
padding: var(--pf-v5-global--spacer--sm);

&__button {
margin-right: 1rem;
}

&__button:last-of-type {
margin-right: 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { Button } from '@patternfly/react-core';
import {
BanIcon,
CheckIcon,
CodeBranchIcon,
CompressArrowsAltIcon,
ExpandArrowsAltIcon,
PlusIcon,
PowerOffIcon,
SyncAltIcon,
TrashIcon,
} from '@patternfly/react-icons';
import clsx from 'clsx';
import { FunctionComponent } from 'react';
import { AddStepMode, IDataTestID, IVisualizationNode } from '../../../../models';
import { useDeleteGroup } from '../../Custom/hooks/delete-group.hook';
import { useDeleteStep } from '../../Custom/hooks/delete-step.hook';
import { useDisableStep } from '../../Custom/hooks/disable-step.hook';
import { useEnableAllSteps } from '../../Custom/hooks/enable-all-steps.hook';
import { useInsertStep } from '../../Custom/hooks/insert-step.hook';
import { useReplaceStep } from '../../Custom/hooks/replace-step.hook';
import './StepToolbar.scss';

interface IStepToolbar extends IDataTestID {
vizNode: IVisualizationNode;
className?: string;
isCollapsed?: boolean;
/** Toggle node collapse / expand */
onCollapseToggle?: () => void;
}

export const StepToolbar: FunctionComponent<IStepToolbar> = ({
vizNode,
className,
isCollapsed = false,
onCollapseToggle,
'data-testid': dataTestId,
}) => {
const { canHaveChildren, canHaveSpecialChildren, canBeDisabled, canReplaceStep, canRemoveStep, canRemoveFlow } =
vizNode.getNodeInteraction();
const { onInsertStep } = useInsertStep(vizNode);
const { onInsertStep: onInsertSpecial } = useInsertStep(vizNode, AddStepMode.InsertSpecialChildStep);
const { onToggleDisableNode, isDisabled } = useDisableStep(vizNode);
const { areMultipleStepsDisabled, onEnableAllSteps } = useEnableAllSteps();
const { onReplaceNode } = useReplaceStep(vizNode);
const { onDeleteStep } = useDeleteStep(vizNode);
const { onDeleteGroup } = useDeleteGroup(vizNode);

return (
<div className={clsx(className, 'step-toolbar')} data-testid={dataTestId}>
{canHaveChildren && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-add"
variant="secondary"
title="Add step"
onClick={(event) => {
onInsertStep();
event.stopPropagation();
}}
>
<PlusIcon />
</Button>
)}

{canHaveSpecialChildren && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-add-special"
variant="secondary"
title="Add branch"
onClick={(event) => {
onInsertSpecial();
event.stopPropagation();
}}
>
<CodeBranchIcon />
</Button>
)}

{canBeDisabled && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-disable"
variant="secondary"
title={isDisabled ? 'Enable step' : 'Disable step'}
onClick={(event) => {
onToggleDisableNode();
event.stopPropagation();
}}
>
{isDisabled ? <CheckIcon /> : <BanIcon />}
</Button>
)}

{areMultipleStepsDisabled && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-enable-all"
variant="secondary"
title="Enable all"
onClick={(event) => {
onEnableAllSteps();
event.stopPropagation();
}}
>
<PowerOffIcon />
</Button>
)}

{canReplaceStep && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-replace"
variant="secondary"
title="Replace step"
onClick={(event) => {
onReplaceNode();
event.stopPropagation();
}}
>
<SyncAltIcon />
</Button>
)}

{onCollapseToggle && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-collapse"
variant="secondary"
title={isCollapsed ? 'Expand step' : 'Collapse step'}
onClick={(event) => {
onCollapseToggle();
event.stopPropagation();
}}
>
{isCollapsed ? <ExpandArrowsAltIcon /> : <CompressArrowsAltIcon />}
</Button>
)}

{canRemoveStep && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-delete"
variant="danger"
title="Delete step"
onClick={(event) => {
onDeleteStep();
event.stopPropagation();
}}
>
<TrashIcon />
</Button>
)}

{canRemoveFlow && (
<Button
className="step-toolbar__button"
data-testid="step-toolbar-button-delete-group"
variant="danger"
title="Delete group"
onClick={(event) => {
onDeleteGroup();
event.stopPropagation();
}}
>
<TrashIcon />
</Button>
)}
</div>
);
};
Loading

0 comments on commit af7ba00

Please sign in to comment.