feat(editor): Workflow history [WIP]- Improve switching between workflow history and editor (no-changelog) (#7353)
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { faker } from '@faker-js/faker';
|
||||
import type { WorkflowHistory } from '@/types/workflowHistory';
|
||||
import type { WorkflowHistory, WorkflowVersion } from '@/types/workflowHistory';
|
||||
|
||||
export const workflowHistoryDataFactory: () => WorkflowHistory = () => ({
|
||||
versionId: faker.string.nanoid(),
|
||||
createdAt: faker.date.past().toDateString(),
|
||||
updatedAt: faker.date.past().toDateString(),
|
||||
authors: Array.from({ length: faker.number.int({ min: 2, max: 5 }) }, faker.person.fullName).join(
|
||||
', ',
|
||||
),
|
||||
});
|
||||
|
||||
export const workflowVersionDataFactory: () => WorkflowHistory = () => ({
|
||||
export const workflowVersionDataFactory: () => WorkflowVersion = () => ({
|
||||
...workflowHistoryDataFactory(),
|
||||
workflow: {
|
||||
name: faker.lorem.words(3),
|
||||
},
|
||||
workflowId: faker.string.nanoid(),
|
||||
connections: {},
|
||||
nodes: [],
|
||||
});
|
||||
|
||||
@@ -1,36 +1,13 @@
|
||||
import { createPinia, setActivePinia } from 'pinia';
|
||||
import type { IN8nUISettings } from 'n8n-workflow';
|
||||
import { useWorkflowHistoryStore } from '@/stores/workflowHistory.store';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import {
|
||||
workflowHistoryDataFactory,
|
||||
workflowVersionDataFactory,
|
||||
} from '@/stores/__tests__/utils/workflowHistoryTestUtils';
|
||||
|
||||
const historyData = Array.from({ length: 5 }, workflowHistoryDataFactory);
|
||||
const versionData = {
|
||||
...workflowVersionDataFactory(),
|
||||
...historyData[0],
|
||||
};
|
||||
|
||||
describe('Workflow history store', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
it('should reset data', () => {
|
||||
const workflowHistoryStore = useWorkflowHistoryStore();
|
||||
|
||||
workflowHistoryStore.addWorkflowHistory(historyData);
|
||||
workflowHistoryStore.setActiveWorkflowVersion(versionData);
|
||||
|
||||
expect(workflowHistoryStore.workflowHistory).toEqual(historyData);
|
||||
expect(workflowHistoryStore.activeWorkflowVersion).toEqual(versionData);
|
||||
|
||||
workflowHistoryStore.reset();
|
||||
expect(workflowHistoryStore.workflowHistory).toEqual([]);
|
||||
expect(workflowHistoryStore.activeWorkflowVersion).toEqual(null);
|
||||
});
|
||||
|
||||
test.each([
|
||||
[true, 1, 1],
|
||||
[true, 2, 2],
|
||||
@@ -49,7 +26,7 @@ describe('Workflow history store', () => {
|
||||
pruneTime,
|
||||
licensePruneTime,
|
||||
},
|
||||
};
|
||||
} as IN8nUISettings;
|
||||
|
||||
expect(workflowHistoryStore.shouldUpgrade).toBe(shouldUpgrade);
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ref, computed } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import * as whApi from '@/api/workflowHistory';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
@@ -13,8 +13,6 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
const rootStore = useRootStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
|
||||
const workflowHistory = ref<WorkflowHistory[]>([]);
|
||||
const activeWorkflowVersion = ref<WorkflowVersion | null>(null);
|
||||
const licensePruneTime = computed(() => settingsStore.settings.workflowHistory.licensePruneTime);
|
||||
const pruneTime = computed(() => settingsStore.settings.workflowHistory.pruneTime);
|
||||
const evaluatedPruneTime = computed(() => Math.min(pruneTime.value, licensePruneTime.value));
|
||||
@@ -22,11 +20,6 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
() => licensePruneTime.value !== -1 && licensePruneTime.value === pruneTime.value,
|
||||
);
|
||||
|
||||
const reset = () => {
|
||||
workflowHistory.value = [];
|
||||
activeWorkflowVersion.value = null;
|
||||
};
|
||||
|
||||
const getWorkflowHistory = async (
|
||||
workflowId: string,
|
||||
queryParams: WorkflowHistoryRequestParams,
|
||||
@@ -37,9 +30,6 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
console.error(error);
|
||||
return [] as WorkflowHistory[];
|
||||
});
|
||||
const addWorkflowHistory = (history: WorkflowHistory[]) => {
|
||||
workflowHistory.value = workflowHistory.value.concat(history);
|
||||
};
|
||||
|
||||
const getWorkflowVersion = async (
|
||||
workflowId: string,
|
||||
@@ -49,18 +39,10 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
console.error(error);
|
||||
return null;
|
||||
});
|
||||
const setActiveWorkflowVersion = (version: WorkflowVersion | null) => {
|
||||
activeWorkflowVersion.value = version;
|
||||
};
|
||||
|
||||
return {
|
||||
reset,
|
||||
getWorkflowHistory,
|
||||
addWorkflowHistory,
|
||||
getWorkflowVersion,
|
||||
setActiveWorkflowVersion,
|
||||
workflowHistory,
|
||||
activeWorkflowVersion,
|
||||
evaluatedPruneTime,
|
||||
shouldUpgrade,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user