mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17: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 { 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';
|
||||||
|
|
||||||
|
|
|
@ -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,31 +7,29 @@ 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() {
|
const getWorkflowOwnerName = computed(() => {
|
||||||
return (
|
return (
|
||||||
workflowId: string,
|
workflowId: string,
|
||||||
fallback = i18n.baseText('workflows.shareModal.info.sharee.fallback'),
|
fallback = i18n.baseText('workflows.shareModal.info.sharee.fallback'),
|
||||||
): string => {
|
): string => {
|
||||||
const workflow = useWorkflowsStore().getWorkflowById(workflowId);
|
const workflow = workflowStore.getWorkflowById(workflowId);
|
||||||
const { name, email } = splitName(workflow?.homeProject?.name ?? '');
|
const { name, email } = splitName(workflow?.homeProject?.name ?? '');
|
||||||
|
|
||||||
return name ? (email ? `${name} (${email})` : name) : (email ?? fallback);
|
return name ? (email ? `${name} (${email})` : name) : (email ?? fallback);
|
||||||
};
|
};
|
||||||
},
|
});
|
||||||
},
|
|
||||||
actions: {
|
const setWorkflowSharedWith = (payload: {
|
||||||
setWorkflowSharedWith(payload: {
|
|
||||||
workflowId: string;
|
workflowId: string;
|
||||||
sharedWithProjects: ProjectSharingData[];
|
sharedWithProjects: ProjectSharingData[];
|
||||||
}): void {
|
}) => {
|
||||||
const workflowsStore = useWorkflowsStore();
|
const workflowsStore = useWorkflowsStore();
|
||||||
|
|
||||||
workflowsStore.workflowsById[payload.workflowId] = {
|
workflowsStore.workflowsById[payload.workflowId] = {
|
||||||
...workflowsStore.workflowsById[payload.workflowId],
|
...workflowsStore.workflowsById[payload.workflowId],
|
||||||
sharedWithProjects: payload.sharedWithProjects,
|
sharedWithProjects: payload.sharedWithProjects,
|
||||||
|
@ -40,23 +38,23 @@ export const useWorkflowsEEStore = defineStore(STORES.WORKFLOWS_EE, {
|
||||||
...workflowsStore.workflow,
|
...workflowsStore.workflow,
|
||||||
sharedWithProjects: payload.sharedWithProjects,
|
sharedWithProjects: payload.sharedWithProjects,
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
async saveWorkflowSharedWith(payload: {
|
|
||||||
|
const saveWorkflowSharedWith = async (payload: {
|
||||||
sharedWithProjects: ProjectSharingData[];
|
sharedWithProjects: ProjectSharingData[];
|
||||||
workflowId: string;
|
workflowId: string;
|
||||||
}): Promise<void> {
|
}) => {
|
||||||
const rootStore = useRootStore();
|
|
||||||
const settingsStore = useSettingsStore();
|
|
||||||
|
|
||||||
if (settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing]) {
|
if (settingsStore.isEnterpriseFeatureEnabled[EnterpriseEditionFeature.Sharing]) {
|
||||||
await setWorkflowSharedWith(rootStore.restApiContext, payload.workflowId, {
|
await workflowsApi.setWorkflowSharedWith(rootStore.restApiContext, payload.workflowId, {
|
||||||
shareWithIds: payload.sharedWithProjects.map((p) => p.id),
|
shareWithIds: payload.sharedWithProjects.map((p) => p.id),
|
||||||
});
|
});
|
||||||
|
setWorkflowSharedWith(payload);
|
||||||
this.setWorkflowSharedWith(payload);
|
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default useWorkflowsEEStore;
|
return {
|
||||||
|
getWorkflowOwnerName,
|
||||||
|
setWorkflowSharedWith,
|
||||||
|
saveWorkflowSharedWith,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue