Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-components): include all relevant models in edge query #4562

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading