refactor of graph pt2
This commit is contained in:
1 parent
730c804c22
commit
2cb2e779d7
20 files changed
+714
-246
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||
import { Page } from "components/Page";
|
||||
import { ButtonNode } from "./ButtonNode";
|
||||
import { DAGGraphBoard } from "components/DAGGraph/board";
|
||||
import { ButtonNodeMaker } from ".";
|
||||
import { DEFAULT_DIMS } from "../../elements/constants";
|
||||
import { AddIcon } from "components/Icons";
|
||||
import { SequenceNodeMaker } from "../SequenceNode";
|
||||
|
||||
export default {
|
||||
title: "DAGGraph/Nodes/Button",
|
||||
component: ButtonNode,
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
icon: <AddIcon />,
|
||||
flipped: true,
|
||||
...DEFAULT_DIMS.node,
|
||||
},
|
||||
} as ComponentMeta<typeof ButtonNode>;
|
||||
|
||||
const Template: ComponentStory<typeof ButtonNode> = (args) => {
|
||||
const dims = {
|
||||
...DEFAULT_DIMS,
|
||||
...args,
|
||||
};
|
||||
return (
|
||||
<Page>
|
||||
<DAGGraphBoard
|
||||
closeModal={() => {}}
|
||||
state={{
|
||||
ready: true,
|
||||
data: {
|
||||
elements: {
|
||||
edges: [
|
||||
{
|
||||
id: `${dims.flipped}-1`,
|
||||
source: `${dims.flipped}-node`,
|
||||
target: `${dims.flipped}-button`,
|
||||
},
|
||||
],
|
||||
nodes: [
|
||||
SequenceNodeMaker.makeElement(
|
||||
{
|
||||
id: `${dims.flipped}-node`,
|
||||
position: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
dims,
|
||||
{
|
||||
label: "test",
|
||||
color: "lblue",
|
||||
enabled: true,
|
||||
}
|
||||
),
|
||||
ButtonNodeMaker.makeElement(
|
||||
{
|
||||
id: `${dims.flipped}-button`,
|
||||
position: !dims.flipped
|
||||
? {
|
||||
x:
|
||||
DEFAULT_DIMS.node.width *
|
||||
DEFAULT_DIMS.distanceFactor.node,
|
||||
y: 0,
|
||||
}
|
||||
: {
|
||||
x: 0,
|
||||
y:
|
||||
DEFAULT_DIMS.node.height *
|
||||
DEFAULT_DIMS.distanceFactor.node,
|
||||
},
|
||||
},
|
||||
dims,
|
||||
args
|
||||
),
|
||||
],
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
export const Basic = Template.bind({});
|
||||
@@ -0,0 +1,14 @@
|
||||
.button-node {
|
||||
max-width: var(--button-width);
|
||||
max-height: var(--button-height);
|
||||
min-width: var(--button-width);
|
||||
min-height: var(--button-height);
|
||||
width: var(--button-width);
|
||||
height: var(--button-height);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
/* outline: 1px dashed white; */
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import "./ButtonNode.css";
|
||||
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { FC } from "react";
|
||||
import { ButtonNodeProps } from "./types";
|
||||
import { Handle, Position } from "react-flow-renderer";
|
||||
|
||||
export const ButtonNode: FC<ButtonNodeProps> = ({
|
||||
height,
|
||||
width,
|
||||
icon,
|
||||
flipped,
|
||||
onClick,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className="button-node"
|
||||
style={
|
||||
{
|
||||
"--button-height": `${height}px`,
|
||||
"--button-width": `${width}px`,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
<ButtonIcon
|
||||
icon={
|
||||
<>
|
||||
<Handle
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
{icon}
|
||||
</>
|
||||
}
|
||||
onClick={onClick}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NodeManager } from "components/DAGGraph/nodes/NodeManager";
|
||||
import { ButtonNode } from "./ButtonNode";
|
||||
import { ButtonNodeDataProps } from "./types";
|
||||
|
||||
export const ButtonNodeMaker = NodeManager.register(
|
||||
"ButtonNode",
|
||||
ButtonNode,
|
||||
(pre: ButtonNodeDataProps, { node, flipped }) => ({
|
||||
...node,
|
||||
...pre,
|
||||
flipped,
|
||||
})
|
||||
);
|
||||
@@ -0,0 +1,12 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
export type ButtonNodeDataProps = {
|
||||
icon: ReactNode;
|
||||
onClick: () => void;
|
||||
};
|
||||
|
||||
export type ButtonNodeProps = ButtonNodeDataProps & {
|
||||
width: number;
|
||||
height: number;
|
||||
flipped: boolean;
|
||||
};
|
||||
@@ -26,7 +26,7 @@
|
||||
max-width: var(--child-width);
|
||||
max-height: var(--child-height);
|
||||
|
||||
border-color: var(--child-color);
|
||||
border-color: var(--node-color);
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-radius: 10px;
|
||||
@@ -36,4 +36,11 @@
|
||||
|
||||
.collection-nodes .react-flow__handle {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.collection-nodes--total {
|
||||
position: absolute;
|
||||
bottom: 0.25em;
|
||||
right: 0.25em;
|
||||
font-size: 0.5em;
|
||||
}
|
||||
@@ -52,6 +52,9 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
)}
|
||||
<span className="collection-nodes--total">
|
||||
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -5,9 +5,24 @@
|
||||
align-items: center;
|
||||
cursor: default;
|
||||
|
||||
max-height: var(--sequence-node-height);
|
||||
max-width: var(--sequence-node-width);
|
||||
height: var(--sequence-node-height);
|
||||
width: var(--sequence-node-width);
|
||||
min-height: var(--sequence-node-height);
|
||||
min-width: var(--sequence-node-width);
|
||||
|
||||
/* outline: 1px dotted white; */
|
||||
}
|
||||
|
||||
.sequence-node.disabled .sequence-node--inner {
|
||||
background-color: var(--mui-grey-500);
|
||||
}
|
||||
|
||||
.sequence-node.enabled .sequence-node--inner {
|
||||
background-color: var(--mui-background-default);
|
||||
}
|
||||
|
||||
.sequence-node--inner {
|
||||
position: relative;
|
||||
display: flex;
|
||||
@@ -20,6 +35,15 @@
|
||||
border-left-width: 1px;
|
||||
border-right-width: 1px;
|
||||
border-radius: 10px;
|
||||
|
||||
|
||||
border-bottom-color: var(--mui-grey-500);
|
||||
border-left-color: var(--mui-grey-700);
|
||||
border-right-color: var(--mui-grey-700);
|
||||
border-top-color: var(--sequence-node-color);
|
||||
max-height: calc(var(--sequence-node-height) - 1em);
|
||||
max-width: calc(var(--sequence-node-width) - 1em);
|
||||
min-width: calc(max(var(--sequence-node-width) / 2, var(--sequence-node-height) / 2));
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +53,10 @@
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
|
||||
max-height: calc(var(--sequence-node-height) - 1em);
|
||||
max-width: calc(var(--sequence-node-width) - 1em);
|
||||
min-height: 1em;
|
||||
}
|
||||
|
||||
.sequence-node--label span {
|
||||
|
||||
@@ -17,6 +17,7 @@ export default {
|
||||
width: dgconst.NODE_WIDTH,
|
||||
label: "test",
|
||||
hasInput: true,
|
||||
enabled: true,
|
||||
},
|
||||
} as ComponentMeta<typeof SequenceNode>;
|
||||
|
||||
|
||||
@@ -35,11 +35,9 @@ export const SequenceNodeElement: FC<
|
||||
onSetEnabled,
|
||||
children,
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
console.log({ onAdd });
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
@@ -48,26 +46,15 @@ export const SequenceNodeElement: FC<
|
||||
flipped ? "flipped" : "",
|
||||
enabled ? "enabled" : "disabled",
|
||||
].join(" ")}
|
||||
style={{
|
||||
height,
|
||||
width,
|
||||
}}
|
||||
style={
|
||||
{
|
||||
"--sequence-node-height": height + "px",
|
||||
"--sequence-node-width": width + "px",
|
||||
"--sequence-node-color": nodeColor,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
<div
|
||||
className="sequence-node--inner"
|
||||
style={{
|
||||
maxHeight: `calc(${height}px - 1em)`,
|
||||
maxWidth: `calc(${width}px - 1em)`,
|
||||
minWidth: Math.max(width / 2, height / 2),
|
||||
borderBottomColor: theme.palette.grey[500],
|
||||
borderLeftColor: theme.palette.grey[700],
|
||||
borderRightColor: theme.palette.grey[700],
|
||||
borderTopColor: nodeColor,
|
||||
backgroundColor: enabled
|
||||
? theme.palette.background.default
|
||||
: theme.palette.grey[600],
|
||||
}}
|
||||
>
|
||||
<div className="sequence-node--inner">
|
||||
<SpeedDial
|
||||
icon={
|
||||
<SettingsOutlinedIcon className="sequence-node--actions-btn" />
|
||||
@@ -131,22 +118,10 @@ export const SequenceNodeElement: FC<
|
||||
/>
|
||||
)}
|
||||
{children}
|
||||
<div
|
||||
className="sequence-node--label"
|
||||
style={{
|
||||
maxHeight: `calc(${height}px - 1em)`,
|
||||
maxWidth: `calc(${width}px - 1em)`,
|
||||
minHeight: `1em`,
|
||||
}}
|
||||
>
|
||||
<div className="sequence-node--label">
|
||||
{typeof label === "string" ? <span>{label}</span> : label}
|
||||
</div>
|
||||
</div>
|
||||
{/* {onAddNode && (
|
||||
<div className="sequence-node--midway-options">
|
||||
<ButtonIcon icon={<Add />} onClick={onAddNode} />
|
||||
</div>
|
||||
)} */}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { Node, NodeTypes } from "react-flow-renderer";
|
||||
import { NodeManager } from "./NodeManager";
|
||||
import { CollectionNodeProps } from "./CollectionNode/types";
|
||||
import { SequenceNodeProps } from "./SequenceNode/types";
|
||||
import { ButtonNodeProps } from "./ButtonNode/types";
|
||||
|
||||
export const nodeTypes: NodeTypes = NodeManager.nodeTypes;
|
||||
export type DAGAutomationFlowNode = Node<any>;
|
||||
export type DAGAutomationFlowNode = Node<
|
||||
CollectionNodeProps | SequenceNodeProps | ButtonNodeProps
|
||||
>;
|
||||
Reference in new issue
Block a user