Sha256: bafa2b6b21eced2d52b8b922d805aae1e6c1681bf95e22281bdcc199ee8810d4

Contents?: true

Size: 1.39 KB

Versions: 558

Compression:

Stored size: 1.39 KB

Contents

import { RowModel } from "@tanstack/react-table"
import { ExpandedStateObject } from "./types"
import { GenericObject } 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<GenericObject>,
  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

558 entries across 558 versions & 1 rubygems

Version Path
playbook_ui-14.0.0.pre.alpha.PLAY15063511 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PA1477timestampkit3509 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PLAY14733507 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PBNTR416formpillsizes3506 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PA1477timestampkit3502 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PBNTR415starratingform3493 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PBNTR415starratingform3492 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PLAY1475bumpaxecoredependency3483 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PLAY14733479 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.dependabotnpmandyarnreactjoyride2823478 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.PLAY14113475 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.0.0.pre.alpha.play1447alphatest3462 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.1.0 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.34.1.pre.alpha.play1447addrequiredicons3455 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.34.1.pre.alpha.play1447addrequiredicons3451 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.34.1.pre.alpha.PLAY14043436 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3413 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3411 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3409 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.34.1.pre.alpha.pbntr258paginationkitforreact3404 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx