summary text
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
'use client'
|
||||
import {createContext, useCallback, useEffect, useState} from "react";
|
||||
|
||||
export const TableSettingContext = createContext();
|
||||
export const TableSettingProvider = ({children}) => {
|
||||
const [settingStore, setSettingStore] = useState({});
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const _localStorage = localStorage.getItem("_setting-app")
|
||||
if (_localStorage) {
|
||||
@@ -11,16 +13,16 @@ export const TableSettingProvider = ({children}) => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const hideAction = useCallback((user_id, page_name, table_name, settingValue) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "hides", settingValue);
|
||||
},[])
|
||||
const sortAction = useCallback((user_id, page_name, table_name, settingValue) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "sorts", settingValue);
|
||||
},[])
|
||||
const hideAction = useCallback((user_id, page_name, table_name, settingValue, columns) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "hides", settingValue, columns);
|
||||
}, [])
|
||||
const sortAction = useCallback((user_id, page_name, table_name, settingValue, columns) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "sorts", settingValue, columns);
|
||||
}, [])
|
||||
const filterAction = (user_id, page_name, table_name, settingValue) => {
|
||||
updateSettingStorage(user_id, page_name, table_name, "filters", settingValue);
|
||||
}
|
||||
const updateSettingStorage = (user_id, page_name, table_name, settingType, settingValue) => {
|
||||
const updateSettingStorage = (user_id, page_name, table_name, settingType, settingValue, columns) => {
|
||||
const prevLocalStorage = JSON.parse(localStorage.getItem("_setting-app")) || {};
|
||||
const userSettings = prevLocalStorage[user_id] || {};
|
||||
const pageSettings = userSettings[page_name] || {};
|
||||
@@ -40,6 +42,10 @@ export const TableSettingProvider = ({children}) => {
|
||||
[table_name]: {
|
||||
...tableSettings,
|
||||
[settingType]: Array.isArray(settingValue) ? [...newSettings] : {...newSettings},
|
||||
summary: SummaryTextMessage({
|
||||
...tableSettings,
|
||||
[settingType]: Array.isArray(settingValue) ? [...newSettings] : {...newSettings},
|
||||
}, columns)
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -48,6 +54,49 @@ export const TableSettingProvider = ({children}) => {
|
||||
setSettingStore(updatedLocalStorage);
|
||||
}
|
||||
|
||||
const SummaryTextMessage = (values, columns) => {
|
||||
let SummaryText = "";
|
||||
let HideText = "";
|
||||
let FilterText;
|
||||
let SortText = "";
|
||||
|
||||
if (values.sorts && values.sorts.length > 0) {
|
||||
const _list = []
|
||||
for (const sort of values.sorts) {
|
||||
const _column = columns.find(column => column.id == sort.id)
|
||||
_list.push(`${_column.header}` + `(${sort.desc ? "نزولی" : "صعودی"})`)
|
||||
}
|
||||
SortText = " مرتب شده بر اساس " + _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)
|
||||
_list.push(_column.header)
|
||||
}
|
||||
HideText = "ستون های مخفی شده : " + _list.join(", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (HideText || SortText) {
|
||||
if (SortText) {
|
||||
SummaryText += SortText;
|
||||
if (HideText) {
|
||||
SummaryText += " ; ";
|
||||
}
|
||||
}
|
||||
if (HideText) {
|
||||
SummaryText += HideText;
|
||||
}
|
||||
}
|
||||
|
||||
return SummaryText;
|
||||
};
|
||||
|
||||
return (
|
||||
<TableSettingContext.Provider
|
||||
value={{settingStore, hideAction, sortAction, filterAction}}>
|
||||
|
||||
Reference in New Issue
Block a user