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): return type for asset search query & duplicate assets #4699

Merged
merged 2 commits into from
Aug 13, 2024
Merged
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 @@ -18,6 +18,7 @@ import { useSDK } from '../components/RevealCanvas/SDKProvider';
import { getAssetsList } from '../hooks/network/getAssetsList';
import { useAssetMappedNodesForRevisions } from '../components/CacheProvider/AssetMappingAndNode3DCacheProvider';
import { isDefined } from '../utilities/isDefined';
import { uniq } from 'lodash';

export type ModelMappings = {
model: AddModelOptions;
Expand All @@ -43,7 +44,7 @@ export const useSearchMappedEquipmentAssetMappings = (
models: AddModelOptions[],
limit: number = 100,
userSdk?: CogniteClient
): UseInfiniteQueryResult<InfiniteData<AssetPage[]>, Error> => {
): UseInfiniteQueryResult<InfiniteData<AssetPage>, Error> => {
const sdk = useSDK(userSdk);
const { data: assetMappingList, isFetched } = useAssetMappedNodesForRevisions(
models.map((model) => ({ ...model, type: 'cad' }))
Expand All @@ -64,11 +65,7 @@ export const useSearchMappedEquipmentAssetMappings = (
}
if (query === '') {
const assets = initialAssetMappings.data?.pages.flatMap((modelWithAssets) =>
modelWithAssets
.map((modelWithAsset) =>
modelWithAsset.modelsAssets.flatMap((modelsAsset) => modelsAsset.assets)
)
.flat()
modelWithAssets.modelsAssets.flatMap((modelsAsset) => modelsAsset.assets).flat()
);
return { assets, nextCursor: undefined };
}
Expand All @@ -89,8 +86,11 @@ export const useSearchMappedEquipmentAssetMappings = (
.filter(isDefined);
});

// Remove duplicates
const uniqueFilteredSearchedAssets = uniq(filteredSearchedAssets);

return {
assets: filteredSearchedAssets,
assets: uniqueFilteredSearchedAssets,
nextCursor: assetsResponse.nextCursor
};
},
Expand All @@ -108,7 +108,7 @@ export const useAllMappedEquipmentAssetMappings = (
models: AddModelOptions[],
userSdk?: CogniteClient,
limit: number = 1000
): UseInfiniteQueryResult<InfiniteData<ModelAssetPage[]>, Error> => {
): UseInfiniteQueryResult<InfiniteData<ModelAssetPage>, Error> => {
const sdk = useSDK(userSdk);
const usedCursors = useRef(new Set());

Expand Down
Loading