mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
Co-authored-by: Guillaume Jacquart <jacquart.guillaume@gmail.com> Co-authored-by: Raúl Gómez Morales <raul00gm@gmail.com>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { computed } from 'vue';
|
|
import { defineStore } from 'pinia';
|
|
import { useAsyncState } from '@vueuse/core';
|
|
import type { ListInsightsWorkflowQueryDto } from '@n8n/api-types';
|
|
import * as insightsApi from '@/features/insights/insights.api';
|
|
import { useRootStore } from '@/stores/root.store';
|
|
import { useUsersStore } from '@/stores/users.store';
|
|
import { useSettingsStore } from '@/stores/settings.store';
|
|
import { transformInsightsSummary } from '@/features/insights/insights.utils';
|
|
import { getResourcePermissions } from '@/permissions';
|
|
|
|
export const useInsightsStore = defineStore('insights', () => {
|
|
const rootStore = useRootStore();
|
|
const usersStore = useUsersStore();
|
|
const settingsStore = useSettingsStore();
|
|
|
|
const globalInsightsPermissions = computed(
|
|
() => getResourcePermissions(usersStore.currentUser?.globalScopes).insights,
|
|
);
|
|
|
|
const isInsightsEnabled = computed(() => settingsStore.settings.insights.enabled);
|
|
|
|
const isSummaryEnabled = computed(
|
|
() => globalInsightsPermissions.value.list && isInsightsEnabled.value,
|
|
);
|
|
|
|
const summary = useAsyncState(
|
|
async () => {
|
|
const raw = await insightsApi.fetchInsightsSummary(rootStore.restApiContext);
|
|
return transformInsightsSummary(raw);
|
|
},
|
|
[],
|
|
{ immediate: false },
|
|
);
|
|
|
|
const charts = useAsyncState(
|
|
async () => {
|
|
return await insightsApi.fetchInsightsByTime(rootStore.restApiContext);
|
|
},
|
|
[],
|
|
{ immediate: false },
|
|
);
|
|
|
|
const table = useAsyncState(
|
|
async (filter?: ListInsightsWorkflowQueryDto) => {
|
|
return await insightsApi.fetchInsightsByWorkflow(rootStore.restApiContext, filter);
|
|
},
|
|
{
|
|
count: 0,
|
|
data: [],
|
|
},
|
|
{ immediate: false },
|
|
);
|
|
|
|
return {
|
|
globalInsightsPermissions,
|
|
isInsightsEnabled,
|
|
isSummaryEnabled,
|
|
summary,
|
|
charts,
|
|
table,
|
|
};
|
|
});
|