in src/UXClient/Components/HierarchyNavigation/HierarchyNavigation.ts [913:1018]
public async showInstance(
timeSeriesID: Array<string | null>,
hierarchyIds: Array<string> = null
) {
this.removeCurrentHitsOfLastLookup();
this.timeSeriesIdForLookup = timeSeriesID;
let isHierarchySelected =
this.selectedHierarchyName !== HierarchySelectionValues.All &&
this.selectedHierarchyName !== HierarchySelectionValues.Unparented;
let hierarchyNamesFromParam = hierarchyIds
? hierarchyIds.map((hId) =>
Object.keys(this.envHierarchies).find(
(n) => this.envHierarchies[n].id === hId
)
)
: null;
let hNames = hierarchyNamesFromParam
? hierarchyNamesFromParam
: isHierarchySelected
? [null, this.selectedHierarchyName]
: [null, ...Object.keys(this.envHierarchies)]; // adding null for search with direct instances
let instance;
let paths = [];
try {
this.prepareComponentForLookup(timeSeriesID);
let response;
response = await this.getInstance(timeSeriesID);
instance = response["get"][0]["instance"];
let instanceFieldValues = instance.instanceFields
? Object.values(instance.instanceFields)
: [];
if (instance) {
try {
this.lastLookedupInstance = instance;
response = await this.doExactSearchWithPossiblePaths(
timeSeriesID,
hNames
);
response.forEach((r, idx) => {
// get full paths
if (r.error) {
throw r.error;
}
if (idx === 0) {
// if instance is direct instance of the top root
if (r.instances?.hitCount) {
paths.push([]);
}
} else {
// under defined hierarchies
if (r.hierarchyNodes?.hits?.length) {
// if the instance is under sub nodes in the hierarchy
r.hierarchyNodes.hits.forEach((h) => {
let currentHit = h;
if (instanceFieldValues.indexOf(currentHit.name) !== -1) {
let path: Array<string> = [hNames[idx]];
path.push(currentHit.name);
while (currentHit.hierarchyNodes) {
currentHit = currentHit.hierarchyNodes.hits[0];
if (
instanceFieldValues?.indexOf(currentHit.name) !== -1
) {
path.push(currentHit.name);
}
}
paths.push(path);
}
});
} else if (r.instances?.hitCount) {
// if it is direct instance under the defined the hierarchy
let path: Array<string> = [hNames[idx]];
paths.push(path);
}
}
});
if (paths.length) {
// go back to default navigate mode without exact search
this.prepareComponentForAfterLookup();
await this.clearAndGetResults(); // get a fresh hierarchy with defaulf settings for navigation, ready to expand and locate
await Promise.all(
paths.map((p) =>
this.simulateExpand(p, hierarchyNamesFromParam, instance)
)
);
this.clearAndHideFilterPath();
} else {
this.showNotFoundForReverseLookup();
}
this.hierarchyElem.style("display", "block");
this.instanceLookupLoadingElem.style("display", "none");
} catch (err) {
// errors are already catched by inner functions
throw err; // throw to be catched by parent try/catch block
}
} else {
this.showNotFoundForReverseLookup();
}
} catch (err) {
// errors are already catched by inner functions
this.showNotFoundForReverseLookup();
}
}