debug and make better data structure for hiding items in material react table hide part
This commit is contained in:
@@ -13,6 +13,7 @@ export const TableSettingProvider = ({ children }) => {
|
||||
}, []);
|
||||
|
||||
const hideAction = useCallback((user_id, page_name, table_name, settingValue, columns) => {
|
||||
clearAction(user_id, page_name, table_name, "hides");
|
||||
updateSettingStorage(user_id, page_name, table_name, "hides", settingValue, columns);
|
||||
}, []);
|
||||
const sortAction = useCallback((user_id, page_name, table_name, settingValue, columns) => {
|
||||
@@ -58,13 +59,6 @@ export const TableSettingProvider = ({ children }) => {
|
||||
[table_name]: {
|
||||
...tableSettings,
|
||||
[settingType]: Array.isArray(settingValue) ? [...newSettings] : { ...newSettings },
|
||||
summary: SummaryTextMessage(
|
||||
{
|
||||
...tableSettings,
|
||||
[settingType]: Array.isArray(settingValue) ? [...newSettings] : { ...newSettings },
|
||||
},
|
||||
columns,
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -73,64 +67,27 @@ export const TableSettingProvider = ({ children }) => {
|
||||
setSettingStore(updatedLocalStorage);
|
||||
};
|
||||
|
||||
const SummaryTextMessage = (values, columns) => {
|
||||
let SummaryText = "";
|
||||
let HideText = "";
|
||||
let FilterText = "";
|
||||
let SortText = "";
|
||||
const clearAction = (user_id, page_name, table_name, key) => {
|
||||
const prevLocalStorage = JSON.parse(localStorage.getItem("_setting-app")) || {};
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
const tableSettings = pageSettings[table_name] || {};
|
||||
const updatedSettings = {
|
||||
...prevLocalStorage,
|
||||
[user_id]: {
|
||||
...userSettings,
|
||||
[page_name]: {
|
||||
...pageSettings,
|
||||
[table_name]: {
|
||||
...tableSettings,
|
||||
[key]: Array.isArray(tableSettings[key]) ? [] : {},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (values.sorts && values.sorts.length > 0) {
|
||||
const _list = [];
|
||||
for (const sort of values.sorts) {
|
||||
const _column = columns.find((column) => column.id == sort.id);
|
||||
if (_column) _list.push(`${_column.header}` + `(${sort.desc ? "نزولی" : "صعودی"})`);
|
||||
}
|
||||
if (_list.length > 0) SortText = " مرتب شده بر اساس : " + _list.join(", ");
|
||||
}
|
||||
if (values.filters && values.filters.length > 0) {
|
||||
const _list = [];
|
||||
for (const filter of values.filters) {
|
||||
const _column = columns.find((column) => column.id == filter.id);
|
||||
if (_column) _list.push(`${_column.header}`);
|
||||
}
|
||||
if (_list.length > 0) FilterText = " فیلتر شده بر اساس : " + _list.join(", ");
|
||||
}
|
||||
|
||||
if (values.hides) {
|
||||
const hidesArray = Object.entries(values.hides).map((e) => ({ id: e[0], value: e[1] }));
|
||||
if (hidesArray.length > 0) {
|
||||
const _list = [];
|
||||
for (const hide of hidesArray) {
|
||||
if (hide.value) continue;
|
||||
const _column = columns.find((c) => c.id == hide.id);
|
||||
if (_column) _list.push(_column.header);
|
||||
}
|
||||
if (_list.length > 0) HideText = "ستون های مخفی شده : " + _list.join(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (HideText || SortText || FilterText) {
|
||||
if (SortText) {
|
||||
SummaryText += SortText;
|
||||
if (HideText) {
|
||||
SummaryText += " ; ";
|
||||
}
|
||||
if (FilterText) {
|
||||
SummaryText += " ; ";
|
||||
}
|
||||
}
|
||||
if (HideText) {
|
||||
SummaryText += HideText;
|
||||
if (FilterText) {
|
||||
SummaryText += " ; ";
|
||||
}
|
||||
}
|
||||
if (FilterText) {
|
||||
SummaryText += FilterText;
|
||||
}
|
||||
}
|
||||
|
||||
return SummaryText;
|
||||
localStorage.setItem("_setting-app", JSON.stringify(updatedSettings));
|
||||
setSettingStore(updatedSettings);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user