Add insights store

This commit is contained in:
rijkvanzanten
2021-05-25 16:30:39 -04:00
parent a7d8d0fafc
commit 8c8232ce25
5 changed files with 48 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import {
useCollectionsStore,
useFieldsStore,
useLatencyStore,
useInsightsStore,
usePermissionsStore,
usePresetsStore,
useRelationsStore,
@@ -35,6 +36,7 @@ export function useStores(
useLatencyStore,
useRelationsStore,
usePermissionsStore,
useInsightsStore,
]
): GenericStore[] {
return stores.map((useStore) => useStore()) as GenericStore[];

View File

@@ -1,6 +1,7 @@
export * from './app';
export * from './collections';
export * from './fields';
export * from './insights';
export * from './latency';
export * from './notifications';
export * from './permissions';

View File

@@ -0,0 +1,19 @@
import { Dashboard } from '../types';
import api from '@/api';
import { createStore } from 'pinia';
export const useInsightsStore = createStore({
id: 'insightsStore',
state: () => ({
dashboards: [] as Dashboard[],
}),
actions: {
async hydrate() {
const response = await api.get('/dashboards', { params: { limit: -1, fields: ['*', 'panels.*'] } });
this.state.dashboards = response.data.data;
},
dehydrate() {
this.reset();
},
},
});

View File

@@ -1,6 +1,7 @@
export * from './collections';
export * from './error';
export * from './fields';
export * from './insights';
export * from './items';
export * from './notifications';
export * from './permissions';

25
app/src/types/insights.ts Normal file
View File

@@ -0,0 +1,25 @@
export type Dashboard = {
id: string;
name: string;
icon: string;
panels: Panel[];
date_created: string;
user_created: string;
};
export type Panel = {
id: string;
dashboard: string;
name: string;
icon: string;
color: string;
note: string;
type: string;
position_x: number;
position_y: number;
width: number;
height: number;
options: Record<string, any>;
date_created: string;
user_created: string;
};