feat(editor): Workflow history [WIP]- create workflow history list component (no-changelog) (#7186)

Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
Csaba Tuncsik
2023-09-29 17:48:36 +02:00
committed by GitHub
parent ec0379378e
commit d1b6c7fd79
14 changed files with 1019 additions and 12 deletions

View File

@@ -0,0 +1,56 @@
import { ref, computed } from 'vue';
import { defineStore } from 'pinia';
import * as whApi from '@/api/workflowHistory';
import { useRootStore } from '@/stores/n8nRoot.store';
import type {
WorkflowHistory,
WorkflowVersion,
WorkflowHistoryRequestParams,
} from '@/types/workflowHistory';
export const useWorkflowHistoryStore = defineStore('workflowHistory', () => {
const rootStore = useRootStore();
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 getWorkflowHistory = async (
workflowId: string,
queryParams: WorkflowHistoryRequestParams,
): Promise<WorkflowHistory[]> =>
whApi
.getWorkflowHistory(rootStore.getRestApiContext, workflowId, queryParams)
.catch((error) => {
console.error(error);
return [] as WorkflowHistory[];
});
const addWorkflowHistory = (history: WorkflowHistory[]) => {
workflowHistory.value = workflowHistory.value.concat(history);
};
const getWorkflowVersion = async (
workflowId: string,
versionId: string,
): Promise<WorkflowVersion | null> =>
whApi.getWorkflowVersion(rootStore.getRestApiContext, workflowId, versionId).catch((error) => {
console.error(error);
return null;
});
const setActiveWorkflowVersion = (version: WorkflowVersion | null) => {
activeWorkflowVersion.value = version;
};
return {
getWorkflowHistory,
addWorkflowHistory,
getWorkflowVersion,
setActiveWorkflowVersion,
workflowHistory,
activeWorkflowVersion,
shouldUpgrade,
maxRetentionPeriod,
};
});