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:
56
packages/editor-ui/src/stores/workflowHistory.store.ts
Normal file
56
packages/editor-ui/src/stores/workflowHistory.store.ts
Normal 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,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user