private fillDataRecursively()

in src/UXClient/Components/HierarchyNavigation/HierarchyNavigation.ts [1379:1460]


  private fillDataRecursively(
    hierarchyNodes,
    payload,
    payloadForContinuation = null
  ) {
    let data = {};
    hierarchyNodes.hits.forEach((h) => {
      let hierarchy = new HierarchyNode(
        h.name,
        payload.path,
        payload.path.length - this.path.length,
        h.cumulativeInstanceCount
      );
      hierarchy.expand = () => {
        let expandNode = () => {
          hierarchy.isExpanded = true;
          hierarchy.node.classed("tsi-expanded", true);
        };

        if (this.mode === State.Search) {
          return this.pathSearchAndRenderResult({
            search: {
              payload: this.requestPayload(hierarchy.path),
              bubbleUpReject: true,
            },
            render: { target: this.instanceListElem },
          })
            .then((r: any) => expandNode())
            .catch((err) => { });
        } else {
          return this.pathSearchAndRenderResult({
            search: {
              payload: this.requestPayload(hierarchy.path),
              bubbleUpReject: true,
            },
            render: { target: hierarchy.node },
          })
            .then((r: any) => expandNode())
            .catch((err) => { });
        }
      };
      data[this.hierarchyNodeIdentifier(h.name)] = hierarchy;
      if (h.hierarchyNodes && h.hierarchyNodes.hits.length) {
        hierarchy.children = this.fillDataRecursively(
          h.hierarchyNodes,
          this.requestPayload(hierarchy.path),
          payloadForContinuation
        );
      }
    });

    if (
      hierarchyNodes.continuationToken &&
      hierarchyNodes.continuationToken !== "END"
    ) {
      let showMorehierarchy = new HierarchyNode(
        this.getString("Show More Hierarchies"),
        payload.path,
        payload.path.length - this.path.length
      );
      showMorehierarchy.onClick = () => {
        return this.pathSearchAndRenderResult({
          search: {
            payload: payloadForContinuation ? payloadForContinuation : payload,
            hierarchiesContinuationToken: hierarchyNodes.continuationToken,
          },
          render: {
            target: showMorehierarchy.node.select(function () {
              return this.parentNode;
            }),
            locInTarget: ".tsi-show-more.tsi-show-more-hierarchy",
            skipLevels: payloadForContinuation
              ? payload.path.length - payloadForContinuation.path.length
              : null,
          },
        });
      };
      data[showMorehierarchy.name] = showMorehierarchy;
    }

    return data;
  }