Skip to content

Commit

Permalink
feat: throw error if config undefined instead
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite committed Jul 27, 2023
1 parent 4f7f70b commit 94d57a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export type Reveal3DResourcesStyling = {

export type Reveal3DResourcesProps = {
resources: AddResourceOptions[];
fdmAssetMappingConfig: FdmAssetMappingsConfig;
styling?: Reveal3DResourcesStyling;
fdmAssetMappingConfig?: FdmAssetMappingsConfig;
};

export const Reveal3DResources = ({
Expand Down
4 changes: 2 additions & 2 deletions react-components/src/hooks/useCalculateModelsStyling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
* @returns
*/
export const useCalculateModelsStyling = (
fdmAssetMappingConfig: FdmAssetMappingsConfig,
models?: TypedReveal3DModel[],
styling?: Reveal3DResourcesStyling
styling?: Reveal3DResourcesStyling,
fdmAssetMappingConfig?: FdmAssetMappingsConfig,
): Array<PointCloudModelStyling | CadModelStyling> => {
const stylingExternalIds = useMemo(
() => styling?.groups?.flatMap((group) => group.fdmAssetExternalIds) ?? [],
Expand Down
23 changes: 12 additions & 11 deletions react-components/src/hooks/useFdmAssetMappings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ import { DEFAULT_QUERY_STALE_TIME } from '../utilities/constants';
*/
export const useFdmAssetMappings = (
fdmAssetExternalIds: CogniteExternalId[],
fdmConfig: FdmAssetMappingsConfig
fdmConfig?: FdmAssetMappingsConfig
): UseQueryResult<ThreeDModelMappings[]> => {
const fdmSdk = useFdmSdk();

const fdmAssetMappingFilter = {
in: {
property: ['edge', 'startNode'],
values: fdmAssetExternalIds.map((externalId) => ({
space: fdmConfig.assetFdmSpace,
externalId
}))
}
};

return useQuery(
['reveal', 'react-components', fdmAssetExternalIds],
async () => {
if (fdmAssetExternalIds?.length === 0) return [];
if (fdmConfig === undefined) throw Error('FDM config must be defined when using FDM asset mappings');

const fdmAssetMappingFilter = {
in: {
property: ['edge', 'startNode'],
values: fdmAssetExternalIds.map((externalId) => ({
space: fdmConfig.assetFdmSpace,
externalId
}))
}
};

const instances = await fdmSdk.filterInstances(
fdmAssetMappingFilter,
Expand Down

0 comments on commit 94d57a5

Please sign in to comment.