From 93a2a8a60413099efd4b5c7b3bb76bdbd50efb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Wed, 2 Aug 2023 09:49:05 +0200 Subject: [PATCH 1/4] fix: propagate undefined results to click handler --- .../components/Reveal3DResources/Reveal3DResources.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx b/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx index a98a1588deb..abaa0a21a5c 100644 --- a/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx +++ b/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx @@ -43,7 +43,7 @@ export type Reveal3DResourcesProps = { resources: AddResourceOptions[]; fdmAssetMappingConfig: FdmAssetMappingsConfig; styling?: Reveal3DResourcesStyling; - onNodeClick?: (node: NodeDataResult) => void; + onNodeClick?: (node: NodeDataResult | undefined) => void; }; export const Reveal3DResources = ({ @@ -76,6 +76,7 @@ export const Reveal3DResources = ({ useEffect(() => { const callback = (event: PointerEventData): void => { void (async (event: PointerEventData): Promise => { + if (onNodeClick === undefined) return; const data = await queryMappedData( viewer, client, @@ -83,9 +84,8 @@ export const Reveal3DResources = ({ fdmAssetMappingConfig, event ); - if (onNodeClick !== undefined && data !== undefined) { - onNodeClick?.(data); - } + + onNodeClick(data); })(event); }; From 630b51e2d072ff794c8933fe9931f850b1ed7447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Wed, 2 Aug 2023 09:50:08 +0200 Subject: [PATCH 2/4] fix: expose intersection in click handler parameter --- .../src/components/Reveal3DResources/queryMappedData.ts | 2 +- .../src/components/Reveal3DResources/types.ts | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/react-components/src/components/Reveal3DResources/queryMappedData.ts b/react-components/src/components/Reveal3DResources/queryMappedData.ts index 7deee733e36..c92f8ecd387 100644 --- a/react-components/src/components/Reveal3DResources/queryMappedData.ts +++ b/react-components/src/components/Reveal3DResources/queryMappedData.ts @@ -73,7 +73,7 @@ export async function queryMappedData( data: nodeData, view: dataView, cadNode: selectedNode, - model: cadIntersection.model + intersection: cadIntersection }; } diff --git a/react-components/src/components/Reveal3DResources/types.ts b/react-components/src/components/Reveal3DResources/types.ts index 821e635c621..13338e6c100 100644 --- a/react-components/src/components/Reveal3DResources/types.ts +++ b/react-components/src/components/Reveal3DResources/types.ts @@ -2,11 +2,7 @@ * Copyright 2023 Cognite AS */ -import { - type CogniteCadModel, - type AddModelOptions, - type SupportedModelTypes -} from '@cognite/reveal'; +import { type AddModelOptions, type SupportedModelTypes, CadIntersection } from '@cognite/reveal'; import { type Matrix4 } from 'three'; import { type FdmNode, type Source } from '../../utilities/FdmSDK'; import { type Node3D } from '@cognite/sdk/dist/src'; @@ -26,5 +22,5 @@ export type NodeDataResult = { data: FdmNode; view: Source; cadNode: Node3D; - model: CogniteCadModel; + intersection: CadIntersection; }; From b1ab62cc5884ae29952166e89c7cd07a2e8208fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Wed, 2 Aug 2023 09:57:12 +0200 Subject: [PATCH 3/4] chore: lint fix --- react-components/src/components/Reveal3DResources/types.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/react-components/src/components/Reveal3DResources/types.ts b/react-components/src/components/Reveal3DResources/types.ts index 13338e6c100..63d4875a396 100644 --- a/react-components/src/components/Reveal3DResources/types.ts +++ b/react-components/src/components/Reveal3DResources/types.ts @@ -2,7 +2,11 @@ * Copyright 2023 Cognite AS */ -import { type AddModelOptions, type SupportedModelTypes, CadIntersection } from '@cognite/reveal'; +import { + type AddModelOptions, + type SupportedModelTypes, + type CadIntersection +} from '@cognite/reveal'; import { type Matrix4 } from 'three'; import { type FdmNode, type Source } from '../../utilities/FdmSDK'; import { type Node3D } from '@cognite/sdk/dist/src'; From b7980fd43c794e3241168457283721858f9c24f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Wed, 2 Aug 2023 11:04:21 +0200 Subject: [PATCH 4/4] fix: correct HighlightNode story --- .../stories/HighlightNode.stories.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/react-components/stories/HighlightNode.stories.tsx b/react-components/stories/HighlightNode.stories.tsx index 83f62109de3..4b538d94a7a 100644 --- a/react-components/stories/HighlightNode.stories.tsx +++ b/react-components/stories/HighlightNode.stories.tsx @@ -66,15 +66,17 @@ const StoryContent = ({ resources: AddResourceOptions[]; fdmAssetMappingConfig: FdmAssetMappingsConfig; }): ReactElement => { - const [nodeData, setNodeData] = useState(); + const [nodeData, setNodeData] = useState(undefined); - const [highlightedId, setHighlightedId] = useState(''); + const [highlightedId, setHighlightedId] = useState(undefined); - const callback = (nodeData: NodeDataResult): void => { - setNodeData(nodeData.data); + const callback = (nodeData: NodeDataResult | undefined): void => { + setNodeData(nodeData?.data); + setHighlightedId(nodeData?.data?.externalId); - setHighlightedId(nodeData.data.externalId); - nodeData.model.assignStyledNodeCollection( + if (nodeData === undefined) return; + + nodeData.intersection.model.assignStyledNodeCollection( new TreeIndexNodeCollection([nodeData.cadNode.treeIndex]), DefaultNodeAppearance.Highlighted ); @@ -86,7 +88,7 @@ const StoryContent = ({ resources={resources} styling={{ groups: - highlightedId.length === 0 + highlightedId === undefined ? undefined : [ {