import "./index.css"; import { FC, ReactNode } from "react"; import { AutomationNode, AutomationNodeMapping } from "types/automations/index"; import { useEditorNodeState } from "./OptionManager"; import { InputList } from "components/Inputs/InputList"; import { Button } from "components/Inputs/Button"; import InputBoolean from "components/Inputs/InputBoolean"; export interface NodeEditorProps { node: AutomationNode; allowedTypes?: Array; onClose?: () => void; onSave?: (n: AutomationNode) => void; onFlags?: (isReady: boolean, isModified: boolean) => void; saveBtnCreateText?: boolean; isErrored?: boolean; children?: ReactNode; } export const NodeEditor: FC = ({ node, allowedTypes = ["action", "condition", "trigger"], onClose = () => {}, onSave = () => {}, onFlags = () => {}, saveBtnCreateText = false, children, isErrored = false, }) => { // state const state = useEditorNodeState(node, isErrored, allowedTypes); // alias const isModified = state.isModified; const isReady = state.isReady(); const areYouSureNotReady = (what: string) => !isReady ? window.confirm( `This node is missing some values, are you sure you want to ${what}?` ) : state.isErrored ? window.confirm( `This node contains errors, are you sure you want to ${what}?` ) : true; // events onFlags(isReady, isModified); // render return (
{allowedTypes.length > 1 ? ( ) : ( <> )} {state.nodeType !== "condition" ? ( ) : ( <> )}
{state.renderOptionList()}
{children}
); };