mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
refactor(editor): Migrate workflow.ee.store
to composition API (#10912)
This commit is contained in:
parent
57ff3cc27b
commit
99d4058e9d
|
@ -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';
|
||||
|
||||
|
|
|
@ -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<void> {
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue