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/Buttons/Button"; import InputBoolean from "components/Inputs/Base/InputBoolean"; import { useConfirm } from "material-ui-confirm"; import { getNodeSubTypeDescription } from "./utils"; import { useLang } from "services/lang"; export interface NodeEditorProps { node: AutomationNode; allowedTypes?: Array; onClose?: () => void; onSave?: (n: AutomationNode) => void; onFlags?: (isReady: boolean, isModified: boolean) => void; saveBtnCreateText?: boolean; children?: ReactNode; } export const NodeEditor: FC = ({ node, allowedTypes = ["action", "condition", "trigger"], onClose = () => {}, onSave = () => {}, onFlags = () => {}, saveBtnCreateText = false, children, }) => { // state const langStore = useLang(); const state = useEditorNodeState(node, allowedTypes, saveBtnCreateText); const confirm = useConfirm(); // alias const isModified = state.isModified; const isReady = state.isReady(); const areYouSureNotReady = async ( what: string, checkModified: boolean = false ) => { const notes: string[] = []; if (!isReady) { notes.push(langStore.get("VALIDATION_MISSING_VALUES_FOR_NODE")); } if (state.isErrored) { notes.push(langStore.get("VALIDATION_ERROR_VALUES_IN_NODE")); } if (checkModified && isModified) { notes.push(langStore.get("VALIDATION_UNSAVED_WORK_IN_NODE")); } if (notes.length > 0) { try { await confirm({ confirmationText: "Yes", title: langStore.get("CONFIRM_EXIT", { what }), description: ( ), }); } catch (_: any) { return false; } } return true; }; // events onFlags(isReady, isModified); // render return (
{allowedTypes.length > 1 ? ( ) : ( <> )} {state.nodeType !== "condition" ? ( ) : ( <> )}
{state.renderOptionList()}
{children}
); };