mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Added report context. Removed report store.
This commit is contained in:
parent
bc37f5124e
commit
bfb52eb678
31 changed files with 372 additions and 273 deletions
|
|
@ -1,57 +0,0 @@
|
|||
import { create } from 'zustand';
|
||||
import produce from 'immer';
|
||||
import { getRandomChars } from 'next-basics';
|
||||
|
||||
const emptyReport = {
|
||||
name: 'Untitled',
|
||||
description: '',
|
||||
parameters: {},
|
||||
};
|
||||
|
||||
const initialState = {};
|
||||
|
||||
const store = create(() => ({ ...initialState }));
|
||||
|
||||
export function updateReport(id, data) {
|
||||
const report = store.getState()[id];
|
||||
|
||||
if (report) {
|
||||
store.setState(
|
||||
produce(state => {
|
||||
const item = state[id];
|
||||
const { parameters, ...rest } = data;
|
||||
|
||||
if (parameters) {
|
||||
item.parameters = { ...item.parameters, ...parameters };
|
||||
}
|
||||
|
||||
for (const key in rest) {
|
||||
item[key] = rest[key];
|
||||
}
|
||||
|
||||
return state;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function createReport(parameters) {
|
||||
const id = `new_${getRandomChars(16)}`;
|
||||
const report = { ...emptyReport, id, parameters };
|
||||
|
||||
store.setState(
|
||||
produce(state => {
|
||||
state[id] = report;
|
||||
|
||||
return state;
|
||||
}),
|
||||
);
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
export default store;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.__STORE__ = store;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue