feat(editor): Workflow history [WIP]- Add workflow history opening button to main header component (no-changelog) (#7310)
Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { faker } from '@faker-js/faker';
|
||||
import type { WorkflowHistory } from '@/types/workflowHistory';
|
||||
|
||||
export const workflowHistoryDataFactory: () => WorkflowHistory = () => ({
|
||||
versionId: faker.string.nanoid(),
|
||||
createdAt: faker.date.past().toDateString(),
|
||||
authors: Array.from({ length: faker.number.int({ min: 2, max: 5 }) }, faker.person.fullName).join(
|
||||
', ',
|
||||
),
|
||||
});
|
||||
|
||||
export const workflowVersionDataFactory: () => WorkflowHistory = () => ({
|
||||
...workflowHistoryDataFactory(),
|
||||
workflow: {
|
||||
name: faker.lorem.words(3),
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import { createPinia, setActivePinia } from 'pinia';
|
||||
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],
|
||||
[false, 1, 2],
|
||||
[false, 2, 1],
|
||||
[false, -1, 2],
|
||||
[false, 2, -1],
|
||||
])(
|
||||
'should set `shouldUpgrade` to %s when pruneTime is %s and licensePruneTime is %s',
|
||||
(shouldUpgrade, pruneTime, licensePruneTime) => {
|
||||
const workflowHistoryStore = useWorkflowHistoryStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
|
||||
settingsStore.settings = {
|
||||
workflowHistory: {
|
||||
pruneTime,
|
||||
licensePruneTime,
|
||||
},
|
||||
};
|
||||
|
||||
expect(workflowHistoryStore.shouldUpgrade).toBe(shouldUpgrade);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { ref, computed } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import * as whApi from '@/api/workflowHistory';
|
||||
import { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import type {
|
||||
WorkflowHistory,
|
||||
WorkflowVersion,
|
||||
@@ -10,12 +11,21 @@ import type {
|
||||
|
||||
export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
const rootStore = useRootStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
|
||||
const workflowHistory = ref<WorkflowHistory[]>([]);
|
||||
const activeWorkflowVersion = ref<WorkflowVersion | null>(null);
|
||||
const maxRetentionPeriod = ref(0);
|
||||
const retentionPeriod = ref(0);
|
||||
const shouldUpgrade = computed(() => maxRetentionPeriod.value === retentionPeriod.value);
|
||||
const licensePruneTime = computed(() => settingsStore.settings.workflowHistory.licensePruneTime);
|
||||
const pruneTime = computed(() => settingsStore.settings.workflowHistory.pruneTime);
|
||||
const evaluatedPruneTime = computed(() => Math.min(pruneTime.value, licensePruneTime.value));
|
||||
const shouldUpgrade = computed(
|
||||
() => licensePruneTime.value !== -1 && licensePruneTime.value === pruneTime.value,
|
||||
);
|
||||
|
||||
const reset = () => {
|
||||
workflowHistory.value = [];
|
||||
activeWorkflowVersion.value = null;
|
||||
};
|
||||
|
||||
const getWorkflowHistory = async (
|
||||
workflowId: string,
|
||||
@@ -44,13 +54,14 @@ export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
|
||||
};
|
||||
|
||||
return {
|
||||
reset,
|
||||
getWorkflowHistory,
|
||||
addWorkflowHistory,
|
||||
getWorkflowVersion,
|
||||
setActiveWorkflowVersion,
|
||||
workflowHistory,
|
||||
activeWorkflowVersion,
|
||||
evaluatedPruneTime,
|
||||
shouldUpgrade,
|
||||
maxRetentionPeriod,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user