Sha256: c3a9f7d60ce6a0453f57f3b2a10115b1ea925cacf5a1e808d0efa20d0dc6ee57
Contents?: true
Size: 1.35 KB
Versions: 3
Compression:
Stored size: 1.35 KB
Contents
import { RowModel } from "@tanstack/react-table" import { DataType, ExpandedStateObject } from "./types" const filterExpandableRows = (expandedState: Record<string, boolean>) => { for (const expandedRow in expandedState) { if (expandedState[expandedRow] === false) { delete expandedState[expandedRow] } } return expandedState } export const updateExpandAndCollapseState = ( tableRows: RowModel<DataType>, expanded: Record<string, boolean>, targetParent: string ) => { const updateExpandedRows: Record<string, boolean> = {}; const rows = tableRows.rows; let isExpansionConsistent = true; const areRowsExpanded = new Set<boolean>(); for (const row of rows) { const shouldBeUpdated = targetParent === undefined ? row.depth === 0 : targetParent === row.parentId; if (shouldBeUpdated) { const isExpanded = row.getIsExpanded(); areRowsExpanded.add(isExpanded); updateExpandedRows[row.id] = !isExpansionConsistent ? true : !isExpanded; if (areRowsExpanded.size > 1) { isExpansionConsistent = false; // If expansion inconsistent, ensure all target rows are set to expand for (const key in updateExpandedRows) { updateExpandedRows[key] = true; } } } } return filterExpandableRows({ ...(expanded as ExpandedStateObject), ...updateExpandedRows, }); };
Version data entries
3 entries across 3 versions & 1 rubygems