updated automation metadata

This commit is contained in:
Ari Sosnovsky committed 2021-11-12 14:39:55 -05:00
1 parent 54c1edba0c
commit ccca0edb65
20 files changed
+238 -723

No files matched your search

+36 -82
View File
@@ -1,87 +1,41 @@
import { useState } from "react";
import * as types from "../../automation/types";
import AutomationNode from "./AutomationNode";
import NewNodeModal from "./NewNodeModal";
import ScriptNode from "./ScriptNode";
import { AutomationData } from "~/automations/types";
import AutoInfoBox from "./AutoInfoBox";
export interface Props {
automation: types.Automation;
interface Props {
automation: AutomationData;
onUpdate: (auto: AutomationData) => void;
}
export default function AutomationEditor({ automation }: Props) {
// state
const [modalState, setModalState] = useState<types.AutomationNodeType | null>(null);
const [state, setState] = useState(automation);
export default function AutomationEditor({
automation,
onUpdate,
}: Props) {
// helper state functions
const addNode = <T extends types.AutomationNodeType>(node_type: T, node: types.AutomationNodeTypes[T]) => {
const nodes: types.AutomationNode<T>[] = state[node_type];
setState({
...state,
[node_type]: nodes.concat([node as any])
});
}
const removeNode = <T extends types.AutomationNodeType>(node_type: T, node_id: number) => {
const nodes: types.AutomationNode<T>[] = state[node_type];
setState({
...state,
[node_type]: nodes
.slice(0, node_id)
.concat(
nodes.slice(
node_id + 1,
nodes.length
)
)
});
}
// helper element functions
const makeChild = <T extends types.AutomationNodeType>(node_type: T) => {
return [
<div className="automation-editor--elm-list" key="list">
{state[node_type].map((n, i) => (
<ScriptNode
key={i}
onDelete={() => removeNode(node_type, i)}
data={n as any}
/>
))}
</div>,
<button
key="btn"
className="elm-list"
onClick={() => setModalState(node_type)}
>
Add +
</button>
];
}
const graphWidth = 300;
const graphHeight = 300;
return <div className="automation-editor">
<AutomationNode
title={`${automation.alias} (${automation.mode})`}
initialOpenState={true}
>
<div className="automation-editor--root">
<div className="automation-editor--triggers">
<h4>Trigger</h4>
{makeChild("trigger")}
<h4>Condition</h4>
{makeChild("condition")}
</div>
<div className="automation-editor--playground">
<h4>Actions</h4>
{makeChild("action")}
</div>
</div>
</AutomationNode>
{modalState && <NewNodeModal
node_type={modalState}
onClose={() => setModalState(null)}
onCreate={node => {
addNode(modalState, node);
setModalState(null);
}}
/>}
</div>
return <div className="automation-dag" >
<svg
viewBox={[0,0,graphWidth, graphHeight].join(" ")}
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
markerWidth="6" markerHeight="6"
orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" />
</marker>
</defs>
<AutoInfoBox
metadata={automation.metadata}
onUpdate={metadata => onUpdate({...automation, metadata})}
/>
{/* <rect x="1" y="1" height={GRAPH_HEIGHT-1} width={GRAPH_WIDTH} stroke="white" fill="none"/> */}
{/* <g className="automation-dag-edges">
</g>
<g className="automation-dag-nodes">
</g> */}
</svg>
</div>
}