experimenting with noderow
This commit is contained in:
1 parent
5115dd9490
commit
bee584d85c
9 files changed
+242
-135
No files matched your search
@@ -1,123 +1,45 @@
|
||||
import "./CollectionNode.css";
|
||||
|
||||
import Add from "@mui/icons-material/Add";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { FC } from "react";
|
||||
import { SequenceNodeElement } from "../SequenceNode/SequenceNodeElement";
|
||||
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,
|
||||
nodes,
|
||||
sequenceNode,
|
||||
height,
|
||||
width,
|
||||
flipped,
|
||||
color,
|
||||
collectionType,
|
||||
onDelete,
|
||||
title,
|
||||
}) => {
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const trueTile = title ?? collectionType;
|
||||
import { CollectionNodeElement } from "./CollectionNodeElement";
|
||||
|
||||
export const CollectionNode: FC<CollectionNodeProps> = (props) => {
|
||||
return (
|
||||
<div
|
||||
className="collection-nodes--wrap"
|
||||
style={
|
||||
{
|
||||
"--node-color": nodeColor,
|
||||
"--node-height": `${height}px`,
|
||||
"--node-width": `${width}px`,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
<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>
|
||||
<div className="collection-nodes--inner">
|
||||
{nodes.map((n, i) => (
|
||||
<SequenceNodeElement
|
||||
key={i}
|
||||
color={color}
|
||||
flipped={flipped}
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
|
||||
<>
|
||||
<Handle
|
||||
id="default"
|
||||
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.Bottom : Position.Right}
|
||||
/>
|
||||
</>
|
||||
<span className="collection-nodes--total">
|
||||
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<CollectionNodeElement {...props}>
|
||||
<>
|
||||
<Handle
|
||||
id="default"
|
||||
key="source-def"
|
||||
type="source"
|
||||
position={props.flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
<Handle
|
||||
id="head"
|
||||
key="source-head"
|
||||
type="source"
|
||||
position={props.flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
</>
|
||||
<>
|
||||
<Handle
|
||||
id="default"
|
||||
key="target-def"
|
||||
type="target"
|
||||
position={props.flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
<Handle
|
||||
id="side"
|
||||
key="target-side"
|
||||
type="target"
|
||||
position={!props.flipped ? Position.Right : Position.Left}
|
||||
/>
|
||||
<Handle
|
||||
id="return"
|
||||
key="target-return"
|
||||
type="target"
|
||||
position={!props.flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
</>
|
||||
</CollectionNodeElement>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
import "./CollectionNode.css";
|
||||
|
||||
import Add from "@mui/icons-material/Add";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { FC, PropsWithChildren } from "react";
|
||||
import { SequenceNodeElement } from "../SequenceNode/SequenceNodeElement";
|
||||
import { CollectionNodeProps } from "./types";
|
||||
import {
|
||||
convertNodeTypeToSequenceNodeColor,
|
||||
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 CollectionNodeElement: FC<PropsWithChildren<CollectionNodeProps>> =
|
||||
({
|
||||
onAddNode,
|
||||
nodes,
|
||||
sequenceNode,
|
||||
height,
|
||||
width,
|
||||
flipped,
|
||||
collectionType,
|
||||
onDelete,
|
||||
title,
|
||||
children,
|
||||
}) => {
|
||||
const color = convertNodeTypeToSequenceNodeColor(collectionType);
|
||||
const nodeColor = useSequenceNodeColor(color);
|
||||
const confirm = useConfirm();
|
||||
const snackbr = useSnackbar();
|
||||
const trueTile = title ?? collectionType;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="collection-nodes--wrap"
|
||||
style={
|
||||
{
|
||||
"--node-color": nodeColor,
|
||||
"--node-height": `${height}px`,
|
||||
"--node-width": `${width}px`,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
<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>
|
||||
<div className="collection-nodes--inner">
|
||||
{nodes.map((n, i) => (
|
||||
<SequenceNodeElement
|
||||
key={i}
|
||||
color={color}
|
||||
flipped={flipped}
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
|
||||
{children}
|
||||
<span className="collection-nodes--total">
|
||||
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,18 +1,12 @@
|
||||
import { NodeManager } from "components/DAGGraph/nodes/NodeManager";
|
||||
import { CollectionNode } from "./CollectionNode";
|
||||
import { CollectionNodeDataProps } from "./types";
|
||||
import { SequenceNodeColor } from "../SequenceNode/types";
|
||||
|
||||
export const CollectionNodeMaker = NodeManager.register(
|
||||
"CollectionNode",
|
||||
CollectionNode,
|
||||
(pre: CollectionNodeDataProps, { node, flipped }) => ({
|
||||
...pre,
|
||||
color: (pre.collectionType === "condition"
|
||||
? "blue"
|
||||
: pre.collectionType === "action"
|
||||
? "green"
|
||||
: "red") as SequenceNodeColor,
|
||||
sequenceNode: node,
|
||||
flipped,
|
||||
})
|
||||
|
||||
@@ -20,5 +20,4 @@ export type CollectionNodeDataProps = Size & {
|
||||
export type CollectionNodeProps = CollectionNodeDataProps & {
|
||||
sequenceNode: Size;
|
||||
flipped: boolean;
|
||||
color: SequenceNodeColor;
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
import { SequenceNodeColor } from "./types";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { AutomationNodeMapping } from "types/automations";
|
||||
|
||||
export const useSequenceNodeColor = (color: SequenceNodeColor): string => {
|
||||
const theme = useTheme();
|
||||
@@ -16,3 +17,8 @@ export const useSequenceNodeColor = (color: SequenceNodeColor): string => {
|
||||
? theme.palette.error.dark
|
||||
: "none";
|
||||
};
|
||||
|
||||
export const convertNodeTypeToSequenceNodeColor = (
|
||||
type: keyof AutomationNodeMapping
|
||||
): SequenceNodeColor =>
|
||||
type === "condition" ? "blue" : type === "action" ? "green" : "red";
|
||||
Reference in new issue
Block a user