import { IStoreState, ID } from '../../index.data'; import { getRow, getCell, getCellType, isTreeRow } from '../selectors'; export function tryToggleCollapse( state: IStoreState, cellId: ID, ): | { collapsedRowIds: ID[]; } | null | undefined { const { collapsedRowIds = [], treeContext } = state; const cell = getCell(state, cellId)!; if (getCellType(state, cell.id) !== 'row-no') return; const row = getRow(state, cell.rowId!); return isTreeRow(row) && treeContext[row.id].childrenIds.length > 0 ? { collapsedRowIds: collapsedRowIds.includes(row.id) ? collapsedRowIds.filter(it => it !== row.id) : [...collapsedRowIds, row.id], } : null; }