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.11.1.pre.alpha.PLAY1720phonenumberinputformatAsYouType5377 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.play17725374 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.play17725372 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.12.0.pre.rc.4 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.hfhbrakemanplaybook5370 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.responsivetablerails5364 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.responsivetablerails5362 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR769sticky5359 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.PBNTR573datepickerinvestigation5355 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5341 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5340 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1.pre.alpha.PLAY1750pbcontenttagkitbutton5339 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.12.0.pre.rc.3 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.12.0.pre.rc.2 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.12.0.pre.rc.1 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.12.0.pre.rc.0 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.10.0.pre.alpha.PLAY1774timelinelabelstepspacing5315 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.10.0.pre.alpha.PLAY1774timelinelabelstepspacing5314 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.10.0.pre.alpha.PLAY1750pbcontenttagkitbutton5308 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-14.11.1 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx