From 5937fe84dee22b5418c75862c00c33607a8b9016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Fri, 4 Aug 2023 14:57:28 +0200 Subject: [PATCH 1/4] feat: only make 4 requests instead of 5, return node ex-ID only --- .../src/components/Reveal3DResources/queryMappedData.ts | 8 +------- .../src/components/Reveal3DResources/types.ts | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/react-components/src/components/Reveal3DResources/queryMappedData.ts b/react-components/src/components/Reveal3DResources/queryMappedData.ts index c92f8ecd387..ebfb6b58e18 100644 --- a/react-components/src/components/Reveal3DResources/queryMappedData.ts +++ b/react-components/src/components/Reveal3DResources/queryMappedData.ts @@ -63,14 +63,8 @@ export async function queryMappedData( const dataView = inspectionResult.items[0]?.inspectionResults.involvedViewsAndContainers?.views[0]; - const nodeData = await filterNodeData(fdmClient, dataNode, dataView); - - if (nodeData === undefined) { - return undefined; - } - return { - data: nodeData, + nodeExternalId: dataNode.externalId, view: dataView, cadNode: selectedNode, intersection: cadIntersection diff --git a/react-components/src/components/Reveal3DResources/types.ts b/react-components/src/components/Reveal3DResources/types.ts index 63d4875a396..563e5600a03 100644 --- a/react-components/src/components/Reveal3DResources/types.ts +++ b/react-components/src/components/Reveal3DResources/types.ts @@ -8,7 +8,7 @@ import { type CadIntersection } from '@cognite/reveal'; import { type Matrix4 } from 'three'; -import { type FdmNode, type Source } from '../../utilities/FdmSDK'; +import { type Source } from '../../utilities/FdmSDK'; import { type Node3D } from '@cognite/sdk/dist/src'; export type AddImageCollection360Options = { @@ -23,7 +23,7 @@ export type AddReveal3DModelOptions = AddModelOptions & { transform?: Matrix4 }; export type TypedReveal3DModel = AddReveal3DModelOptions & { type: SupportedModelTypes | '' }; export type NodeDataResult = { - data: FdmNode; + nodeExternalId: string; view: Source; cadNode: Node3D; intersection: CadIntersection; From b43609d4fa752d733ce17fc7c59ffc0cdd3f9013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Fri, 4 Aug 2023 15:11:30 +0200 Subject: [PATCH 2/4] chore: remove unused function --- .../Reveal3DResources/queryMappedData.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/react-components/src/components/Reveal3DResources/queryMappedData.ts b/react-components/src/components/Reveal3DResources/queryMappedData.ts index ebfb6b58e18..7788b1ef723 100644 --- a/react-components/src/components/Reveal3DResources/queryMappedData.ts +++ b/react-components/src/components/Reveal3DResources/queryMappedData.ts @@ -147,20 +147,3 @@ async function inspectNode( return inspectionResult; } - -async function filterNodeData( - fdmClient: FdmSDK, - dataNode: DmsUniqueIdentifier, - dataView: Source -): Promise | undefined> { - if (dataView === undefined) { - return undefined; - } - - const dataQueryResult = await fdmClient.getByExternalIds( - [{ instanceType: 'node', ...dataNode }], - dataView - ); - - return dataQueryResult.items[0]; -} From 76279801e05896ceac6ceae8d05a95615cdc28ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Fri, 4 Aug 2023 15:11:51 +0200 Subject: [PATCH 3/4] chore: remove unused type parameter --- .../Reveal3DResources/Reveal3DResources.tsx | 16 +++++----------- .../Reveal3DResources/queryMappedData.ts | 8 +++----- .../src/components/Reveal3DResources/types.ts | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx b/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx index abaa0a21a5c..35d9c0a7e6c 100644 --- a/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx +++ b/react-components/src/components/Reveal3DResources/Reveal3DResources.tsx @@ -39,19 +39,19 @@ export type Reveal3DResourcesStyling = { groups?: FdmAssetStylingGroup[]; }; -export type Reveal3DResourcesProps = { +export type Reveal3DResourcesProps = { resources: AddResourceOptions[]; fdmAssetMappingConfig: FdmAssetMappingsConfig; styling?: Reveal3DResourcesStyling; - onNodeClick?: (node: NodeDataResult | undefined) => void; + onNodeClick?: (node: NodeDataResult | undefined) => void; }; -export const Reveal3DResources = ({ +export const Reveal3DResources = ({ resources, styling, fdmAssetMappingConfig, onNodeClick -}: Reveal3DResourcesProps): ReactElement => { +}: Reveal3DResourcesProps): ReactElement => { const [reveal3DModels, setReveal3DModels] = useState([]); const [reveal3DModelsStyling, setReveal3DModelsStyling] = useState< Array @@ -77,13 +77,7 @@ export const Reveal3DResources = ({ const callback = (event: PointerEventData): void => { void (async (event: PointerEventData): Promise => { if (onNodeClick === undefined) return; - const data = await queryMappedData( - viewer, - client, - fdmSdk, - fdmAssetMappingConfig, - event - ); + const data = await queryMappedData(viewer, client, fdmSdk, fdmAssetMappingConfig, event); onNodeClick(data); })(event); diff --git a/react-components/src/components/Reveal3DResources/queryMappedData.ts b/react-components/src/components/Reveal3DResources/queryMappedData.ts index 7788b1ef723..76469429d53 100644 --- a/react-components/src/components/Reveal3DResources/queryMappedData.ts +++ b/react-components/src/components/Reveal3DResources/queryMappedData.ts @@ -8,21 +8,19 @@ import { type EdgeItem, type InspectResultList, type FdmSDK, - type DmsUniqueIdentifier, - type Source, - type FdmNode + type DmsUniqueIdentifier } from '../../utilities/FdmSDK'; import { type FdmAssetMappingsConfig } from '../../hooks/types'; import { type NodeDataResult } from './types'; import assert from 'assert'; -export async function queryMappedData( +export async function queryMappedData( viewer: Cognite3DViewer, cdfClient: CogniteClient, fdmClient: FdmSDK, fdmConfig: FdmAssetMappingsConfig, clickEvent: PointerEventData -): Promise | undefined> { +): Promise { const intersection = await viewer.getIntersectionFromPixel( clickEvent.offsetX, clickEvent.offsetY diff --git a/react-components/src/components/Reveal3DResources/types.ts b/react-components/src/components/Reveal3DResources/types.ts index 563e5600a03..bb30b2a84ce 100644 --- a/react-components/src/components/Reveal3DResources/types.ts +++ b/react-components/src/components/Reveal3DResources/types.ts @@ -22,7 +22,7 @@ export type AddResourceOptions = AddReveal3DModelOptions | AddImageCollection360 export type AddReveal3DModelOptions = AddModelOptions & { transform?: Matrix4 }; export type TypedReveal3DModel = AddReveal3DModelOptions & { type: SupportedModelTypes | '' }; -export type NodeDataResult = { +export type NodeDataResult = { nodeExternalId: string; view: Source; cadNode: Node3D; From 4901c031ab3e06bf7cac3b1c7304c05bf00a7952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Flatval?= Date: Fri, 4 Aug 2023 15:12:04 +0200 Subject: [PATCH 4/4] fix: adhere to new API in story --- react-components/stories/HighlightNode.stories.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/react-components/stories/HighlightNode.stories.tsx b/react-components/stories/HighlightNode.stories.tsx index cbfa8b459a4..e91f3a51d8d 100644 --- a/react-components/stories/HighlightNode.stories.tsx +++ b/react-components/stories/HighlightNode.stories.tsx @@ -60,9 +60,9 @@ const StoryContent = ({ const [highlightedId, setHighlightedId] = useState(undefined); - const callback = (nodeData: NodeDataResult | undefined): void => { - setNodeData(nodeData?.data); - setHighlightedId(nodeData?.data?.externalId); + const callback = (nodeData: NodeDataResult | undefined): void => { + setNodeData(nodeData); + setHighlightedId(nodeData?.nodeExternalId); if (nodeData === undefined) return;