-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-components): color clicked poi instance and bump to 0.73.0 (…
…#4915) * refactor(react-components): move caching into domain object * chore: preliminary lint fix * chore: lint fix some more * chore: remove unwanted changes * chore: make direct reference from render targe to caches * feat(react-components): color clicked instance from POI tool * fix: issue where cad data would sometimes get uncached * feat: add event listener to InstanceStylingController * chore: export InstanceStylingGroup type * chore: return undefined at end of function * feat: set style on assigned instance in PoITool * chore: rename variable * chore: lint fix * chore: remove unnecessary async * chore: correct method name * chore: bump package version * chore: add option to turn off exit button
- Loading branch information
1 parent
5d59392
commit e345cbf
Showing
13 changed files
with
379 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
react-components/src/architecture/base/renderTarget/InstanceStylingController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
|
||
import { remove } from 'lodash'; | ||
import { type InstanceStylingGroup } from '../../../components/Reveal3DResources/types'; | ||
|
||
export class InstanceStylingController { | ||
private readonly _eventHandlers: Array<() => void> = []; | ||
|
||
private readonly _stylingMap = new Map<symbol, InstanceStylingGroup>(); | ||
|
||
setStylingGroup(symbol: symbol, group: InstanceStylingGroup | undefined): void { | ||
if (group === undefined) { | ||
this._stylingMap.delete(symbol); | ||
this.fireChangeEvent(); | ||
return; | ||
} | ||
|
||
this._stylingMap.set(symbol, group); | ||
this.fireChangeEvent(); | ||
} | ||
|
||
getStylingGroups(): Iterable<InstanceStylingGroup> { | ||
return this._stylingMap.values(); | ||
} | ||
|
||
addEventListener(eventHandler: () => void): void { | ||
this._eventHandlers.push(eventHandler); | ||
} | ||
|
||
removeEventListener(eventHandler: () => void): boolean { | ||
return remove(this._eventHandlers, eventHandler).length > 0; | ||
} | ||
|
||
private fireChangeEvent(): void { | ||
this._eventHandlers.forEach((f) => { | ||
f(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
react-components/src/hooks/pointClouds/usePointCloudAnnotationMappingForAssetId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
|
||
import { type UseQueryResult, useQuery } from '@tanstack/react-query'; | ||
import { type PointCloudAnnotationMappedAssetData } from '../types'; | ||
import { EMPTY_ARRAY } from '../../utilities/constants'; | ||
import { type AnyIntersection } from '@cognite/reveal'; | ||
import { queryKeys } from '../../utilities/queryKeys'; | ||
import { usePointCloudAnnotationCache } from '../../components/CacheProvider/CacheProvider'; | ||
import { fetchAnnotationsForModel } from './fetchAnnotationsForModel'; | ||
|
||
export const usePointCloudAnnotationMappingForAssetId = ( | ||
intersection: AnyIntersection | undefined | ||
): UseQueryResult<PointCloudAnnotationMappedAssetData[]> => { | ||
const pointCloudAnnotationCache = usePointCloudAnnotationCache(); | ||
|
||
const isPointCloudIntersection = intersection?.type === 'pointcloud'; | ||
const [modelId, revisionId, assetId] = isPointCloudIntersection | ||
? [ | ||
intersection.model.modelId, | ||
intersection.model.revisionId, | ||
intersection.assetRef?.externalId ?? intersection.assetRef?.id | ||
] | ||
: [undefined, undefined, undefined]; | ||
|
||
return useQuery({ | ||
queryKey: [ | ||
queryKeys.pointCloudAnnotationForAssetId( | ||
`${modelId}/${revisionId}`, | ||
assetId?.toString() ?? '' | ||
) | ||
], | ||
queryFn: async () => { | ||
if (modelId === undefined || revisionId === undefined || assetId === undefined) { | ||
return EMPTY_ARRAY; | ||
} | ||
const result = await fetchAnnotationsForModel( | ||
modelId, | ||
revisionId, | ||
[assetId], | ||
pointCloudAnnotationCache | ||
); | ||
return result ?? EMPTY_ARRAY; | ||
}, | ||
staleTime: Infinity, | ||
enabled: isPointCloudIntersection && assetId !== undefined | ||
}); | ||
}; |
Oops, something went wrong.