Sha256: 836b8208cc037a6a04b8a2eaf1122cb6591e64f9e9385b2012a9adf0eb8b158f
Contents?: true
Size: 1.67 KB
Versions: 24
Compression:
Stored size: 1.67 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.flatRows // Variable checks if all rows in a section have same expansion state or not let isExpansionConsistent = true const areRowsExpanded = new Set<boolean>() // Update isExpansionConsistent variable for (const row of rows) { if ( targetParent === undefined ? row.depth === 0 : targetParent === row.parentId ) { areRowsExpanded.add(row.getIsExpanded()) if (areRowsExpanded.size > 1) { isExpansionConsistent = false break } } } // The if statement runs only for row depth 0, the else statement for the rest if (targetParent === undefined) { rows.forEach(row => { if (row.depth === 0) { updateExpandedRows[row.id] = !isExpansionConsistent ? true : !row.getIsExpanded() } }) } else { for (const row of rows) { if (targetParent === row.parentId) { updateExpandedRows[row.id] = !isExpansionConsistent ? true : !row.getIsExpanded() } } } return filterExpandableRows({ ...(expanded as ExpandedStateObject), ...updateExpandedRows, }) }
Version data entries
24 entries across 24 versions & 1 rubygems