Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanmathur91 committed May 8, 2024
2 parents 109c701 + 306d062 commit 7afc927
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface ContentListTableProps<DataType> extends TableProps<DataType> {
onRecordSelection?: (selectedRows: DataType[]) => void;
}

const EXPANDED_ROWS_LOCAL_STORAGE_KEY = "content-list-table-expanded-rows";

const ContentListTable = <DataType extends { [key: string]: any }>({
id,
columns,
Expand Down Expand Up @@ -47,9 +49,13 @@ const ContentListTable = <DataType extends { [key: string]: any }>({
updatedExpandedRowKeys.delete(record[rowKey]);
}
setExpandedRowsKeys(Array.from(updatedExpandedRowKeys));

const expandedRows = JSON.parse(localStorage.getItem(EXPANDED_ROWS_LOCAL_STORAGE_KEY) || null) ?? {};

localStorage.setItem(
"content-list-table-expanded-rows",
EXPANDED_ROWS_LOCAL_STORAGE_KEY,
JSON.stringify({
...expandedRows,
[id]: Array.from(updatedExpandedRowKeys),
})
);
Expand All @@ -58,7 +64,7 @@ const ContentListTable = <DataType extends { [key: string]: any }>({
);

useEffect(() => {
const expandedRowsData = localStorage.getItem("content-list-table-expanded-rows");
const expandedRowsData = localStorage.getItem(EXPANDED_ROWS_LOCAL_STORAGE_KEY);
const currentListTableExpandedRows = expandedRowsData ? JSON.parse(expandedRowsData)[id] : [];
if (currentListTableExpandedRows) {
setExpandedRowsKeys(currentListTableExpandedRows);
Expand Down

0 comments on commit 7afc927

Please sign in to comment.