Skip to content

Commit

Permalink
fix(react-components): include all relevant models in edge query (#4562)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite authored Jun 3, 2024
1 parent afdc0dd commit ad0943c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

import {
fetchAncestorNodesForTreeIndex,
getDMSModel,
getDMSModels,
getMappingEdgesForNodeIds,
inspectNodes
} from './requests';
Expand All @@ -33,7 +33,7 @@ export class RevisionFdmNodeCache {

private readonly _treeIndexToFdmEdges = new Map<TreeIndex, FdmEdgeWithNode[]>();

private readonly _model: Promise<DmsUniqueIdentifier | undefined>;
private readonly _modelInstances: Promise<DmsUniqueIdentifier[] | undefined>;

constructor(
cogniteClient: CogniteClient,
Expand All @@ -46,7 +46,7 @@ export class RevisionFdmNodeCache {

this._modelId = modelId;
this._revisionId = revisionId;
this._model = getDMSModel(this._modelId, this._fdmClient).catch(() => undefined);
this._modelInstances = getDMSModels(this._modelId, this._fdmClient).catch(() => undefined);
}

public getClosestParentFdmData(searchTreeIndex: number): FdmNodeDataPromises {
Expand Down Expand Up @@ -251,7 +251,7 @@ export class RevisionFdmNodeCache {

return edgesAndNodes.map((edge) => edge.edge);
}
const modelInstances = await this._model;
const modelInstances = await this._modelInstances;
if (modelInstances === undefined) {
return [];
}
Expand Down
16 changes: 8 additions & 8 deletions react-components/src/components/CacheProvider/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export async function fetchAncestorNodesForTreeIndex(
return ancestorNodes.items;
}

export async function getDMSModel(
export async function getDMSModels(
modelId: number,
fdmClient: FdmSDK
): Promise<DmsUniqueIdentifier> {
): Promise<DmsUniqueIdentifier[]> {
const filter = {
equals: {
property: ['node', 'externalId'],
Expand All @@ -53,25 +53,25 @@ export async function getDMSModel(
version: SYSTEM_SPACE_3D_MODEL_VERSION
};

const model = await fdmClient.filterInstances(filter, 'node', sources);
return model.instances[0];
const modelResults = await fdmClient.filterInstances(filter, 'node', sources);
return modelResults.instances;
}

export async function getMappingEdgesForNodeIds(
model: DmsUniqueIdentifier,
models: DmsUniqueIdentifier[],
revisionId: number,
fdmClient: FdmSDK,
ancestorIds: CogniteInternalId[]
): Promise<{ edges: FdmCadEdge[] }> {
const filter = {
and: [
{
equals: {
in: {
property: ['edge', 'endNode'],
value: {
values: models.map((model) => ({
externalId: model.externalId,
space: model.space
}
}))
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions react-components/src/query/useSearchMappedEquipmentFDM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { type UseQueryResult, useQuery } from '@tanstack/react-query';
import { SYSTEM_3D_EDGE_SOURCE, SYSTEM_SPACE_3D_SCHEMA } from '../utilities/globalDataModels';
import { type AddModelOptions } from '@cognite/reveal';
import { isEqual, uniq, chunk } from 'lodash';
import { getDMSModel } from '../components/CacheProvider/requests';
import { getDMSModels } from '../components/CacheProvider/requests';

export type SearchResultsWithView = { view: Source; instances: NodeItem[] };

Expand Down Expand Up @@ -258,9 +258,9 @@ async function createMappedEquipmentMaps(
revisionId.toString() === getRevisionIdFromEdge(edge)
);

const modelInstance = await getDMSModel(parseInt(endExternalId), fdmSdk);
const modelInstances = await getDMSModels(parseInt(endExternalId), fdmSdk);

if (endSpace === modelInstance.space && isModelsMapped) {
if (modelInstances.find((model) => model.space === endSpace) !== undefined && isModelsMapped) {
const key = `${space}/${externalId}`;

const keyEdges = mappedEquipmentFirstLevelMap[key];
Expand Down

0 comments on commit ad0943c

Please sign in to comment.