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

Version Path
playbook_ui-13.21.0.pre.alpha.PLAY12652489 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.21.0.pre.alpha.PBNTR224letuserresetrowexpansion2441 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.21.0.pre.alpha.PBNTR238DatePickerYearBug2436 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.20.0.pre.alpha.play1247htmloptions2404 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.20.0.pre.alpha.play1247htmloptions2403 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.20.0.pre.alpha.PLAY12572402 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.21.0 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.PBNTR200addadvancedtablekitdarkmodestyles2346 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.play1174fixconfimationtoastmobilebug2345 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.play1174fixconfimationtoastmobilebug2342 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.play1186collapsiblenaviconcolorbug2321 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.PBNTR211tablekitsubcomponentsreact2318 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.play1174fixconfimationtoastmobilebug2306 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.play1174fixconfimationtoastmobilebug2305 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.20.0 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.play1141iconkitusinglibrary2264 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.PBNTR207tabledivsupport2261 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0.pre.alpha.PBNTR207tabledivsupport2245 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.19.0 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx
playbook_ui-13.18.0.pre.alpha.PBNTR191AdvancedTableFinalFixes2197 app/pb_kits/playbook/pb_advanced_table/Utilities/ExpansionControlHelpers.tsx