From 151e60f829663e79982aae6ac1cd8489f3083224 Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:06:08 +0100 Subject: [PATCH] fix(editor): Fix local storage flags defaulting to undefined string (#7603) useStorage takes the default value `undefined` and sets it in local storage.. also returns "undefined" as string which breaks onboarding flows Github issue / Community forum post (link here to close automatically): --- .../src/components/ActivationModal.vue | 3 +- .../src/components/NDVDraggablePanels.vue | 9 ++-- packages/editor-ui/src/components/Node.vue | 9 ++-- packages/editor-ui/src/components/RunData.vue | 11 ++--- .../src/composables/useStorage.test.ts | 48 +++++++++++++++++++ .../editor-ui/src/composables/useStorage.ts | 13 +++++ .../editor-ui/src/mixins/workflowActivate.ts | 7 +-- packages/editor-ui/src/router.ts | 5 +- .../src/stores/__tests__/posthog.test.ts | 13 ++--- packages/editor-ui/src/stores/ndv.store.ts | 6 +-- .../editor-ui/src/stores/posthog.store.ts | 6 +-- packages/editor-ui/src/stores/ui.utils.ts | 9 ++-- 12 files changed, 97 insertions(+), 42 deletions(-) create mode 100644 packages/editor-ui/src/composables/useStorage.test.ts create mode 100644 packages/editor-ui/src/composables/useStorage.ts diff --git a/packages/editor-ui/src/components/ActivationModal.vue b/packages/editor-ui/src/components/ActivationModal.vue index 6b2e7274bc..a8c119c2e2 100644 --- a/packages/editor-ui/src/components/ActivationModal.vue +++ b/packages/editor-ui/src/components/ActivationModal.vue @@ -50,6 +50,7 @@ import { getActivatableTriggerNodes, getTriggerNodeServiceName } from '@/utils'; import { useUIStore } from '@/stores/ui.store'; import { useWorkflowsStore } from '@/stores/workflows.store'; import { useNodeTypesStore } from '@/stores/nodeTypes.store'; +import { useStorage } from '@/composables/useStorage'; export default defineComponent({ name: 'ActivationModal', @@ -88,7 +89,7 @@ export default defineComponent({ }, handleCheckboxChange(checkboxValue: boolean) { this.checked = checkboxValue; - window.localStorage.setItem(LOCAL_STORAGE_ACTIVATION_FLAG, checkboxValue.toString()); + useStorage(LOCAL_STORAGE_ACTIVATION_FLAG).value = checkboxValue.toString(); }, }, computed: { diff --git a/packages/editor-ui/src/components/NDVDraggablePanels.vue b/packages/editor-ui/src/components/NDVDraggablePanels.vue index 8c96ebf154..5851aa85b1 100644 --- a/packages/editor-ui/src/components/NDVDraggablePanels.vue +++ b/packages/editor-ui/src/components/NDVDraggablePanels.vue @@ -41,7 +41,7 @@ import { defineComponent } from 'vue'; import type { PropType } from 'vue'; import { mapStores } from 'pinia'; import { get } from 'lodash-es'; -import { useStorage } from '@vueuse/core'; +import { useStorage } from '@/composables/useStorage'; import type { INodeTypeDescription } from 'n8n-workflow'; import PanelDragButton from './PanelDragButton.vue'; @@ -348,7 +348,6 @@ export default defineComponent({ restorePositionData() { const storedPanelWidthData = useStorage( `${LOCAL_STORAGE_MAIN_PANEL_RELATIVE_WIDTH}_${this.currentNodePaneType}`, - undefined, ).value; if (storedPanelWidthData) { @@ -362,10 +361,8 @@ export default defineComponent({ return false; }, storePositionData() { - window.localStorage.setItem( - `${LOCAL_STORAGE_MAIN_PANEL_RELATIVE_WIDTH}_${this.currentNodePaneType}`, - this.mainPanelDimensions.relativeWidth.toString(), - ); + useStorage(`${LOCAL_STORAGE_MAIN_PANEL_RELATIVE_WIDTH}_${this.currentNodePaneType}`).value = + this.mainPanelDimensions.relativeWidth.toString(); }, onDragStart() { this.isDragging = true; diff --git a/packages/editor-ui/src/components/Node.vue b/packages/editor-ui/src/components/Node.vue index da67476079..615aab0c5f 100644 --- a/packages/editor-ui/src/components/Node.vue +++ b/packages/editor-ui/src/components/Node.vue @@ -170,7 +170,7 @@