Skip to content

Commit

Permalink
fix(react-components): export useAssetMappedNodesForRevisions hook to…
Browse files Browse the repository at this point in the history
… check for loading state of asset mapping (#4709)

* exported useAssetMappedNodesForRevisions hook to check for loading state of asset mapping

* enable useSearchMappedEquipmentAssetMappings query only when initialAssetMappings value is loaded

* renamed asset mapping node fetch variable
  • Loading branch information
pramodcog authored Aug 20, 2024
1 parent d9b6130 commit 5d60eca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions react-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export {
export { useImage360AnnotationMappingsForAssetIds } from './components/CacheProvider/Image360AnnotationCacheProvider';
export { useLoadedScene } from './components/SceneContainer/LoadedSceneContext';
export { useIsDraggingOnViewer } from './hooks/useIsDraggingOnViewer';
export { useAssetMappedNodesForRevisions } from './components/CacheProvider/AssetMappingAndNode3DCacheProvider';

// Queries
export { use3DModelName } from './query/use3DModelName';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export const useSearchMappedEquipmentAssetMappings = (
userSdk?: CogniteClient
): UseInfiniteQueryResult<InfiniteData<AssetPage>, Error> => {
const sdk = useSDK(userSdk);
const { data: assetMappingList, isFetched } = useAssetMappedNodesForRevisions(
models.map((model) => ({ ...model, type: 'cad' }))
);
const initialAssetMappings = useAllMappedEquipmentAssetMappings(models, sdk);
const { data: assetMappingList, isFetched: isAssetMappingNodesFetched } =
useAssetMappedNodesForRevisions(models.map((model) => ({ ...model, type: 'cad' })));
const { data: initialAssetMappings, isLoading: isInitialAssetMappingsLoading } =
useAllMappedEquipmentAssetMappings(models, sdk);

return useInfiniteQuery({
queryKey: [
Expand All @@ -60,11 +60,11 @@ export const useSearchMappedEquipmentAssetMappings = (
...models.map((model) => [model.modelId, model.revisionId])
],
queryFn: async ({ pageParam }: { pageParam: string | undefined }) => {
if (initialAssetMappings.data === undefined) {
if (initialAssetMappings === undefined) {
return { assets: [], nextCursor: undefined };
}
if (query === '') {
const assets = initialAssetMappings.data?.pages.flatMap((modelWithAssets) =>
const assets = initialAssetMappings.pages.flatMap((modelWithAssets) =>
modelWithAssets.modelsAssets.flatMap((modelsAsset) => modelsAsset.assets).flat()
);
return { assets, nextCursor: undefined };
Expand Down Expand Up @@ -100,7 +100,11 @@ export const useSearchMappedEquipmentAssetMappings = (
const lastPageData = allPages[allPages.length - 1];
return lastPageData.nextCursor;
},
enabled: isFetched && assetMappingList !== undefined && assetMappingList.length > 0
enabled:
!isInitialAssetMappingsLoading &&
isAssetMappingNodesFetched &&
assetMappingList !== undefined &&
assetMappingList.length > 0
});
};

Expand Down

0 comments on commit 5d60eca

Please sign in to comment.