UNPKG

@itwin/presentation-hierarchies

Version:

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

53 lines 2.2 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.applyGroupHidingParams = applyGroupHidingParams; const Shared_js_1 = require("./Shared.js"); /** @internal */ 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; (0, Shared_js_1.iterateChildNodeGroupingParams)(groupingNode, groupingType, (groupingProps) => { if (hideIfNoSiblings && hideIfOneGroupedNode) { return true; } hideIfNoSiblings ||= !!groupingProps?.hideIfNoSiblings; hideIfOneGroupedNode ||= !!groupingProps?.hideIfOneGroupedNode; return; }); return { hideIfNoSiblings, hideIfOneGroupedNode }; } //# sourceMappingURL=GroupHiding.js.map