Report updates.

This commit is contained in:
Mike Cao 2023-05-20 09:02:08 -07:00
parent 40f53e8856
commit 0fb93ff00b
147 changed files with 1095 additions and 628 deletions

View file

@ -1,4 +1,4 @@
import create from 'zustand';
import { create } from 'zustand';
import {
DATE_RANGE_CONFIG,
DEFAULT_DATE_RANGE,

View file

@ -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';

View file

@ -1,4 +1,4 @@
import create from 'zustand';
import { create } from 'zustand';
const store = create(() => ({}));

61
store/reports.js Normal file
View 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;
}

View file

@ -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';

View file

@ -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';