feat(cms): improve catalog, editorial recovery and operations
This commit is contained in:
1 parent
2fead134e6
commit
c389c3893d
122 files changed
+8137
-703
No files matched your search
@@ -106,7 +106,42 @@ export function DataTable<T extends { id: number | string }>({
|
||||
const [bulkBusy, setBulkBusy] = useState(false);
|
||||
const bulkLock = useRef(false);
|
||||
|
||||
const [hiddenColumns, setHiddenColumns] = useState<Set<string>>(new Set());
|
||||
const [columnPreference, setColumnPreference] = useState<{
|
||||
path: string;
|
||||
hidden: Set<string>;
|
||||
}>(() => ({ path: pathname, hidden: new Set() }));
|
||||
const hiddenColumns =
|
||||
columnPreference.path === pathname &&
|
||||
!columns.every((column) => columnPreference.hidden.has(column.key))
|
||||
? columnPreference.hidden
|
||||
: new Set<string>();
|
||||
useEffect(() => {
|
||||
try {
|
||||
const raw: unknown = JSON.parse(
|
||||
sessionStorage.getItem(`cms-table-columns:${pathname}`) ?? "[]",
|
||||
);
|
||||
const hidden = Array.isArray(raw)
|
||||
? raw.filter((key): key is string => typeof key === "string")
|
||||
: [];
|
||||
setColumnPreference({ path: pathname, hidden: new Set(hidden) });
|
||||
} catch {
|
||||
setColumnPreference({ path: pathname, hidden: new Set() });
|
||||
}
|
||||
}, [pathname]);
|
||||
function setHiddenColumns(update: (previous: Set<string>) => Set<string>) {
|
||||
const next = update(hiddenColumns);
|
||||
// Leave at least one data column available, even after a stale saved preference.
|
||||
if (columns.every((column) => next.has(column.key))) return;
|
||||
setColumnPreference({ path: pathname, hidden: next });
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
`cms-table-columns:${pathname}`,
|
||||
JSON.stringify([...next]),
|
||||
);
|
||||
} catch {
|
||||
/* Storage can be disabled by the browser. */
|
||||
}
|
||||
}
|
||||
|
||||
const currentSort = searchParams.get("sort") || "";
|
||||
const currentOrder = searchParams.get("order") || "desc";
|
||||
|
||||
Reference in new issue
Block a user