From 9a171c880efe2c32ae49e443637dc4eb117a23fc Mon Sep 17 00:00:00 2001 From: Ari Date: Thu, 30 Jun 2022 20:37:38 -0400 Subject: [PATCH] updated messages --- webapp/src/components/DAGFlow/helpers.tsx | 17 +++++++--- webapp/src/components/NodeEditor/index.tsx | 39 +++++++++++----------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/webapp/src/components/DAGFlow/helpers.tsx b/webapp/src/components/DAGFlow/helpers.tsx index d78ed8e..25e32cf 100644 --- a/webapp/src/components/DAGFlow/helpers.tsx +++ b/webapp/src/components/DAGFlow/helpers.tsx @@ -37,10 +37,19 @@ export const makeOnEditAutomationConditions = () => openModal({ single: true, - node: { - condition: "and", - conditions, - }, + node: + conditions.length > 1 + ? { + condition: "and", + conditions, + } + : conditions.length === 1 + ? conditions[0] + : { + condition: "state", + entity_id: "", + state: "", + }, allowedTypes: ["condition"], update: (c: AutomationCondition) => { if (c.condition === "and") { diff --git a/webapp/src/components/NodeEditor/index.tsx b/webapp/src/components/NodeEditor/index.tsx index e7f7e34..3f48726 100644 --- a/webapp/src/components/NodeEditor/index.tsx +++ b/webapp/src/components/NodeEditor/index.tsx @@ -36,29 +36,30 @@ export const NodeEditor: FC = ({ // alias const isModified = state.isModified; const isReady = state.isReady(); - const areYouSureNotReady = async (what: string) => { - if (isModified) { - try { - await confirm({ - description: `This node is has some unsaved work, are you sure you want to ${what}?`, - }); - } catch (_: any) { - return false; - } - } + const areYouSureNotReady = async ( + what: string, + checkModified: boolean = false + ) => { + const notes: string[] = []; if (!isReady) { - try { - await confirm({ - description: `This node is missing some values, are you sure you want to ${what}?`, - }); - } catch (_: any) { - return false; - } + notes.push("This node is missing some values"); } if (state.isErrored) { + notes.push("This node contains errors"); + } + if (checkModified && isModified) { + notes.push("This node is has some unsaved work"); + } + if (notes.length > 0) { try { await confirm({ - description: `This node contains errors, are you sure you want to ${what}?`, + description: ( + + ), }); } catch (_: any) { return false; @@ -126,7 +127,7 @@ export const NodeEditor: FC = ({