Convert flows store to setup function (#18504)

This commit is contained in:
Nicola Krumschmidt
2023-05-05 15:13:09 +02:00
committed by GitHub
parent f08a54c32f
commit 608255d151

View File

@@ -1,41 +1,46 @@
import { FlowRaw } from '@directus/types';
import api from '@/api';
import { defineStore } from 'pinia';
import { useUserStore } from '@/stores/user';
import { usePermissionsStore } from '@/stores/permissions';
import { useUserStore } from '@/stores/user';
import { FlowRaw } from '@directus/types';
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useFlowsStore = defineStore({
id: 'flowsStore',
state: () => ({
flows: [] as FlowRaw[],
}),
actions: {
async hydrate() {
const { isAdmin } = useUserStore();
const { hasPermission } = usePermissionsStore();
export const useFlowsStore = defineStore('flowsStore', () => {
const flows = ref<FlowRaw[]>([]);
if (isAdmin !== true && !hasPermission('directus_flows', 'read')) {
this.flows = [];
} else {
try {
const response = await api.get<any>('/flows', {
params: { limit: -1, fields: ['*', 'operations.*'] },
});
return {
flows,
hydrate,
dehydrate,
getManualFlowsForCollection,
};
this.flows = response.data.data;
} catch {
this.flows = [];
}
async function hydrate() {
const { isAdmin } = useUserStore();
const { hasPermission } = usePermissionsStore();
if (isAdmin !== true && !hasPermission('directus_flows', 'read')) {
flows.value = [];
} else {
try {
const response = await api.get<any>('/flows', {
params: { limit: -1, fields: ['*', 'operations.*'] },
});
flows.value = response.data.data;
} catch {
flows.value = [];
}
},
async dehydrate() {
this.$reset();
},
getManualFlowsForCollection(collection: string): FlowRaw[] {
return this.flows.filter(
(flow) =>
flow.trigger === 'manual' && flow.status === 'active' && flow.options?.collections?.includes(collection)
);
},
},
}
}
async function dehydrate() {
flows.value = [];
}
function getManualFlowsForCollection(collection: string): FlowRaw[] {
return flows.value.filter(
(flow) => flow.trigger === 'manual' && flow.status === 'active' && flow.options?.collections?.includes(collection)
);
}
});