import type { GridRowId } from '../types' import type { Collection, SortFn } from './types' export function getSortedChildren( collection: Collection, parentId: null | GridRowId, sortFn: SortFn ) { /* Start by grabbing all the root ids, optionally filtering them if a filter is present */ let ids = collection.ids if (parentId) { ids = collection.meta.get(parentId)?.children ?? [] } const sortedIds = sortFn ? sortFn(ids, collection.entities, collection.meta) : ids return sortedIds }