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): Move global camera controls to Reveal context #4745

Merged

Conversation

haakonflatval-cognite
Copy link
Contributor

Type of change

Feat

Jira ticket 📘

https://cognitedata.atlassian.net/browse/

Description 📝

This moves the global camera controls to props in RevealContext. Earlier, they would be given to a component that had been created from the withCameraStateControl. This makes it very abritrary where in the code this camera control happens, and can be controlled from multiple places in the same page, which may cause unintended behavior. Now, the controls (a getter and setter) of the camera state are given as props directly to RevealContext, making it more obvious where this global state is controlled. Of course, the user may still mutate the state otherwise (either through the useNavigation hook, direct access to the Reveal camera manager, or just moving the camera with mouse or keyboard), and this will be handled gracefully by the RevealContext (the setter sent to RevealContext will be called in all these cases)

How has this been tested? 🔍

Test instructions ℹ️

Checklist ☑️

  • I am proud of this feature.
  • I have performed a self-review of my own code.
  • I have added PR type (Feat, Bug, Chore, Test, Docs, Style, Refactor) to the PR title.
  • I have manually tested this for different scenarios (different models, formats, devices, browsers).
  • I have commented my code in hard-to-understand areas.
  • I have made corresponding changes to the public documentation.
  • I have added unit and visuals tests to prove that my feature works to the best of my ability.
  • I have refactored the code for readability to the best of my ability.
  • I have checked that my changes do not introduce regressions in the public documentation.
  • I have outlined any known defects / lacking capabilities in the contents of this PR.
  • I have listed any remaining work that should follow this PR in the description or jira/miro/etc.
  • I have added TSDoc to any public facing changes.
  • I have added "developer documentation" in any package README.md that is related / applicable to this PR.
  • I have noted down and am currently tracking any technical debt introduced in this PR.
  • I have thoroughly thought about the architecture of this implementation.
  • I have asked peers to test this feature.

return null;
};

export const useReveal = (): Cognite3DViewer => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in hooks folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, the convention we have been using so far, is that hooks that are sort-of exposing values from a Context, are put together with that Context. That's how this hook was placed before this PR as well, in ViewerContext.ts

*/

import { type MutableRefObject, useEffect, useRef } from 'react';
import { useReveal } from '../../..';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper path!

Copy link
Contributor

@pramodcog pramodcog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice works with the tests!
Minor comments

@haakonflatval-cognite haakonflatval-cognite merged commit bcb8cff into master Sep 9, 2024
14 checks passed
@haakonflatval-cognite haakonflatval-cognite deleted the hflatval/move-camera-control-to-reveal-context branch September 9, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants