Files
directus/app/src/stores/flows.ts
Rijk van Zanten d6846d74eb Refactor unnecessary nested app folders (#14580)
* Remove unused nested folders from components

* Remove nested folders

* Standardize composables output

* Fix import inconsistencies

* Same trick for directives

* Same for routes

* Replace reliance root grouped export in favor of explicit imports

* Replace reliance on implicit imports

* Remove nested folder structure

* Consistent use of non-default exports in utils

* Remove nested folder structure from private components

* Fix test mock

* Remove extraneous component registration for valuenull

* Fix stores provider

* Fix logo sprite
2022-07-22 15:10:28 -04:00

39 lines
1018 B
TypeScript

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