Skip to content

Commit

Permalink
consider data model version when request for data fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodcog committed Sep 26, 2024
1 parent c3797fe commit 76b20b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
2 changes: 1 addition & 1 deletion react-components/src/data-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*/

export type { FdmInstanceWithView, InstanceReference, AssetInstanceReference } from './types';
export type { Source, DmsUniqueIdentifier } from './FdmSDK';
export type { Source, DmsUniqueIdentifier, SimpleSource } from './FdmSDK';
33 changes: 9 additions & 24 deletions react-components/src/query/useSearchMappedEquipmentFDM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
type NodeItem,
type FdmSDK,
type Source,
type DmsUniqueIdentifier,
type InstanceFilter
type InstanceFilter,
type SimpleSource
} from '../data-providers/FdmSDK';
import { useFdm3dDataProvider, useFdmSdk } from '../components/RevealCanvas/SDKProvider';
import { type UseQueryResult, useQuery } from '@tanstack/react-query';
Expand All @@ -21,7 +21,7 @@ export type InstancesWithView = { view: Source; instances: NodeItem[] };

export const useSearchMappedEquipmentFDM = (
query: string,
viewsToSearch: DmsUniqueIdentifier[],
viewsToSearch: SimpleSource[],
models: AddModelOptions[],
instancesFilter: InstanceFilter | undefined,
limit: number = 100
Expand Down Expand Up @@ -53,7 +53,7 @@ export const useSearchMappedEquipmentFDM = (
if (models.length === 0) {
return [];
}
const sources = await createSourcesFromViews(viewsToSearch, fdmSdk);
const sources = await createSourcesFromViews(viewsToSearch);
const chunkedSources = chunk(sources, 10);
if (chunkedSources.length === 0) {
chunkedSources.push([]);
Expand Down Expand Up @@ -127,15 +127,14 @@ const searchNodesWithViewsAndModels = async (

export const useAllMappedEquipmentFDM = (
models: AddModelOptions[],
viewsToSearch: DmsUniqueIdentifier[]
viewsToSearch: SimpleSource[]
): UseQueryResult<NodeItem[]> => {
const fdmSdk = useFdmSdk();
const fdmDataProvider = useFdm3dDataProvider();

return useQuery({
queryKey: ['reveal', 'react-components', 'all-mapped-equipment-fdm', viewsToSearch, models],
queryFn: async () => {
const viewSources = await createSourcesFromViews(viewsToSearch, fdmSdk);
const viewSources = await createSourcesFromViews(viewsToSearch);

return await fdmDataProvider.listAllMappedFdmNodes(models, viewSources, undefined);
},
Expand Down Expand Up @@ -189,33 +188,19 @@ function convertQueryNodeItemsToSearchResultsWithViews(
}, []);
}

async function createSourcesFromViews(
viewsToSearch: DmsUniqueIdentifier[],
fdmSdk: FdmSDK
): Promise<Source[]> {
async function createSourcesFromViews(viewsToSearch: SimpleSource[]): Promise<Source[]> {
try {
const dataModelResult = await fdmSdk.listDataModels();
const viewToVersionMap = new Map<string, string>(
dataModelResult.items.flatMap((dataModel: { views: Source[] }) => {
return dataModel.views.map(
(view: Source) => [`${view.space}/${view.externalId}`, view.version] as const
);
})
);

return viewsToSearch
.map((view) => {
const version = viewToVersionMap.get(`${view.space}/${view.externalId}`);
if (version === undefined) {
if (view.version === undefined) {
console.error(
`Could not find version for view with space/externalId ${view.space}/${view.externalId}`
);
return undefined;
}
return {
...view,
type: 'view' as const,
version
type: 'view' as const
};
})
.filter(isDefined);
Expand Down

0 comments on commit 76b20b4

Please sign in to comment.