Skip to content

Commit

Permalink
feat: add more result data for 3d-related nodes (#4134)
Browse files Browse the repository at this point in the history
* feat: add more result data for 3d-related nodes
  • Loading branch information
haakonflatval-cognite authored Jan 26, 2024
1 parent 72a0ab4 commit 2637272
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
8 changes: 6 additions & 2 deletions react-components/src/hooks/use3dRelatedDirectConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { type UseQueryResult, useQuery } from '@tanstack/react-query';
import { useFdmSdk } from '../components/RevealContainer/SDKProvider';
import { type Source, type DmsUniqueIdentifier } from '../utilities/FdmSDK';
import assert from 'assert';
import { type FdmInstanceWithView } from '../utilities/types';

export function use3dRelatedDirectConnections(
instance: DmsUniqueIdentifier | undefined
): UseQueryResult<DmsUniqueIdentifier[]> {
): UseQueryResult<FdmInstanceWithView[]> {
const fdmSdk = useFdmSdk();

return useQuery(
Expand Down Expand Up @@ -72,7 +73,10 @@ export function use3dRelatedDirectConnections(
return Object.keys(propsForView.properties).some((propName) => propName === 'inModel3d');
});

return threeDRelatedViews.map(([index, _view]) => directlyRelatedObjects[index]);
return threeDRelatedViews.map(([index, view]) => ({
...directlyRelatedObjects[index],
view
}));
},
{
enabled: instance !== undefined
Expand Down
35 changes: 24 additions & 11 deletions react-components/src/hooks/use3dRelatedEdgeConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,46 @@

import { type UseQueryResult, useQuery } from '@tanstack/react-query';
import { useFdmSdk } from '../components/RevealContainer/SDKProvider';
import { type QueryResult, type DmsUniqueIdentifier } from '../utilities/FdmSDK';
import { type DmsUniqueIdentifier } from '../utilities/FdmSDK';
import { zipWith } from 'lodash';
import { type FdmInstanceWithView } from '../utilities/types';

export function use3dRelatedEdgeConnections(
fdmId: DmsUniqueIdentifier | undefined
): UseQueryResult<
QueryResult<
Related3dEdgesQueryType & { parameters: { instanceExternalId: string; instanceSpace: string } }
>
> {
): UseQueryResult<FdmInstanceWithView[]> {
const fdmSdk = useFdmSdk();

return useQuery(
['reveal-react-components', 'get-3d-related-edge-connections', fdmId?.externalId, fdmId?.space],
async () =>
await fdmSdk.queryNodesAndEdges({
async () => {
const nodesResult = await fdmSdk.queryNodesAndEdges({
...related3dEdgesQuery,
parameters: {
instanceExternalId: fdmId?.externalId ?? '',
instanceSpace: fdmId?.space ?? ''
}
}),
});

const nodeIds = nodesResult.items.connected_objects_with_3d.map((obj) => ({
instanceType: 'node' as const,
externalId: obj.externalId,
space: obj.space
}));

const views = await fdmSdk.inspectInstances({
inspectionOperations: { involvedViews: {} },
items: nodeIds
});

return zipWith(nodeIds, views.items, (node, view) => ({
...node,
view
}));
},
{ enabled: fdmId !== undefined }
);
}

type Related3dEdgesQueryType = typeof related3dEdgesQuery;

const related3dEdgesQuery = {
with: {
start_instance: {
Expand Down
1 change: 1 addition & 0 deletions react-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type {
} from './components/Reveal3DResources/types';
export type { CameraNavigationActions } from './hooks/useCameraNavigation';
export type { Source, DmsUniqueIdentifier } from './utilities/FdmSDK';
export type { FdmInstanceWithView } from './utilities/types';
export type { QualitySettings } from './components/RevealToolbar/SettingsContainer/types';
export { WindowWidget } from './components/Widgets/WindowWidget';
export { use3dRelatedEdgeConnections } from './hooks/use3dRelatedEdgeConnections';
Expand Down
6 changes: 6 additions & 0 deletions react-components/src/utilities/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*!
* Copyright 2024 Cognite AS
*/
import { type DmsUniqueIdentifier, type Source } from './FdmSDK';

export type FdmInstanceWithView = DmsUniqueIdentifier & Source;
4 changes: 0 additions & 4 deletions yarn.lock

This file was deleted.

0 comments on commit 2637272

Please sign in to comment.