From 99d4058e9d94e4e83d37bf6c050eca1da1ecfe20 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Mon, 23 Sep 2024 07:51:41 -0400 Subject: [PATCH] refactor(editor): Migrate `workflow.ee.store` to composition API (#10912) --- .../src/composables/useWorkflowHelpers.ts | 2 +- .../src/stores/workflows.ee.store.ts | 94 +++++++++---------- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/packages/editor-ui/src/composables/useWorkflowHelpers.ts b/packages/editor-ui/src/composables/useWorkflowHelpers.ts index 2c79cb2639..77d8abeb14 100644 --- a/packages/editor-ui/src/composables/useWorkflowHelpers.ts +++ b/packages/editor-ui/src/composables/useWorkflowHelpers.ts @@ -66,7 +66,7 @@ import type { useRouter } from 'vue-router'; import { useTelemetry } from '@/composables/useTelemetry'; import { useProjectsStore } from '@/stores/projects.store'; import { useTagsStore } from '@/stores/tags.store'; -import useWorkflowsEEStore from '@/stores/workflows.ee.store'; +import { useWorkflowsEEStore } from '@/stores/workflows.ee.store'; import { useNpsSurveyStore } from '@/stores/npsSurvey.store'; import type { NavigationGuardNext } from 'vue-router'; diff --git a/packages/editor-ui/src/stores/workflows.ee.store.ts b/packages/editor-ui/src/stores/workflows.ee.store.ts index de3589f9fe..e861c87dff 100644 --- a/packages/editor-ui/src/stores/workflows.ee.store.ts +++ b/packages/editor-ui/src/stores/workflows.ee.store.ts @@ -1,4 +1,4 @@ -import { setWorkflowSharedWith } from '@/api/workflows.ee'; +import * as workflowsApi from '@/api/workflows.ee'; import { EnterpriseEditionFeature, STORES } from '@/constants'; import { useRootStore } from '@/stores/root.store'; import { useSettingsStore } from '@/stores/settings.store'; @@ -7,56 +7,54 @@ import { useWorkflowsStore } from '@/stores/workflows.store'; import { i18n } from '@/plugins/i18n'; import type { ProjectSharingData } from '@/types/projects.types'; import { splitName } from '@/utils/projects.utils'; +import { computed } from 'vue'; -export const useWorkflowsEEStore = defineStore(STORES.WORKFLOWS_EE, { - state() { - return {}; - }, - getters: { - getWorkflowOwnerName() { - return ( - workflowId: string, - fallback = i18n.baseText('workflows.shareModal.info.sharee.fallback'), - ): string => { - const workflow = useWorkflowsStore().getWorkflowById(workflowId); - const { name, email } = splitName(workflow?.homeProject?.name ?? ''); +export const useWorkflowsEEStore = defineStore(STORES.WORKFLOWS_EE, () => { + const rootStore = useRootStore(); + const settingsStore = useSettingsStore(); + const workflowStore = useWorkflowsStore(); - return name ? (email ? `${name} (${email})` : name) : (email ?? fallback); - }; - }, - }, - actions: { - setWorkflowSharedWith(payload: { - workflowId: string; - sharedWithProjects: ProjectSharingData[]; - }): void { - const workflowsStore = useWorkflowsStore(); + const getWorkflowOwnerName = computed(() => { + return ( + workflowId: string, + fallback = i18n.baseText('workflows.shareModal.info.sharee.fallback'), + ): string => { + const workflow = workflowStore.getWorkflowById(workflowId); + const { name, email } = splitName(workflow?.homeProject?.name ?? ''); + return name ? (email ? `${name} (${email})` : name) : (email ?? fallback); + }; + }); - workflowsStore.workflowsById[payload.workflowId] = { - ...workflowsStore.workflowsById[payload.workflowId], - sharedWithProjects: payload.sharedWithProjects, - }; - workflowsStore.workflow = { - ...workflowsStore.workflow, - sharedWithProjects: payload.sharedWithProjects, - }; - }, - async saveWorkflowSharedWith(payload: { - sharedWithProjects: ProjectSharingData[]; - workflowId: string; - }): Promise { - const rootStore = useRootStore(); - const settingsStore = useSettingsStore(); + const setWorkflowSharedWith = (payload: { + workflowId: string; + sharedWithProjects: ProjectSharingData[]; + }) => { + const workflowsStore = useWorkflowsStore(); + workflowsStore.workflowsById[payload.workflowId] = { + ...workflowsStore.workflowsById[payload.workflowId], + sharedWithProjects: payload.sharedWithProjects, + }; + workflowsStore.workflow = { + ...workflowsStore.workflow, + sharedWithProjects: payload.sharedWithProjects, + }; + }; - if (settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing]) { - await setWorkflowSharedWith(rootStore.restApiContext, payload.workflowId, { - shareWithIds: payload.sharedWithProjects.map((p) => p.id), - }); + const saveWorkflowSharedWith = async (payload: { + sharedWithProjects: ProjectSharingData[]; + workflowId: string; + }) => { + if (settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing]) { + await workflowsApi.setWorkflowSharedWith(rootStore.restApiContext, payload.workflowId, { + shareWithIds: payload.sharedWithProjects.map((p) => p.id), + }); + setWorkflowSharedWith(payload); + } + }; - this.setWorkflowSharedWith(payload); - } - }, - }, + return { + getWorkflowOwnerName, + setWorkflowSharedWith, + saveWorkflowSharedWith, + }; }); - -export default useWorkflowsEEStore;