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(react-components): list 360-core-dm-connected assets #4967

Merged
merged 41 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
40fc7ed
fix(react-components): list 360-core-dm-connected assets
haakonflatval-cognite Jan 23, 2025
b3f274a
feat: enable search filtering for 360
haakonflatval-cognite Jan 24, 2025
047ac4c
Merge branch 'master' into hflatval/list-360-coredm-assets
pramod-cog Feb 10, 2025
d46f64e
chore: lint fix in viewer
haakonflatval-cognite Feb 11, 2025
ffa7eac
chore: correct AnnotationAssetRef type
haakonflatval-cognite Feb 11, 2025
6b67834
chore: ignore lint error
haakonflatval-cognite Feb 12, 2025
4b4818d
chore: try to fix build error by upgrading target ES version in tsconfig
haakonflatval-cognite Feb 12, 2025
89bd1e4
Revert "chore: try to fix build error by upgrading target ES version …
haakonflatval-cognite Feb 12, 2025
4f48857
Merge branch 'master' into hflatval/list-360-coredm-assets
haakonflatval-cognite Feb 24, 2025
ace8001
test(react-components): Add tests for listMappedFdmNodes
haakonflatval-cognite Feb 26, 2025
831478f
chore: remove unnecessary results, improve typing
haakonflatval-cognite Feb 26, 2025
002ed54
chore: tests WIP
haakonflatval-cognite Feb 27, 2025
f38c6be
chore: minor changes to filterNodesByMappedTo3d
haakonflatval-cognite Feb 27, 2025
d4a96a7
chore: rename annotations-folder and utilities
haakonflatval-cognite Feb 27, 2025
5cd2736
chore: spurious cleanup, lint and add missing files
haakonflatval-cognite Feb 27, 2025
f98db9c
chore: lint fix again
haakonflatval-cognite Feb 27, 2025
fe2d7d6
chore: lint fix YET AGAIN (not sure why CI get more errors than me)
haakonflatval-cognite Feb 27, 2025
1672d18
test: a few tests for CoreDm3dDataProvider
haakonflatval-cognite Feb 27, 2025
43046bf
chore: move fixtures
haakonflatval-cognite Feb 27, 2025
7d493c5
chore: lint fix
haakonflatval-cognite Feb 27, 2025
0f10579
chore: remove outdated file
haakonflatval-cognite Feb 27, 2025
08e222b
chore: remove a bunch of cyclic dependencies
haakonflatval-cognite Feb 28, 2025
0ab2543
chore: LINT FIXSNTEOHUSNEOTHUSNTOEHUSNTH
haakonflatval-cognite Feb 28, 2025
7ce3cc9
chore: don't initialize mock
haakonflatval-cognite Feb 28, 2025
9ffe9fa
Merge branch 'master' into hflatval/list-360-coredm-assets
pramod-cog Feb 28, 2025
7352db7
chore: import right function...
haakonflatval-cognite Feb 28, 2025
1f09a24
Update react-components/src/data-providers/core-dm-provider/listMappe…
haakonflatval-cognite Mar 3, 2025
e0e42c2
Update react-components/src/utilities/image360Annotations/getImage360…
haakonflatval-cognite Mar 3, 2025
b6be26e
chore: increase type safety
haakonflatval-cognite Mar 4, 2025
9dc0d25
chore: lint fix
haakonflatval-cognite Mar 4, 2025
fc3b1de
chore: avoid as unknown
haakonflatval-cognite Mar 4, 2025
bcd8263
chore: rewrite image360 queries to make life easier for Typescript
haakonflatval-cognite Mar 4, 2025
21acff7
chore: add missing export
haakonflatval-cognite Mar 4, 2025
05cff4c
chore: correct tests etc.
haakonflatval-cognite Mar 4, 2025
0c020b1
chore: lint fix
haakonflatval-cognite Mar 4, 2025
844421d
fix: persist unhoisted properties in return value from search
haakonflatval-cognite Mar 5, 2025
658840e
fix: correct table name in FDM query
haakonflatval-cognite Mar 5, 2025
0f148d7
chore: lint fix
haakonflatval-cognite Mar 5, 2025
36c9cc8
fix: fix typing in hoist function
haakonflatval-cognite Mar 5, 2025
2604205
Merge branch 'master' into hflatval/list-360-coredm-assets
christjt Mar 5, 2025
42e5af0
Merge branch 'master' into hflatval/list-360-coredm-assets
haakonflatval-cognite Mar 5, 2025
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 @@ -35,7 +35,7 @@ export class CdfCaches {
const fdmClient = new FdmSDK(cdfClient);

const fdm3dDataProvider = coreDmOnly
? new CoreDm3dFdm3dDataProvider([], fdmClient)
? new CoreDm3dFdm3dDataProvider(fdmClient)
: new LegacyFdm3dDataProvider(fdmClient, cdfClient);

this._assetMappingAndNode3dCache = new AssetMappingAndNode3DCache(cdfClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RenderTargetCommand } from '../../base/commands/RenderTargetCommand';
import { PointsOfInterestDomainObject } from './PointsOfInterestDomainObject';
import { PointsOfInterestTool } from './PointsOfInterestTool';

export abstract class PointsOfInterestCommand<PoiIdType> extends RenderTargetCommand {
export class PointsOfInterestCommand<PoiIdType> extends RenderTargetCommand {
protected getTool(): PointsOfInterestTool<PoiIdType> | undefined {
return this.getActiveTool(PointsOfInterestTool);
}
Expand Down
15 changes: 1 addition & 14 deletions react-components/src/components/CacheProvider/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ import {
type InstanceReferenceKey
} from '../../utilities/instanceIds/toKey';
import { createFdmKey } from './idAndKeyTranslation';
import { type DmsUniqueIdentifier } from '../../data-providers';

export function getInstanceReferenceFromPointCloudAnnotation(
annotation: AnnotationModel
): IdEither | undefined {
const annotationData = annotation.data as AnnotationsBoundingVolume;
const assetRef = annotationData.assetRef;
return assetRef !== undefined && isIdEither(annotationData.assetRef as IdEither)
? (assetRef as IdEither)
: undefined;
return assetRef !== undefined && isIdEither(assetRef) ? assetRef : undefined;
}

export function getInstanceReferenceFromImage360Annotation(
Expand Down Expand Up @@ -62,16 +59,6 @@ export function getIdKeyForImage360Annotation(
}
}

export function getIdForImage360Annotation(
annotation: DataSourceType['image360AnnotationType']
): DmsUniqueIdentifier | number {
if (isCoreDmImage360Annotation(annotation)) {
return annotation.annotationIdentifier;
} else {
return annotation.id;
}
}

// TODO: Implement this in Reveal instead
function isCoreDmImage360Annotation(
annotation: DataSourceType['image360AnnotationType']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { modelExists } from '../../utilities/modelExists';
import { getViewerResourceCount } from '../../utilities/getViewerResourceCount';
import { type PointCloudModelStyling } from './types';
import { useModelIdRevisionIdFromModelOptions } from '../../hooks/useModelIdRevisionIdFromModelOptions';
import { isClassicIdentifier, isDM3DModelIdentifier } from '../Reveal3DResources/typeGuards';
import { isSameModel } from '../../utilities/isSameModel';
import { isClassicIdentifier, isDMIdentifier } from '../Reveal3DResources/typeGuards';
import { RevealModelsUtils } from '../../architecture/concrete/reveal/RevealModelsUtils';

export type CognitePointCloudModelProps = {
Expand Down Expand Up @@ -141,7 +141,7 @@ function defaultLoadErrorHandler(addOptions: AddModelOptions<DataSourceType>, er
console.warn(
`Failed to load (${addOptions.modelId}, ${addOptions.revisionId}): ${JSON.stringify(error)}`
);
} else if (isDMIdentifier(addOptions)) {
} else if (isDM3DModelIdentifier(addOptions)) {
console.warn(
`Failed to load (${addOptions.revisionExternalId}, ${addOptions.revisionSpace}): ${JSON.stringify(error)}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useCallCallbackOnFinishedLoading } from './hooks/useCallCallbackOnFinis
import { useSetExpectedLoadCount } from './hooks/useSetExpectedLoadCount';
import { useCalculateImage360Styling } from './hooks/useCalculateImage360Styling';
import { CadModelContainer } from '../CadModelContainer';
import { PointCloudContainer } from '../PointCloudContainer';
import { PointCloudContainer } from '../PointCloudContainer/PointCloudContainer';
import { Image360CollectionContainer } from '../Image360CollectionContainer';

export type Reveal3DResourcesDependencies = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { EMPTY_ARRAY } from '../../../utilities/constants';
import { type PointCloudVolumeStylingGroup } from '../../PointCloudContainer/types';
import { useModelIdRevisionIdFromModelOptions } from '../../../hooks/useModelIdRevisionIdFromModelOptions';
import { isDefined } from '../../../utilities/isDefined';
import { use3dModels } from '../../../hooks';
import { use3dModels } from '../../../hooks/use3dModels';
import {
isClassicAssetMappingStylingGroup,
isFdmAssetStylingGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@cognite/reveal';
import { useMemo } from 'react';
import { EMPTY_ARRAY } from '../../../utilities/constants';
import { isDMIdentifier } from '../typeGuards';
import { isDM3DModelIdentifier } from '../typeGuards';

type MatchedPointCloudModel = {
viewerModel: CognitePointCloudModel<DataSourceType>;
Expand All @@ -30,7 +30,7 @@ export function useMatchedPointCloudModels(
}
const model = viewerModel;
const matchedModel = classicModelOptions.find((modelOption) => {
if (isDMPointCloudModel(model) && isDMIdentifier(modelOption)) {
if (isDMPointCloudModel(model) && isDM3DModelIdentifier(modelOption)) {
return (
model.modelIdentifier.revisionExternalId === modelOption.revisionExternalId &&
model.modelIdentifier.revisionSpace === modelOption.revisionSpace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export {
useReveal3DResourcesExpectedInViewerCount,
useReveal3DLoadedResourceCount
} from './Reveal3DResourcesInfoContext';
export { isClassicIdentifier, isDM3DModelIdentifier } from './typeGuards';
22 changes: 11 additions & 11 deletions react-components/src/components/Reveal3DResources/typeGuards.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/*!
* Copyright 2024 Cognite AS
*/
import {
type DMDataSourceType,
type ClassicDataSourceType,
type AddModelOptions
} from '@cognite/reveal';
import { type DMDataSourceType, type AddModelOptions } from '@cognite/reveal';
import {
type AddImage360CollectionEventsOptions,
type AddImage360CollectionDatamodelsOptions,
type AddImage360CollectionOptions,
type AddResourceOptions,
type AddPointCloudResourceOptions
type ClassicAdd3DModelOptions
} from './types';

export function is360ImageAddOptions(
Expand All @@ -24,7 +20,11 @@ export function is360ImageDataModelAddOptions(
addOptions: AddResourceOptions
): addOptions is AddImage360CollectionDatamodelsOptions {
const castOptions = addOptions as AddImage360CollectionDatamodelsOptions;
return castOptions.externalId !== undefined && castOptions.space !== undefined;
return (
castOptions.externalId !== undefined &&
castOptions.space !== undefined &&
(castOptions.source === 'cdm' || castOptions.source === 'dm')
);
}

export function is360ImageEventsAddOptions(
Expand All @@ -36,8 +36,8 @@ export function is360ImageEventsAddOptions(

export function isClassicIdentifier(
addOptions: AddResourceOptions
): addOptions is AddPointCloudResourceOptions & AddModelOptions<ClassicDataSourceType> {
const castOptions = addOptions as AddModelOptions<ClassicDataSourceType>;
): addOptions is ClassicAdd3DModelOptions {
const castOptions = addOptions as ClassicAdd3DModelOptions;
return (
castOptions.modelId !== undefined &&
castOptions.revisionId !== undefined &&
Expand All @@ -46,9 +46,9 @@ export function isClassicIdentifier(
);
}

export function isDMIdentifier(
export function isDM3DModelIdentifier(
addOptions: AddResourceOptions
): addOptions is AddPointCloudResourceOptions & AddModelOptions<DMDataSourceType> {
): addOptions is AddModelOptions<DMDataSourceType> {
const castOptions = addOptions as AddModelOptions<DMDataSourceType>;
return castOptions.revisionExternalId !== undefined && castOptions.revisionSpace !== undefined;
}
13 changes: 9 additions & 4 deletions react-components/src/components/Reveal3DResources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ export type AddResourceOptions =
| AddPointCloudResourceOptions
| AddImage360CollectionOptions;

export type AddPointCloudResourceOptions = AddModelOptions<DataSourceType> & {
transform?: Matrix4;
styling?: { default?: NodeAppearance; mapped?: NodeAppearance };
};
export type AddPointCloudResourceOptions<T extends DataSourceType = DataSourceType> =
AddModelOptions<T> & {
transform?: Matrix4;
styling?: { default?: NodeAppearance; mapped?: NodeAppearance };
};

export type AddCadResourceOptions = AddModelOptions<ClassicDataSourceType> & {
transform?: Matrix4;
Expand All @@ -89,6 +90,10 @@ export type AddCadResourceOptions = AddModelOptions<ClassicDataSourceType> & {
};
};

export type ClassicAdd3DModelOptions =
| AddCadResourceOptions
| AddPointCloudResourceOptions<ClassicDataSourceType>;

export type TypedReveal3DModel = CadModelOptions | PointCloudModelOptions;

export type CadModelOptions = { type: 'cad' } & AddCadResourceOptions;
Expand Down
2 changes: 1 addition & 1 deletion react-components/src/components/i18n/Translator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import { type Translations } from './types';
import { getLanguage } from './utils';
import { type TranslationInput } from '../../architecture';
import {
type TranslationInput,
isTranslatedString,
type TranslationKey
} from '../../architecture/base/utilities/TranslateInput';
Expand Down
11 changes: 7 additions & 4 deletions react-components/src/data-providers/Fdm3dDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
import { type DataSourceType, type AddModelOptions } from '@cognite/reveal';
import { type InstancesWithView } from '../query/useSearchMappedEquipmentFDM';
import { type FdmCadConnection } from '../components/CacheProvider/types';
import { type TaggedAddResourceOptions } from '../components/Reveal3DResources/types';
import {
type AddImage360CollectionDatamodelsOptions,
type TaggedAddResourceOptions
} from '../components/Reveal3DResources/types';
import { type Node3D } from '@cognite/sdk';

export type Fdm3dDataProvider = {
Expand All @@ -28,21 +31,21 @@ export type Fdm3dDataProvider = {
) => Promise<FdmCadConnection[]>;

listMappedFdmNodes: (
models: Array<AddModelOptions<DataSourceType>>,
models: Array<AddModelOptions<DataSourceType> | AddImage360CollectionDatamodelsOptions>,
sourcesToSearch: Source[],
instancesFilter: InstanceFilter | undefined,
limit: number
) => Promise<NodeItem[]>;

listAllMappedFdmNodes: (
models: Array<AddModelOptions<DataSourceType>>,
models: Array<AddModelOptions<DataSourceType> | AddImage360CollectionDatamodelsOptions>,
sourcesToSearch: Source[],
instanceFilter: InstanceFilter | undefined
) => Promise<NodeItem[]>;

filterNodesByMappedTo3d: (
nodes: InstancesWithView[],
models: Array<AddModelOptions<DataSourceType>>,
models: Array<AddModelOptions<DataSourceType> | AddImage360CollectionDatamodelsOptions>,
spacesToSearch: string[]
) => Promise<InstancesWithView[]>;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*!
* Copyright 2025 Cognite AS
*/
import { describe, expect, it, beforeEach } from 'vitest';
import { CoreDm3dFdm3dDataProvider } from './CoreDm3dDataProvider';
import { Mock, It, type IMock } from 'moq.ts';
import { type FdmSDK } from '../FdmSDK';
import { restrictToDmsId } from '../../utilities/restrictToDmsId';
import { type AddImage360CollectionDatamodelsOptions } from '../../components';
import {
modelInstanceFixture0,
revisionInstanceFixture0
} from '../../../tests/tests-utilities/fixtures/dm/model3dData';

const image360CollectionId: AddImage360CollectionDatamodelsOptions = {
externalId: 'image360Collection0',
space: 'space0',
source: 'cdm'
};

const modelId0 = 1234;
const revisionId0 = 5678;

describe(CoreDm3dFdm3dDataProvider.name, () => {
let fdmSdkMock: IMock<FdmSDK>;

beforeEach(() => {
fdmSdkMock = createFdmSdkMock();
});

it('should fetch model ref for classic input model options', async () => {
const coreDmProvider = new CoreDm3dFdm3dDataProvider(fdmSdkMock.object());

const result = await coreDmProvider.getDMSModels(modelId0);

expect(result).toEqual([restrictToDmsId(modelInstanceFixture0)]);
});

it('should fetch revision ref for classic input model options', async () => {
const coreDmProvider = new CoreDm3dFdm3dDataProvider(fdmSdkMock.object());

const result = await coreDmProvider.getRevisionRefs([
{ modelId: modelId0, revisionId: revisionId0 }
]);

expect(result).toEqual([restrictToDmsId(revisionInstanceFixture0)]);
});

it('should return the input ID when input is CoreDM image360 options', async () => {
const coreDmProvider = new CoreDm3dFdm3dDataProvider(fdmSdkMock.object());

const result = await coreDmProvider.getRevisionRefs([image360CollectionId]);

expect(result).toEqual([restrictToDmsId(image360CollectionId)]);
});
});

function createFdmSdkMock(): IMock<FdmSDK> {
return new Mock<FdmSDK>()
.setup(
async (p) =>
await p.queryNodesAndEdges(
It.Is(
(query) =>
(query as any).with?.models?.nodes?.filter?.and?.[0]?.equals?.value ===
`cog_3d_model_${modelId0}`
)
)
)
.returns(Promise.resolve({ items: { models: [modelInstanceFixture0] } }))
.setup(
async (p) =>
await p.queryNodesAndEdges(
It.Is(
(query) =>
(query as any).parameters?.revisionExternalId === `cog_3d_revision_${revisionId0}`
)
)
)
.returns(Promise.resolve({ items: { revision: [revisionInstanceFixture0] } }));
}
Loading
Loading