condition + repeat node
This commit is contained in:
1 parent
89c7007612
commit
07ab4b9089
22 files changed
+631
-282
No files matched your search
@@ -85,3 +85,8 @@ const Template: ComponentStory<typeof ButtonNode> = (args) => {
|
||||
};
|
||||
|
||||
export const Basic = Template.bind({});
|
||||
export const Text = Template.bind({});
|
||||
Text.args = {
|
||||
...Text.args,
|
||||
text: "Option",
|
||||
};
|
||||
@@ -11,4 +11,9 @@
|
||||
align-items: center;
|
||||
|
||||
/* outline: 1px dashed white; */
|
||||
}
|
||||
|
||||
.button-node button {
|
||||
display: flex;
|
||||
gap: 0.25em;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { FC } from "react";
|
||||
import { ButtonNodeProps } from "./types";
|
||||
import { Handle, Position } from "react-flow-renderer";
|
||||
import { Button } from "components/Inputs/Button";
|
||||
|
||||
export const ButtonNode: FC<ButtonNodeProps> = ({
|
||||
height,
|
||||
@@ -11,7 +12,18 @@ export const ButtonNode: FC<ButtonNodeProps> = ({
|
||||
icon,
|
||||
flipped,
|
||||
onClick,
|
||||
text,
|
||||
}) => {
|
||||
const inner = (
|
||||
<>
|
||||
<Handle type="target" position={flipped ? Position.Top : Position.Left} />
|
||||
{icon}
|
||||
<Handle
|
||||
type="source"
|
||||
position={!flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<div
|
||||
className="button-node"
|
||||
@@ -22,22 +34,14 @@ export const ButtonNode: FC<ButtonNodeProps> = ({
|
||||
} as any
|
||||
}
|
||||
>
|
||||
<ButtonIcon
|
||||
icon={
|
||||
<>
|
||||
<Handle
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
{icon}
|
||||
<Handle
|
||||
type="source"
|
||||
position={!flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
onClick={onClick}
|
||||
/>
|
||||
{!text ? (
|
||||
<ButtonIcon icon={inner} onClick={onClick} />
|
||||
) : (
|
||||
<Button onClick={onClick}>
|
||||
{inner}
|
||||
{text}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { ReactNode } from "react";
|
||||
export type ButtonNodeDataProps = {
|
||||
icon: ReactNode;
|
||||
onClick: () => void;
|
||||
text?: string;
|
||||
};
|
||||
|
||||
export type ButtonNodeProps = ButtonNodeDataProps & {
|
||||
|
||||
@@ -8,6 +8,9 @@ import { CollectionNodeProps } from "./types";
|
||||
import { Handle, Position } from "react-flow-renderer";
|
||||
import { useSequenceNodeColor } from "../SequenceNode/util";
|
||||
import { prettyName } from "utils/formatting";
|
||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||
import { useConfirm } from "material-ui-confirm";
|
||||
import { useSnackbar } from "notistack";
|
||||
|
||||
export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
onAddNode,
|
||||
@@ -18,8 +21,13 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
flipped,
|
||||
color,
|
||||
collectionType,
|
||||
onDelete,
|
||||
title,
|
||||
}) => {
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const trueTile = title ?? collectionType;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -33,6 +41,30 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
}
|
||||
>
|
||||
<div className="collection-nodes">
|
||||
{!!onDelete && (
|
||||
<ButtonIcon
|
||||
className="delete-icon"
|
||||
icon={<DeleteForeverIcon />}
|
||||
onClick={() => {
|
||||
confirm({
|
||||
description: `Are you sure you want to delete ${trueTile}?`,
|
||||
})
|
||||
.then(() => {
|
||||
onDelete();
|
||||
snackbr.enqueueSnackbar("Deleted.", {
|
||||
variant: "info",
|
||||
});
|
||||
})
|
||||
.catch(() =>
|
||||
snackbr.enqueueSnackbar(`Did not delete ${trueTile}.`, {
|
||||
variant: "info",
|
||||
})
|
||||
);
|
||||
}}
|
||||
borderless
|
||||
color="secondary"
|
||||
/>
|
||||
)}
|
||||
<span className="collection-nodes--title">
|
||||
{prettyName(collectionType)}s
|
||||
</span>
|
||||
@@ -48,23 +80,38 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
))}
|
||||
</div>
|
||||
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
|
||||
<Handle
|
||||
key="source"
|
||||
type="source"
|
||||
position={flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
<>
|
||||
<Handle
|
||||
id="default"
|
||||
key="target"
|
||||
key="source-def"
|
||||
type="source"
|
||||
position={flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
<Handle
|
||||
id="head"
|
||||
key="source-head"
|
||||
type="source"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
</>
|
||||
<>
|
||||
<Handle
|
||||
id="default"
|
||||
key="target-def"
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
<Handle
|
||||
id="side"
|
||||
key="target-side"
|
||||
type="target"
|
||||
position={!flipped ? Position.Right : Position.Left}
|
||||
/>
|
||||
<Handle
|
||||
id="return"
|
||||
key="target-return"
|
||||
type="target"
|
||||
position={!flipped ? Position.Top : Position.Right}
|
||||
position={!flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
</>
|
||||
<span className="collection-nodes--total">
|
||||
|
||||
@@ -14,6 +14,7 @@ type DemoProps = {
|
||||
width: number;
|
||||
totalChildNodes: number;
|
||||
onAddNode: () => void;
|
||||
hasDelete: boolean;
|
||||
enabledChild: boolean;
|
||||
};
|
||||
const Demo: FC<DemoProps> = (args) => {
|
||||
@@ -26,7 +27,7 @@ const Demo: FC<DemoProps> = (args) => {
|
||||
data: {
|
||||
elements: {
|
||||
edges: [],
|
||||
nodes: ["trogger", "sequence", "condition"].map(
|
||||
nodes: ["trigger", "sequence", "condition"].map(
|
||||
(collectionType: any, i: number) =>
|
||||
CollectionNodeMaker.makeElement(
|
||||
{
|
||||
@@ -40,6 +41,7 @@ const Demo: FC<DemoProps> = (args) => {
|
||||
{
|
||||
hasInput: false,
|
||||
onAddNode: args.onAddNode,
|
||||
onDelete: args.hasDelete ? console.info : undefined,
|
||||
width: args.width,
|
||||
height: args.height,
|
||||
nodes: [
|
||||
@@ -71,9 +73,10 @@ export default {
|
||||
component: Demo,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
...DEFAULT_DIMS.condition,
|
||||
...DEFAULT_DIMS.collection,
|
||||
totalChildNodes: 1,
|
||||
enabledChild: true,
|
||||
hasDelete: false,
|
||||
},
|
||||
} as ComponentMeta<typeof Demo>;
|
||||
|
||||
@@ -101,6 +104,7 @@ export const Empty: ComponentStory<typeof Demo> = (args) => {
|
||||
DEFAULT_DIMS,
|
||||
{
|
||||
hasInput: false,
|
||||
onDelete: args.hasDelete ? console.info : undefined,
|
||||
onAddNode: args.onAddNode,
|
||||
width: args.width,
|
||||
height: args.height,
|
||||
@@ -194,6 +198,7 @@ export const ReturnTarget: ComponentStory<typeof Demo> = (args) => {
|
||||
},
|
||||
DEFAULT_DIMS,
|
||||
{
|
||||
onDelete: args.hasDelete ? console.info : undefined,
|
||||
onAddNode: args.onAddNode,
|
||||
width: args.width,
|
||||
height: args.height,
|
||||
@@ -220,3 +225,9 @@ export const ReturnTarget: ComponentStory<typeof Demo> = (args) => {
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
export const DeleteIconExample = Empty.bind({});
|
||||
DeleteIconExample.args = {
|
||||
...DeleteIconExample.args,
|
||||
hasDelete: true,
|
||||
};
|
||||
@@ -12,6 +12,8 @@ export type CollectionNodeDataProps = Size & {
|
||||
onAddNode: () => void;
|
||||
hasInput?: boolean;
|
||||
collectionType: keyof AutomationActionData;
|
||||
onDelete?: () => void;
|
||||
title?: string;
|
||||
};
|
||||
|
||||
export type CollectionNodeProps = CollectionNodeDataProps & {
|
||||
|
||||
@@ -10,15 +10,22 @@ export const SequenceNode: FC<SequenceNodeProps> = ({
|
||||
return (
|
||||
<SequenceNodeElement {...props}>
|
||||
{hasInput && (
|
||||
<Handle
|
||||
type="target"
|
||||
position={props.flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
<>
|
||||
<Handle
|
||||
type="target"
|
||||
position={props.flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Handle
|
||||
type="source"
|
||||
position={props.flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
<Handle
|
||||
id="side"
|
||||
type="source"
|
||||
position={props.flipped ? Position.Right : Position.Bottom}
|
||||
/>
|
||||
</SequenceNodeElement>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user