From 35c76f3e3c09b21bac5fa40c94eb34e332fd5f16 Mon Sep 17 00:00:00 2001 From: Sanjeev Lakhwani Date: Mon, 4 Mar 2024 13:23:08 -0500 Subject: [PATCH 1/3] added the option to reset layout in store --- src/js/features/data/data.store.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/js/features/data/data.store.ts b/src/js/features/data/data.store.ts index 45d3f966..d7e382d9 100644 --- a/src/js/features/data/data.store.ts +++ b/src/js/features/data/data.store.ts @@ -6,12 +6,14 @@ import { Counts } from '@/types/overviewResponse'; interface DataState { isFetchingData: boolean; + defaultLayout: Sections; sections: Sections; counts: Counts; } const initialState: DataState = { isFetchingData: true, + defaultLayout: [], sections: [], counts: { individuals: 0, @@ -69,6 +71,9 @@ const data = createSlice({ arr[ind].isDisplayed = false; }); }, + resetLayout: (state) => { + state.sections = state.defaultLayout; + }, }, extraReducers: (builder) => { builder @@ -77,6 +82,7 @@ const data = createSlice({ }) .addCase(makeGetDataRequestThunk.fulfilled, (state, { payload }) => { state.sections = payload.sectionData; + state.defaultLayout = payload.sectionData; state.counts = payload.counts; state.isFetchingData = false; }) @@ -93,6 +99,7 @@ export const { setChartWidth, setAllDisplayedCharts, hideAllSectionCharts, + resetLayout, } = data.actions; export { makeGetDataRequestThunk }; export default data.reducer; From 9c3bc75b0b62592a70b8772a6fd8e1febaed4be2 Mon Sep 17 00:00:00 2001 From: Sanjeev Lakhwani Date: Mon, 4 Mar 2024 14:07:04 -0500 Subject: [PATCH 2/3] Added the reset button --- .../Overview/Drawer/ManageChartsDrawer.tsx | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/js/components/Overview/Drawer/ManageChartsDrawer.tsx b/src/js/components/Overview/Drawer/ManageChartsDrawer.tsx index 0d7203f4..e83dd111 100644 --- a/src/js/components/Overview/Drawer/ManageChartsDrawer.tsx +++ b/src/js/components/Overview/Drawer/ManageChartsDrawer.tsx @@ -7,7 +7,7 @@ import ChartTree from './ChartTree'; import { ChartDataField } from '@/types/data'; import { useAppSelector, useAppDispatch, useTranslationCustom, useTranslationDefault } from '@/hooks'; -import { hideAllSectionCharts, setAllDisplayedCharts } from '@/features/data/data.store'; +import { hideAllSectionCharts, setAllDisplayedCharts, resetLayout } from '@/features/data/data.store'; const ManageChartsDrawer = ({ onManageDrawerClose, manageDrawerVisible }: ManageChartsDrawerProps) => { const t = useTranslationCustom(); @@ -24,14 +24,24 @@ const ManageChartsDrawer = ({ onManageDrawerClose, manageDrawerVisible }: Manage onClose={onManageDrawerClose} open={manageDrawerVisible} extra={ - + + + + } > {sections.map(({ sectionTitle, charts }: { sectionTitle: string; charts: ChartDataField[] }, i: number) => ( From b26b08174aee54730ebc8055838a010cc4a4464c Mon Sep 17 00:00:00 2001 From: Sanjeev Lakhwani Date: Mon, 4 Mar 2024 14:07:32 -0500 Subject: [PATCH 3/3] resolved bug with reset & LS --- src/js/features/data/data.store.ts | 2 +- src/js/features/data/makeGetDataRequest.thunk.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/features/data/data.store.ts b/src/js/features/data/data.store.ts index d7e382d9..07793a26 100644 --- a/src/js/features/data/data.store.ts +++ b/src/js/features/data/data.store.ts @@ -82,7 +82,7 @@ const data = createSlice({ }) .addCase(makeGetDataRequestThunk.fulfilled, (state, { payload }) => { state.sections = payload.sectionData; - state.defaultLayout = payload.sectionData; + state.defaultLayout = payload.defaultData; state.counts = payload.counts; state.isFetchingData = false; }) diff --git a/src/js/features/data/makeGetDataRequest.thunk.ts b/src/js/features/data/makeGetDataRequest.thunk.ts index b72d9b0c..0584fcd1 100644 --- a/src/js/features/data/makeGetDataRequest.thunk.ts +++ b/src/js/features/data/makeGetDataRequest.thunk.ts @@ -12,7 +12,7 @@ import { Counts, OverviewResponse } from '@/types/overviewResponse'; import { printAPIError } from '@/utils/error.util'; export const makeGetDataRequestThunk = createAsyncThunk< - { sectionData: Sections; counts: Counts }, + { sectionData: Sections; counts: Counts; defaultData: Sections }, void, { rejectValue: string } >('data/makeGetDataRequest', async (_, { rejectWithValue }) => { @@ -46,6 +46,8 @@ export const makeGetDataRequestThunk = createAsyncThunk< charts: charts.map(normalizeChart), })); + const defaultSectionData = JSON.parse(JSON.stringify(sectionData)); + // comparing to the local store and updating itself let convertedData = convertSequenceAndDisplayData(sectionData); const localValue = getValue(LOCALSTORAGE_CHARTS_KEY, convertedData, (val: LocalStorageData) => @@ -63,5 +65,5 @@ export const makeGetDataRequestThunk = createAsyncThunk< convertedData = convertSequenceAndDisplayData(sectionData); saveValue(LOCALSTORAGE_CHARTS_KEY, convertedData); - return { sectionData, counts: overviewResponse.counts }; + return { sectionData, counts: overviewResponse.counts, defaultData: defaultSectionData }; });