UNPKG

@itwin/presentation-hierarchies

Version:

A package for creating hierarchies based on data in iTwin.js iModels.

50 lines 2.07 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { iterateChildNodeGroupingParams } from "./Shared.js"; /** @internal */ export function applyGroupHidingParams(props, extraSiblings) { const { grouped, ungrouped, groupingType } = props; if (grouped.length === 0) { return props; } // handle the "no siblings" case if (grouped.length === 1 && ungrouped.length === 0 && extraSiblings === 0) { const hideParams = getHideOptionsFromNodeProcessingParams(grouped[0], groupingType); if (hideParams.hideIfNoSiblings) { return { groupingType, grouped: [], ungrouped: grouped[0].children }; } } // handle the "no children" case const filteredGrouped = new Array(); for (const node of grouped) { if (node.children.length === 1) { const hideParams = getHideOptionsFromNodeProcessingParams(node, groupingType); if (hideParams.hideIfOneGroupedNode) { ungrouped.push(node.children[0]); continue; } } filteredGrouped.push(node); } return { groupingType, grouped: filteredGrouped, ungrouped, }; } function getHideOptionsFromNodeProcessingParams(groupingNode, groupingType) { let hideIfNoSiblings = false; let hideIfOneGroupedNode = false; iterateChildNodeGroupingParams(groupingNode, groupingType, (groupingProps) => { if (hideIfNoSiblings && hideIfOneGroupedNode) { return true; } hideIfNoSiblings ||= !!groupingProps?.hideIfNoSiblings; hideIfOneGroupedNode ||= !!groupingProps?.hideIfOneGroupedNode; return; }); return { hideIfNoSiblings, hideIfOneGroupedNode }; } //# sourceMappingURL=GroupHiding.js.map