initial attempt at visual
This commit is contained in:
1 parent
126f1df657
commit
08a50051d5
16 files changed
+170
-42
No files matched your search
@@ -36,7 +36,7 @@ export default function NewNodeModal<T extends AutomationNodeType>({
|
||||
</div>
|
||||
<div className="new-node-modal--footer">
|
||||
<button onClick={() => onClose()}>Close</button>
|
||||
<button onClick={() => onCreate({} as any)}
|
||||
<button onClick={() => onCreate(stateManager.state)}
|
||||
disabled={!stateManager.isReady}>
|
||||
Create
|
||||
</button>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import StateManager from "../../automation/StateManager";
|
||||
import { AutomationAction } from "../../automation/types";
|
||||
import { determineNodeTypes, getNameFromAction } from "../../automation/utils";
|
||||
import AutomationNode from "../Node";
|
||||
|
||||
|
||||
export interface Props {
|
||||
data: AutomationAction;
|
||||
onDelete: () => void;
|
||||
}
|
||||
export default function ScriptNode({
|
||||
data,
|
||||
onDelete,
|
||||
}: Props) {
|
||||
const [nodeType, nodeSubType] = determineNodeTypes(data);
|
||||
const stateManager = new StateManager(nodeType, nodeSubType, data);
|
||||
|
||||
return <AutomationNode title={getNameFromAction(data)} onXClick={onDelete}>
|
||||
{stateManager.renderOptionList()}
|
||||
</AutomationNode>
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import * as types from "../../automation/types";
|
||||
import { getNameFromAction } from "../../automation/utils";
|
||||
import AutomationNode from "../Node";
|
||||
import NewNodeModal from "./NewNodeModal";
|
||||
import ScriptNode from "./ScriptNode";
|
||||
|
||||
export interface Props {
|
||||
automation: types.Automation;
|
||||
@@ -36,16 +37,13 @@ export default function AutomationEditor({ automation }: Props) {
|
||||
}
|
||||
// helper element functions
|
||||
const makeChild = <T extends types.AutomationNodeType>(node_type: T) => {
|
||||
const nodes: types.AutomationNode<T>[] = state[node_type];
|
||||
return [
|
||||
<div className="automation-box--elm-list" key="list">
|
||||
<div className="automation-editor--elm-list" key="list">
|
||||
{state[node_type].map((n, i) => (
|
||||
<AutomationNode
|
||||
<ScriptNode
|
||||
key={i}
|
||||
title={getNameFromAction(n)}
|
||||
showX={false}
|
||||
initialOpenState={false}
|
||||
onXClick={() => removeNode(node_type, i)}
|
||||
onDelete={() => removeNode(node_type, i)}
|
||||
data={n as any}
|
||||
/>
|
||||
))}
|
||||
</div>,
|
||||
@@ -63,16 +61,19 @@ export default function AutomationEditor({ automation }: Props) {
|
||||
<AutomationNode
|
||||
title={`${automation.alias} (${automation.mode})`}
|
||||
initialOpenState={true}
|
||||
showChildren={true}
|
||||
showX={false}
|
||||
>
|
||||
<div className="automation-editor--root">
|
||||
<h4>Trigger</h4>
|
||||
{makeChild("trigger")}
|
||||
<h4>Condition</h4>
|
||||
{makeChild("condition")}
|
||||
<h4>Actions</h4>
|
||||
{makeChild("action")}
|
||||
<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
|
||||
|
||||
@@ -2,16 +2,12 @@ import { PropsWithChildren, useState } from "react";
|
||||
|
||||
export interface Props {
|
||||
title: string;
|
||||
showX?: boolean;
|
||||
showChildren?: boolean;
|
||||
initialOpenState?: boolean;
|
||||
onXClick?: () => void;
|
||||
}
|
||||
export default function AutomationNode({
|
||||
children,
|
||||
title,
|
||||
showX=false,
|
||||
showChildren=false,
|
||||
initialOpenState=false,
|
||||
onXClick = () => {},
|
||||
}: PropsWithChildren<Props>) {
|
||||
@@ -22,20 +18,18 @@ export default function AutomationNode({
|
||||
className="automation-node-inner-edge left"
|
||||
onClick={() => onXClick()}
|
||||
>
|
||||
{showX && (
|
||||
<div className="automation-node-side-button">X</div>
|
||||
)}
|
||||
<div className="automation-node-side-button">X</div>
|
||||
</div>
|
||||
<div className="automation-node-inner-text">{title}</div>
|
||||
<div
|
||||
className="automation-node-inner-edge right"
|
||||
onClick={() => setOpen(!isOpen)}
|
||||
>
|
||||
{showChildren && <div className="automation-node-side-button">{isOpen ? "▲" : "▼"}</div>}
|
||||
<div className="automation-node-side-button">{isOpen ? "▲" : "▼"}</div>
|
||||
</div>
|
||||
</div>
|
||||
{showChildren&&<div className={`automation-node-children ${isOpen ? "open" : "closed"}`}>
|
||||
<div className={`automation-node-children ${isOpen ? "open" : "closed"}`}>
|
||||
{children}
|
||||
</div>}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
Reference in new issue
Block a user