import { IStoreState, ID, IRow, ICell } from '../../index.data'; import * as R from 'rambda'; import { TreeContext } from 'valor-app-utils'; /** * 矩阵是几行几列的 */ export function getSize(state: IStoreState): { rowCount: number; colCount: number } { return { rowCount: state.rows.length, colCount: (state.columns || []).length }; } /** * 哪些行被隐藏了 */ export function getAllCollapsedRowIds(state: IStoreState): ID[] { const { collapsedRowIds, treeContext } = state; const t = collapsedRowIds.map(rowId => getDecendants(treeContext, rowId)); return R.uniq(R.flatten(t as any)); } /** * 返回类似于bitset的数组, [true, false, false,..] * 数组元素代表当前row[i]是否被折叠, 数组长度等于state.rows * @params state * @return [true, false...] */ export function getAllCollapsedRowFlags(state: IStoreState): boolean[] { const allCollapsedRowIds = getAllCollapsedRowIds(state); const result = R.repeat(false, state.rows.length); const rowIds = state.rows.map(it => it.id); for (let i = 0; i < allCollapsedRowIds.length; i++) { const idx = rowIds.indexOf(allCollapsedRowIds[i]); result[idx] = true; } return result; } function getDecendants(treeContext: TreeContext, id: ID): ID[] { const childrenIds = treeContext[id].childrenIds; if (!childrenIds || childrenIds.length <= 0) { return []; } else { return childrenIds.concat(childrenIds.map(id => getDecendants(treeContext, id))); } }