Report updates.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import create from 'zustand';
|
||||
import { create } from 'zustand';
|
||||
import {
|
||||
DATE_RANGE_CONFIG,
|
||||
DEFAULT_DATE_RANGE,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import create from 'zustand';
|
||||
import { create } from 'zustand';
|
||||
import { DASHBOARD_CONFIG, DEFAULT_WEBSITE_LIMIT } from 'lib/constants';
|
||||
import { getItem, setItem } from 'next-basics';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import create from 'zustand';
|
||||
import { create } from 'zustand';
|
||||
|
||||
const store = create(() => ({}));
|
||||
|
||||
|
||||
61
store/reports.js
Normal file
61
store/reports.js
Normal file
@@ -0,0 +1,61 @@
|
||||
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];
|
||||
|
||||
console.log('UPDATE STORE START', id, report);
|
||||
|
||||
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() {
|
||||
const id = `new_${getRandomChars(16)}`;
|
||||
const report = { ...emptyReport, id };
|
||||
|
||||
store.setState(
|
||||
produce(state => {
|
||||
state[id] = report;
|
||||
|
||||
return state;
|
||||
}),
|
||||
);
|
||||
|
||||
console.log('CREATE STORE', report);
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
export default store;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.__STORE__ = store;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import create from 'zustand';
|
||||
import { create } from 'zustand';
|
||||
import produce from 'immer';
|
||||
import semver from 'semver';
|
||||
import { CURRENT_VERSION, VERSION_CHECK, UPDATES_URL } from 'lib/constants';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import create from 'zustand';
|
||||
import { create } from 'zustand';
|
||||
import produce from 'immer';
|
||||
import app from './app';
|
||||
import { parseDateRange } from 'lib/date';
|
||||
|
||||
Reference in New Issue
Block a user