Skip to content

Commit

Permalink
updated lodash unique to filter with safe type guard
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodcog committed Aug 22, 2024
1 parent d13ebdb commit 7bbba83
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export async function fetchPointCloudAnnotationAssets(
});
const filteredAnnotationMapping = annotationMapping.filter(isDefined);

const uniqueAnnotationMapping = uniqBy(filteredAnnotationMapping, 'assetId');
const uniqueAnnotationMapping = uniqBy(
filteredAnnotationMapping,
(annotationMapping) => annotationMapping.assetId
);
const assetIds = uniqueAnnotationMapping.map((mapping) => mapping.assetId);
const assets = await fetchAssetForAssetIds(assetIds, sdk);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useExtractUniqueAssetIdsFromMapped = (
id: item.assetId
};
});
const uniqueAssetIds = uniqBy(assetIds, 'id');
const uniqueAssetIds = uniqBy(assetIds, (assetId) => assetId.id);
return uniqueAssetIds;
}, [assetMappings]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ async function get360AnnotationAssets(
})
.filter(isDefined);

const uniqueAnnotationMapping = uniqBy(filteredAnnotationMappings, 'assetId');
const uniqueAnnotationMapping = uniqBy(
filteredAnnotationMappings,
(annotationMapping) => annotationMapping.assetId
);

const assets = await retrieveAssets(sdk, uniqueAnnotationMapping);
const flatAssets = assets.flat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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';
import { uniqBy } from 'lodash';

export type ModelMappings = {
model: AddModelOptions;
Expand Down Expand Up @@ -81,7 +81,10 @@ export const useSearchMappedEquipmentAssetMappings = (
.filter(isDefined);
});

const uniqueAssets = uniq([...accumulatedAssets, ...filteredSearchedAssets]);
const uniqueAssets = uniqBy(
[...accumulatedAssets, ...filteredSearchedAssets],
(asset) => asset.id
);

if (uniqueAssets.length >= limit || assetsResponse.nextCursor === undefined) {
return { assets: uniqueAssets, nextCursor: assetsResponse.nextCursor };
Expand Down

0 comments on commit 7bbba83

Please sign in to comment.