From 1ab3dee455b41a314cc639167347721dff6eeb87 Mon Sep 17 00:00:00 2001 From: Daniel Priori Date: Wed, 8 Jan 2025 06:19:51 -0300 Subject: [PATCH] fix(react-components): avoid fetching classic asset mappings when in coredm only and recache all revisionIds when requesting the connections with views (#4946) * Avoid fetching classic asset mappings when in coredm only and recache all revisionIds when request the connecitons with views * fix the request of views and add a hook with the coreDM flag * cr changes --- .../components/CacheProvider/RevisionFdmNodeCache.ts | 4 ++-- .../RuleBasedOutputs/RuleBasedOutputsSelector.tsx | 4 ++-- .../src/hooks/cad/useAssetMappedNodesForRevisions.ts | 5 ++++- react-components/src/hooks/useIsCoreDmOnly.ts | 10 ++++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 react-components/src/hooks/useIsCoreDmOnly.ts diff --git a/react-components/src/components/CacheProvider/RevisionFdmNodeCache.ts b/react-components/src/components/CacheProvider/RevisionFdmNodeCache.ts index 3b5769f745e..84abc4fd235 100644 --- a/react-components/src/components/CacheProvider/RevisionFdmNodeCache.ts +++ b/react-components/src/components/CacheProvider/RevisionFdmNodeCache.ts @@ -301,9 +301,9 @@ export class RevisionFdmNodeCache { ); allConnectionsWithoutView.forEach((fdmConnectionWithNode, ind) => { - const connectionWithView = { + const connectionWithView: FdmConnectionWithNode = { ...fdmConnectionWithNode, - view: nodeInspectionResults.items[ind].inspectionResults.involvedViews[0] + views: [nodeInspectionResults.items[ind].inspectionResults.involvedViews[0]] }; this.insertTreeIndexMappings(connectionWithView.cadNode.treeIndex, connectionWithView); diff --git a/react-components/src/components/RuleBasedOutputs/RuleBasedOutputsSelector.tsx b/react-components/src/components/RuleBasedOutputs/RuleBasedOutputsSelector.tsx index d7505fe56f3..875ee904fe3 100644 --- a/react-components/src/components/RuleBasedOutputs/RuleBasedOutputsSelector.tsx +++ b/react-components/src/components/RuleBasedOutputs/RuleBasedOutputsSelector.tsx @@ -115,10 +115,10 @@ export function RuleBasedOutputsSelector({ const flatAssetsMappingsList = flatAssetsMappingsListPerModel.get(model) ?? []; - if (flatAssetsMappingsList.length === 0) return []; + if (flatAssetsMappingsList.length === 0 && fdmMappings?.length === 0) return []; const mappingsStylings = await initializeRuleBasedOutputs({ - assetMappings: flatAssetsMappingsList ?? [], + assetMappings: flatAssetsMappingsList, fdmMappings: fdmMappings ?? [], contextualizedAssetNodes, ruleSet, diff --git a/react-components/src/hooks/cad/useAssetMappedNodesForRevisions.ts b/react-components/src/hooks/cad/useAssetMappedNodesForRevisions.ts index c4056a018a8..ad072836ba8 100644 --- a/react-components/src/hooks/cad/useAssetMappedNodesForRevisions.ts +++ b/react-components/src/hooks/cad/useAssetMappedNodesForRevisions.ts @@ -5,12 +5,15 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query'; import { type CadModelOptions } from '../../components'; import { type ModelWithAssetMappings } from './ModelWithAssetMappings'; import { useAssetMappingAndNode3DCache } from '../../components/CacheProvider/CacheProvider'; +import { useIsCoreDmOnly } from '../useIsCoreDmOnly'; export const useAssetMappedNodesForRevisions = ( cadModels: CadModelOptions[] ): UseQueryResult => { const assetMappingAndNode3DCache = useAssetMappingAndNode3DCache(); + const isCoreDmOnly = useIsCoreDmOnly(); + return useQuery({ queryKey: [ 'reveal', @@ -28,6 +31,6 @@ export const useAssetMappedNodesForRevisions = ( return await Promise.all(fetchPromises); }, staleTime: Infinity, - enabled: cadModels.length > 0 + enabled: cadModels.length > 0 && !isCoreDmOnly }); }; diff --git a/react-components/src/hooks/useIsCoreDmOnly.ts b/react-components/src/hooks/useIsCoreDmOnly.ts new file mode 100644 index 00000000000..d6826a71e2e --- /dev/null +++ b/react-components/src/hooks/useIsCoreDmOnly.ts @@ -0,0 +1,10 @@ +/*! + * Copyright 2025 Cognite AS + */ +import { useRenderTarget } from '../components'; + +export function useIsCoreDmOnly(): boolean { + const renderTarget = useRenderTarget(); + const isCoreDmOnly = renderTarget.cdfCaches.coreDmOnly; + return isCoreDmOnly ?? false; +}