Skip to content

Commit

Permalink
Merge branch 'pramodcog/fix-layer-button-component' of https://github…
Browse files Browse the repository at this point in the history
….com/cognitedata/reveal into pramodcog/fix-layer-button-component
  • Loading branch information
pramodcog committed Aug 2, 2023
2 parents 852edb8 + 00fe94b commit 39c6de7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type Reveal3DResourcesProps<NodeType = any> = {
resources: AddResourceOptions[];
fdmAssetMappingConfig: FdmAssetMappingsConfig;
styling?: Reveal3DResourcesStyling;
onNodeClick?: (node: NodeDataResult<NodeType>) => void;
onNodeClick?: (node: NodeDataResult<NodeType> | undefined) => void;
};

export const Reveal3DResources = <NodeType = any,>({
Expand Down Expand Up @@ -76,16 +76,16 @@ export const Reveal3DResources = <NodeType = any,>({
useEffect(() => {
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
);
if (onNodeClick !== undefined && data !== undefined) {
onNodeClick?.(data);
}

onNodeClick(data);
})(event);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function queryMappedData<NodeType>(
data: nodeData,
view: dataView,
cadNode: selectedNode,
model: cadIntersection.model
intersection: cadIntersection
};
}

Expand Down
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 @@ -3,9 +3,9 @@
*/

import {
type CogniteCadModel,
type AddModelOptions,
type SupportedModelTypes
type SupportedModelTypes,
type CadIntersection
} from '@cognite/reveal';
import { type Matrix4 } from 'three';
import { type FdmNode, type Source } from '../../utilities/FdmSDK';
Expand All @@ -26,5 +26,5 @@ export type NodeDataResult<NodeType> = {
data: FdmNode<NodeType>;
view: Source;
cadNode: Node3D;
model: CogniteCadModel;
intersection: CadIntersection;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ export type ViewerAnchorElementMapping = {
export type ViewerAnchorProps = {
position: Vector3;
children: ReactElement;
uniqueKey: string;
};

export const ViewerAnchor = ({
position,
children,
uniqueKey
}: ViewerAnchorProps): ReactElement => {
export const ViewerAnchor = ({ position, children }: ViewerAnchorProps): ReactElement => {
const viewer = useReveal();
const [divTranslation, setDivTranslation] = useState(new Vector2());
const [visible, setVisible] = useState(false);
Expand Down Expand Up @@ -50,7 +45,6 @@ export const ViewerAnchor = ({

return visible ? (
<div
key={uniqueKey}
ref={htmlRef}
style={{
position: 'absolute',
Expand Down
16 changes: 9 additions & 7 deletions react-components/stories/HighlightNode.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ const StoryContent = ({
resources: AddResourceOptions[];
fdmAssetMappingConfig: FdmAssetMappingsConfig;
}): ReactElement => {
const [nodeData, setNodeData] = useState<any>();
const [nodeData, setNodeData] = useState<any>(undefined);

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

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

setHighlightedId(nodeData.data.externalId);
nodeData.model.assignStyledNodeCollection(
if (nodeData === undefined) return;

nodeData.intersection.model.assignStyledNodeCollection(
new TreeIndexNodeCollection([nodeData.cadNode.treeIndex]),
DefaultNodeAppearance.Highlighted
);
Expand All @@ -86,7 +88,7 @@ const StoryContent = ({
resources={resources}
styling={{
groups:
highlightedId.length === 0
highlightedId === undefined
? undefined
: [
{
Expand Down
4 changes: 2 additions & 2 deletions react-components/stories/ViewerAnchor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Main: Story = {
styling={styling}
fdmAssetMappingConfig={fdmAssetMappingConfig}
/>
<ViewerAnchor position={position} uniqueKey="key2">
<ViewerAnchor position={position}>
<p
style={{
backgroundColor: 'turquoise',
Expand All @@ -62,7 +62,7 @@ export const Main: Story = {
This label is stuck at position {position.toArray().join(',')}
</p>
</ViewerAnchor>
<ViewerAnchor position={position2} uniqueKey="key1">
<ViewerAnchor position={position2}>
<p
style={{
backgroundColor: 'red',
Expand Down

0 comments on commit 39c6de7

Please sign in to comment.