UNPKG

@itwin/presentation-hierarchies

Version:

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

75 lines 4.82 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.LOGGING_NAMESPACE = void 0; exports.createHideIfNoChildrenOperator = createHideIfNoChildrenOperator; const rxjs_1 = require("rxjs"); const Common_js_1 = require("../../internal/Common.js"); const LoggingUtils_js_1 = require("../../internal/LoggingUtils.js"); const Partition_js_1 = require("../../internal/operators/Partition.js"); const IModelHierarchyNode_js_1 = require("../IModelHierarchyNode.js"); // cspell:words doesnt const OPERATOR_NAME = "HideIfNoChildren"; /** @internal */ exports.LOGGING_NAMESPACE = (0, Common_js_1.createOperatorLoggingNamespace)(OPERATOR_NAME, Common_js_1.LOGGING_NAMESPACE_INTERNAL); /** * Creates an operator that hides nodes with no children if they have a `hideIfNoChildren` handling param. * * @internal */ function createHideIfNoChildrenOperator(hasNodes) { return function (nodes) { const inputNodes = nodes.pipe( /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.log)({ category: exports.LOGGING_NAMESPACE, message: (n) => `in: ${(0, Common_js_1.createNodeIdentifierForLogging)(n)}` })); // split input into 3 pieces: // - `doesntNeedHide` - nodes without the flag (return no matter if they have children or not) // - `determinedChildren` - nodes with the flag and known children // - `undeterminedChildren` - nodes with the flag and unknown children const [needsHide, doesntNeedHide] = (0, Partition_js_1.partition)(inputNodes, (n) => (IModelHierarchyNode_js_1.ProcessedHierarchyNode.isGeneric(n) || IModelHierarchyNode_js_1.ProcessedHierarchyNode.isInstancesNode(n)) && !!n.processingParams?.hideIfNoChildren); const [determinedChildren, undeterminedChildren] = (0, Partition_js_1.partition)(needsHide, (n) => n.children !== undefined); return (0, rxjs_1.merge)(doesntNeedHide.pipe( /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.log)({ category: exports.LOGGING_NAMESPACE, message: (n) => `${(0, Common_js_1.createNodeIdentifierForLogging)(n)}: doesn't need hide` })), (0, rxjs_1.merge)(determinedChildren.pipe( /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.log)({ category: exports.LOGGING_NAMESPACE, message: (n) => `${(0, Common_js_1.createNodeIdentifierForLogging)(n)}: needs hide, has children`, })), undeterminedChildren.pipe( /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.log)({ category: exports.LOGGING_NAMESPACE, message: (n) => `${(0, Common_js_1.createNodeIdentifierForLogging)(n)}: needs hide, needs children`, }), (0, rxjs_1.mergeMap)((n) => (0, rxjs_1.defer)(() => { /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.doLog)({ category: exports.LOGGING_NAMESPACE, message: () => `${(0, Common_js_1.createNodeIdentifierForLogging)(n)}: requesting children flag`, }); return hasNodes(n).pipe( /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.log)({ category: exports.LOGGING_NAMESPACE, message: (childrenFlag) => `${(0, Common_js_1.createNodeIdentifierForLogging)(n)}: determined children: ${childrenFlag}`, }), (0, rxjs_1.map)((children) => Object.assign(n, { children }))); }), // Sending child check requests for all nodes without any limit greatly slows down // the following case: // - NodeX (determining children) -> ... lots of children with "hide if no children" -> ... // We check the nodes with "hide if no children" at most 2 at a time to prefer going deep into // the hierarchy, where we're more likely to find an answer, rather than going wide. 2), /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.log)({ category: exports.LOGGING_NAMESPACE, message: (n) => `${(0, Common_js_1.createNodeIdentifierForLogging)(n)}: needs hide, determined children: ${(0, Common_js_1.hasChildren)(n)}`, }))).pipe((0, rxjs_1.filter)(Common_js_1.hasChildren))).pipe( /* v8 ignore next -- @preserve */ (0, LoggingUtils_js_1.log)({ category: exports.LOGGING_NAMESPACE, message: (n) => `out: ${(0, Common_js_1.createNodeIdentifierForLogging)(n)}` })); }; } //# sourceMappingURL=HideIfNoChildren.js.map