Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only 4 requests #3551

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ export type Reveal3DResourcesStyling = {
groups?: FdmAssetStylingGroup[];
};

export type Reveal3DResourcesProps<NodeType = any> = {
export type Reveal3DResourcesProps = {
resources: AddResourceOptions[];
fdmAssetMappingConfig: FdmAssetMappingsConfig;
styling?: Reveal3DResourcesStyling;
onNodeClick?: (node: NodeDataResult<NodeType> | undefined) => void;
onNodeClick?: (node: NodeDataResult | undefined) => void;
};

export const Reveal3DResources = <NodeType = any,>({
export const Reveal3DResources = ({
resources,
styling,
fdmAssetMappingConfig,
onNodeClick
}: Reveal3DResourcesProps<NodeType>): ReactElement => {
}: Reveal3DResourcesProps): ReactElement => {
const [reveal3DModels, setReveal3DModels] = useState<TypedReveal3DModel[]>([]);
const [reveal3DModelsStyling, setReveal3DModelsStyling] = useState<
Array<PointCloudModelStyling | CadModelStyling>
Expand All @@ -77,13 +77,7 @@ export const Reveal3DResources = <NodeType = any,>({
const callback = (event: PointerEventData): void => {
void (async (event: PointerEventData): Promise<void> => {
if (onNodeClick === undefined) return;
const data = await queryMappedData<NodeType>(
viewer,
client,
fdmSdk,
fdmAssetMappingConfig,
event
);
const data = await queryMappedData(viewer, client, fdmSdk, fdmAssetMappingConfig, event);

onNodeClick(data);
})(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeType>(
export async function queryMappedData(
viewer: Cognite3DViewer,
cdfClient: CogniteClient,
fdmClient: FdmSDK,
fdmConfig: FdmAssetMappingsConfig,
clickEvent: PointerEventData
): Promise<NodeDataResult<NodeType> | undefined> {
): Promise<NodeDataResult | undefined> {
const intersection = await viewer.getIntersectionFromPixel(
clickEvent.offsetX,
clickEvent.offsetY
Expand Down Expand Up @@ -63,14 +61,8 @@ export async function queryMappedData<NodeType>(
const dataView =
inspectionResult.items[0]?.inspectionResults.involvedViewsAndContainers?.views[0];

const nodeData = await filterNodeData<NodeType>(fdmClient, dataNode, dataView);

if (nodeData === undefined) {
return undefined;
}

return {
data: nodeData,
nodeExternalId: dataNode.externalId,
view: dataView,
cadNode: selectedNode,
intersection: cadIntersection
Expand Down Expand Up @@ -153,20 +145,3 @@ async function inspectNode(

return inspectionResult;
}

async function filterNodeData<NodeType>(
fdmClient: FdmSDK,
dataNode: DmsUniqueIdentifier,
dataView: Source
): Promise<FdmNode<NodeType> | undefined> {
if (dataView === undefined) {
return undefined;
}

const dataQueryResult = await fdmClient.getByExternalIds<NodeType>(
[{ instanceType: 'node', ...dataNode }],
dataView
);

return dataQueryResult.items[0];
}
6 changes: 3 additions & 3 deletions react-components/src/components/Reveal3DResources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -22,8 +22,8 @@ export type AddResourceOptions = AddReveal3DModelOptions | AddImageCollection360
export type AddReveal3DModelOptions = AddModelOptions & { transform?: Matrix4 };
export type TypedReveal3DModel = AddReveal3DModelOptions & { type: SupportedModelTypes | '' };

export type NodeDataResult<NodeType> = {
data: FdmNode<NodeType>;
export type NodeDataResult = {
nodeExternalId: string;
view: Source;
cadNode: Node3D;
intersection: CadIntersection;
Expand Down
6 changes: 3 additions & 3 deletions react-components/stories/HighlightNode.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const StoryContent = ({

const [highlightedId, setHighlightedId] = useState<string | undefined>(undefined);

const callback = (nodeData: NodeDataResult<any> | undefined): void => {
setNodeData(nodeData?.data);
setHighlightedId(nodeData?.data?.externalId);
const callback = (nodeData: NodeDataResult | undefined): void => {
setNodeData(nodeData);
setHighlightedId(nodeData?.nodeExternalId);

if (nodeData === undefined) return;

Expand Down
Loading