Skip to content

Commit

Permalink
fix(react-components): avoid fetching classic asset mappings when in …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
danpriori authored Jan 8, 2025
1 parent 7f210db commit 1ab3dee
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelWithAssetMappings[]> => {
const assetMappingAndNode3DCache = useAssetMappingAndNode3DCache();

const isCoreDmOnly = useIsCoreDmOnly();

return useQuery({
queryKey: [
'reveal',
Expand All @@ -28,6 +31,6 @@ export const useAssetMappedNodesForRevisions = (
return await Promise.all(fetchPromises);
},
staleTime: Infinity,
enabled: cadModels.length > 0
enabled: cadModels.length > 0 && !isCoreDmOnly
});
};
10 changes: 10 additions & 0 deletions react-components/src/hooks/useIsCoreDmOnly.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 1ab3dee

Please sign in to comment.