add reset button for reset local storage and update state renamed
This commit is contained in:
@@ -21,6 +21,23 @@ export const TableSettingProvider = ({ children }) => {
|
||||
const filterAction = (user_id, page_name, table_name, settingValue, columns) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "filters", settingValue, columns);
|
||||
};
|
||||
const resetAction = (user_id, page_name, table_name) => {
|
||||
const prevLocalStorage = JSON.parse(localStorage.getItem("_setting-app")) || {};
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
const resetData = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
[table_name]: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
localStorage.setItem("_setting-app", JSON.stringify(resetData));
|
||||
setSettingStore(resetData);
|
||||
};
|
||||
const updateSettingStorage = (user_id, page_name, table_name, settingType, settingValue, columns) => {
|
||||
const prevLocalStorage = JSON.parse(localStorage.getItem("_setting-app")) || {};
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
@@ -46,7 +63,7 @@ export const TableSettingProvider = ({ children }) => {
|
||||
...tableSettings,
|
||||
[settingType]: Array.isArray(settingValue) ? [...newSettings] : { ...newSettings },
|
||||
},
|
||||
columns
|
||||
columns,
|
||||
),
|
||||
},
|
||||
},
|
||||
@@ -117,7 +134,7 @@ export const TableSettingProvider = ({ children }) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<TableSettingContext.Provider value={{ settingStore, hideAction, sortAction, filterAction }}>
|
||||
<TableSettingContext.Provider value={{ settingStore, hideAction, sortAction, filterAction, resetAction }}>
|
||||
{children}
|
||||
</TableSettingContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user