refactor(editor): Migrate workflow.ee.store to composition API (#10912)

This commit is contained in:
Ricardo Espinoza 2024-09-23 07:51:41 -04:00 committed by GitHub
parent 57ff3cc27b
commit 99d4058e9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 49 deletions

View file

@ -66,7 +66,7 @@ import type { useRouter } from 'vue-router';
import { useTelemetry } from '@/composables/useTelemetry'; import { useTelemetry } from '@/composables/useTelemetry';
import { useProjectsStore } from '@/stores/projects.store'; import { useProjectsStore } from '@/stores/projects.store';
import { useTagsStore } from '@/stores/tags.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 { useNpsSurveyStore } from '@/stores/npsSurvey.store';
import type { NavigationGuardNext } from 'vue-router'; import type { NavigationGuardNext } from 'vue-router';

View file

@ -1,4 +1,4 @@
import { setWorkflowSharedWith } from '@/api/workflows.ee'; import * as workflowsApi from '@/api/workflows.ee';
import { EnterpriseEditionFeature, STORES } from '@/constants'; import { EnterpriseEditionFeature, STORES } from '@/constants';
import { useRootStore } from '@/stores/root.store'; import { useRootStore } from '@/stores/root.store';
import { useSettingsStore } from '@/stores/settings.store'; import { useSettingsStore } from '@/stores/settings.store';
@ -7,56 +7,54 @@ import { useWorkflowsStore } from '@/stores/workflows.store';
import { i18n } from '@/plugins/i18n'; import { i18n } from '@/plugins/i18n';
import type { ProjectSharingData } from '@/types/projects.types'; import type { ProjectSharingData } from '@/types/projects.types';
import { splitName } from '@/utils/projects.utils'; import { splitName } from '@/utils/projects.utils';
import { computed } from 'vue';
export const useWorkflowsEEStore = defineStore(STORES.WORKFLOWS_EE, { export const useWorkflowsEEStore = defineStore(STORES.WORKFLOWS_EE, () => {
state() { const rootStore = useRootStore();
return {}; const settingsStore = useSettingsStore();
}, const workflowStore = useWorkflowsStore();
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 ?? '');
return name ? (email ? `${name} (${email})` : name) : (email ?? fallback); const getWorkflowOwnerName = computed(() => {
}; return (
}, workflowId: string,
}, fallback = i18n.baseText('workflows.shareModal.info.sharee.fallback'),
actions: { ): string => {
setWorkflowSharedWith(payload: { const workflow = workflowStore.getWorkflowById(workflowId);
workflowId: string; const { name, email } = splitName(workflow?.homeProject?.name ?? '');
sharedWithProjects: ProjectSharingData[]; return name ? (email ? `${name} (${email})` : name) : (email ?? fallback);
}): void { };
const workflowsStore = useWorkflowsStore(); });
workflowsStore.workflowsById[payload.workflowId] = { const setWorkflowSharedWith = (payload: {
...workflowsStore.workflowsById[payload.workflowId], workflowId: string;
sharedWithProjects: payload.sharedWithProjects, sharedWithProjects: ProjectSharingData[];
}; }) => {
workflowsStore.workflow = { const workflowsStore = useWorkflowsStore();
...workflowsStore.workflow, workflowsStore.workflowsById[payload.workflowId] = {
sharedWithProjects: payload.sharedWithProjects, ...workflowsStore.workflowsById[payload.workflowId],
}; sharedWithProjects: payload.sharedWithProjects,
}, };
async saveWorkflowSharedWith(payload: { workflowsStore.workflow = {
sharedWithProjects: ProjectSharingData[]; ...workflowsStore.workflow,
workflowId: string; sharedWithProjects: payload.sharedWithProjects,
}): Promise<void> { };
const rootStore = useRootStore(); };
const settingsStore = useSettingsStore();
if (settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing]) { const saveWorkflowSharedWith = async (payload: {
await setWorkflowSharedWith(rootStore.restApiContext, payload.workflowId, { sharedWithProjects: ProjectSharingData[];
shareWithIds: payload.sharedWithProjects.map((p) => p.id), 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;