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

feat(react-components): support newer scene -> 3d-model connection and bump to 0.59.0 #4759

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions react-components/src/hooks/scenes/use3dScenes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
type TRANSFORMATION_SOURCE,
transformationSourceWithProperties
} from './types';
import { tryGetModelIdFromExternalId } from '../../utilities/tryGetModelIdFromExternalId';

export type Space = string;
export type ExternalId = string;
Expand Down Expand Up @@ -173,10 +174,10 @@ function populateSceneMapWithModels(

const properties = Object.values(Object.values(edge.properties)[0])[0];

const newModelId = Number(edge.endNode.externalId);
const newModelId = tryGetModelIdFromExternalId(edge.endNode.externalId);
const newModelRevisionId = Number(properties?.revisionId);

if (isNaN(newModelId) || isNaN(newModelRevisionId)) {
if (newModelId === undefined || isNaN(newModelRevisionId)) {
return;
}

Expand Down
18 changes: 11 additions & 7 deletions react-components/src/hooks/scenes/useSceneConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
type SceneConfigurationProperties,
type TRANSFORMATION_SOURCE
} from './types';
import { tryGetModelIdFromExternalId } from '../../utilities/tryGetModelIdFromExternalId';

const DefaultScene: Scene = {
sceneConfiguration: {
Expand Down Expand Up @@ -140,14 +141,17 @@ function getSceneModels(sceneResponse: SceneResponse): CadOrPointCloudModel[] {
const sceneModels = sceneResponse.items.sceneModels;
sceneModels.forEach((sceneModel) => {
const sceneModelProperties = extractProperties<SceneModelsProperties>(sceneModel.properties);
if (!isNaN(Number(sceneModel.endNode.externalId))) {
const model: CadOrPointCloudModel = {
modelId: Number(sceneModel.endNode.externalId),
...sceneModelProperties
};

models.push(model);
const parsedModelId = tryGetModelIdFromExternalId(sceneModel.endNode.externalId);
if (parsedModelId === undefined) {
throw Error(`Could not parse model Id from externalId ${sceneModel.endNode.externalId}`);
}

const model: CadOrPointCloudModel = {
modelId: parsedModelId,
...sceneModelProperties
};

models.push(model);
});
}
return models;
Expand Down
19 changes: 19 additions & 0 deletions react-components/src/utilities/tryGetModelIdFromExternalId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*!
* Copyright 2024 Cognite AS
*/
import { getModelIdFromExternalId } from '../data-providers/core-dm-provider/getCdfIdFromExternalId';

export function tryGetModelIdFromExternalId(externalId: string): number | undefined {
const legacyModelId = Number(externalId);
if (!isNaN(legacyModelId)) {
return legacyModelId;
}

const coreDmModelId = getModelIdFromExternalId(externalId);

if (!isNaN(coreDmModelId)) {
return coreDmModelId;
}

return undefined;
}
Loading