From 911f86751816cb17b5196462da36c0b264388a4a Mon Sep 17 00:00:00 2001 From: Ari Date: Sat, 4 Jun 2022 22:10:41 -0400 Subject: [PATCH] fixed up issues with saving --- webapp/src/apiService/index.ts | 1 - webapp/src/components/DAGFlow/index.tsx | 6 ++++- webapp/src/components/DAGFlow/updater.ts | 22 +++++++++++-------- .../src/components/MultiNodeEditors/index.css | 12 ++++++++++ .../src/components/MultiNodeEditors/index.tsx | 15 ++++++------- .../src/components/MultiNodeEditors/state.ts | 18 +++++++++++++-- webapp/src/components/NodeEditor/index.tsx | 6 +---- 7 files changed, 54 insertions(+), 26 deletions(-) diff --git a/webapp/src/apiService/index.ts b/webapp/src/apiService/index.ts index 895b0cb..70a961c 100644 --- a/webapp/src/apiService/index.ts +++ b/webapp/src/apiService/index.ts @@ -11,7 +11,6 @@ const baseURL = new URL( window.location.origin + (!locationPrefixWeb ? '' : locationPrefixWeb[1]) ); export const wsURL = baseURL + "socket" -console.log({ baseURL, wsURL }) export const remoteAutoAPI = makeRemoteAPI( baseURL + "automations" ); diff --git a/webapp/src/components/DAGFlow/index.tsx b/webapp/src/components/DAGFlow/index.tsx index 8bc551a..fd6891c 100644 --- a/webapp/src/components/DAGFlow/index.tsx +++ b/webapp/src/components/DAGFlow/index.tsx @@ -60,13 +60,17 @@ export const DAGAutomationFlow: FC = ({ // modal let modalBody = <> + console.log(modalState) if (modalState) { if (modalState.single) { modalBody = setModalState(null)} - onSave={n => { modalState.update(n as any); setModalState(null); }} + onSave={n => { + modalState.update(n as any); + setModalState(null); + }} allowedTypes={modalState.allowedTypes} saveBtnCreateText={modalState.saveBtnCreateText} /> diff --git a/webapp/src/components/DAGFlow/updater.ts b/webapp/src/components/DAGFlow/updater.ts index ad277c9..522ecad 100644 --- a/webapp/src/components/DAGFlow/updater.ts +++ b/webapp/src/components/DAGFlow/updater.ts @@ -27,19 +27,23 @@ export const makeSequenceUpdater = ( choose: [], default: [], }, - update: n => onChange([ - ...sequence, - n, - ]), + update: n => { + onChange([ + ...sequence, + n, + ]) + }, allowedTypes: ['action', 'condition'] }) }, updateNode(i: number, node: AutomationSequenceNode) { - return onChange([ - ...sequence.slice(0, i), - node, - ...sequence.slice(i + 1), - ]) + if (JSON.stringify(node) !== JSON.stringify(sequence[i])) { + return onChange([ + ...sequence.slice(0, i), + node, + ...sequence.slice(i + 1), + ]) + } }, updateChooseActionData(i: number, data: ChooseAction) { const node = sequence[i] as ChooseAction; diff --git a/webapp/src/components/MultiNodeEditors/index.css b/webapp/src/components/MultiNodeEditors/index.css index ea10c7d..3999992 100644 --- a/webapp/src/components/MultiNodeEditors/index.css +++ b/webapp/src/components/MultiNodeEditors/index.css @@ -33,4 +33,16 @@ .multinode-editor.modded .multinode-editor--total { color: var(--green-light) +} + +.multinode-editor.modded .node-editor--footer--save { + border-color: var(--green-opaque); + background-color: var(--green-light); + color: var(--primary); +} + +.multinode-editor.modded .node-editor--footer--save:hover { + border-color: var(--green-light); + background-color: var(--green-opaque); + color: var(--green-light); } \ No newline at end of file diff --git a/webapp/src/components/MultiNodeEditors/index.tsx b/webapp/src/components/MultiNodeEditors/index.tsx index 5d5ec85..11ab693 100644 --- a/webapp/src/components/MultiNodeEditors/index.tsx +++ b/webapp/src/components/MultiNodeEditors/index.tsx @@ -19,19 +19,18 @@ export const MultiNodeEditor: FC = props => { ; // branch if (state.isEmpty) { - return
-
+
{nextOrAddBtn}
-
+
+ +
+
+ {state.currentSlideNumber}/{state.totalSlides}
} diff --git a/webapp/src/components/MultiNodeEditors/state.ts b/webapp/src/components/MultiNodeEditors/state.ts index 0c317c5..972f4ba 100644 --- a/webapp/src/components/MultiNodeEditors/state.ts +++ b/webapp/src/components/MultiNodeEditors/state.ts @@ -107,9 +107,9 @@ export const useMultiNodeEditorState = (props: MultiNodeEditorProps) => { slides.slice(slide + 1) ), multiNode: { - isModified: multiNode.isModified, + isModified: true, isSaved: false, - } + }, }) }, onSave(node: AutomationNode) { @@ -129,6 +129,17 @@ export const useMultiNodeEditorState = (props: MultiNodeEditorProps) => { internalNodeModified: false, }) }, + onSaveEmpty() { + justSaved.current = true + setState({ + ...state, + multiNode: { + isModified: multiNode.isModified, + isSaved: true, + }, + internalNodeModified: false, + }) + }, onClose() { if (!multiNode.isSaved && multiNode.isModified) { if (!window.confirm("You haven't saved your work, are you ok with losing it?")) { @@ -136,6 +147,9 @@ export const useMultiNodeEditorState = (props: MultiNodeEditorProps) => { } props.onSave && props.onSave(slides) } + if (justSaved.current) { + props.onSave && props.onSave(slides) + } props.onClose && props.onClose() } } diff --git a/webapp/src/components/NodeEditor/index.tsx b/webapp/src/components/NodeEditor/index.tsx index 27b8347..dc72ffb 100644 --- a/webapp/src/components/NodeEditor/index.tsx +++ b/webapp/src/components/NodeEditor/index.tsx @@ -68,11 +68,7 @@ export const NodeEditor: FC = ({ className="node-editor--footer--save" onClick={() => { if (areYouSureNotReady('save')) { - if (JSON.stringify(state.data) !== JSON.stringify(node)) { - onSave(state.data) - } else { - onClose() - } + onSave(state.data) } }} title={