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

looker 3d improvements #4226

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions app/packages/looker-3d/src/action-bar/FullScreenToggler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { fullscreen, fullscreenExit } from "@fiftyone/looker/src/icons";
import * as fos from "@fiftyone/state";
import { IconButton } from "@mui/material";
import { useCallback, useEffect, useRef } from "react";
import { useRecoilState } from "recoil";
import { ActionItem } from "../containers";

const FullScreenIcon = ({ exit }: { exit: boolean }) => {
const ref = useRef<HTMLDivElement>();

useEffect(() => {
if (ref) {
ref.current.innerHTML = "";
ref.current.appendChild(exit ? fullscreenExit : fullscreen);
}
}, [exit]);

return <div style={{ display: "flex" }} ref={ref} />;
Comment on lines +8 to +18
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 3, 2024

Choose a reason for hiding this comment

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

Refactor the FullScreenIcon component to use conditional rendering instead of direct DOM manipulation for better alignment with React best practices.

- const FullScreenIcon = ({ exit }: { exit: boolean }) => {
-   const ref = useRef<HTMLDivElement>();
- 
-   useEffect(() => {
-     if (ref) {
-       ref.current.innerHTML = "";
-       ref.current.appendChild(exit ? fullscreenExit : fullscreen);
-     }
-   }, [exit]);
- 
-   return <div style={{ display: "flex" }} ref={ref} />;
- };
+ const FullScreenIcon = ({ exit }: { exit: boolean }) => (
+   <div style={{ display: "flex" }}>
+     {exit ? fullscreenExit : fullscreen}
+   </div>
+ );

This change eliminates the need for useRef and useEffect for DOM manipulation, leveraging React's declarative nature for UI updates.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const FullScreenIcon = ({ exit }: { exit: boolean }) => {
const ref = useRef<HTMLDivElement>();
useEffect(() => {
if (ref) {
ref.current.innerHTML = "";
ref.current.appendChild(exit ? fullscreenExit : fullscreen);
}
}, [exit]);
return <div style={{ display: "flex" }} ref={ref} />;
const FullScreenIcon = ({ exit }: { exit: boolean }) => (
<div style={{ display: "flex" }}>
{exit ? fullscreenExit : fullscreen}
</div>
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't work

Copy link
Contributor

Choose a reason for hiding this comment

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

@sashankaryal, it seems there was an issue locating the icons.ts file or extracting the implementation details of the fullscreen and fullscreenExit icons using the provided script. This could be due to a variety of reasons, such as the file not existing where expected or the icons being imported from an external library that isn't directly accessible in this manner.

Given this, I'd like to suggest a couple of alternative approaches to address the original concern with the FullScreenIcon component:

  1. Verify Icon Import Method: Ensure that the fullscreen and fullscreenExit icons are imported correctly and can be rendered directly in JSX. If these icons are SVGs or React components, they should be able to be included directly within the JSX return statement without needing to manipulate the DOM.

  2. Alternative Rendering Strategy: If the icons are not directly renderable in JSX (for example, if they are SVG elements stored as strings or files), consider using a method to safely convert them into a format that can be rendered. This could involve using a library or utility function designed for this purpose.

  3. Revisit Original Implementation: If direct DOM manipulation is indeed necessary due to the specific requirements or limitations of how these icons are implemented, it may be worth revisiting the original implementation. In such cases, ensuring that the manipulation is done as safely and efficiently as possible within the React component lifecycle is important.

Without direct access to the implementation details of the icons, these suggestions are based on common practices and potential scenarios. If you have more information about how these icons are implemented or if there's a specific error or issue encountered with the suggested refactor, please let me know, and I can provide further assistance.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Inspect the implementation of the fullscreen and fullscreenExit icons.
fd "icons.ts" app/packages/looker/src --exec cat {}

Length of output: 53

};

export const FullScreenToggler = () => {
const [isFullScreen, setIsFullScreen] = useRecoilState(fos.fullscreen);

const toggleFullScreen = useCallback(() => {
setIsFullScreen((prev) => !prev);
}, []);

return (
<ActionItem title="Toggle Fullscreen">
<IconButton onClick={toggleFullScreen} sx={{ fontSize: 24, padding: 0 }}>
{isFullScreen ? (
<FullScreenIcon exit />
) : (
<FullScreenIcon exit={false} />
)}
</IconButton>
</ActionItem>
);
};
5 changes: 4 additions & 1 deletion app/packages/looker-3d/src/action-bar/ViewHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useHelpPanel } from "@fiftyone/state";
import { ActionItem } from "../containers";
import { ACTION_VIEW_HELP } from "../constants";

const LOOKER3D_HELP_ITEMS = [
export const LOOKER3D_HELP_ITEMS = [
{ shortcut: "Wheel", title: "Zoom", detail: "Zoom in and out" },
{ shortcut: "Drag", title: "Rotate", detail: "Rotate the camera" },
{
Expand All @@ -13,7 +13,10 @@ const LOOKER3D_HELP_ITEMS = [
},
{ shortcut: "T", title: "Top-down", detail: "Reset camera to top-down view" },
{ shortcut: "E", title: "Ego-view", detail: "Reset the camera to ego view" },
{ shortcut: "B", title: "Background", detail: "Toggle background" },
{ shortcut: "C", title: "Controls", detail: "Toggle controls" },
{ shortcut: "G", title: "Grid", detail: "Toggle grid" },
{ shortcut: "F", title: "Full-screen", detail: "Toggle full-screen" },
{ shortcut: "?", title: "Display help", detail: "Display this help window" },
{ shortcut: "ESC", title: "Escape ", detail: "Escape the current context" },
];
Expand Down
6 changes: 5 additions & 1 deletion app/packages/looker-3d/src/action-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { ActionBarContainer, ActionsBar } from "../containers";
import { actionRenderListAtomFamily } from "../state";
import { ChooseColorSpace } from "./ColorSpace";
import { FullScreenToggler } from "./FullScreenToggler";
import { SetPointSizeButton } from "./PointSize";
import { SetViewButton } from "./SetViewButton";
import { SliceSelector } from "./SliceSelector";
Expand Down Expand Up @@ -133,7 +134,10 @@ export const ActionBar = ({
onMouseLeave={onMouseLeave}
>
{isSliceSelectorOn && <SliceSelector />}
<ActionsBar>{componentsToRender}</ActionsBar>
<ActionsBar>
{componentsToRender}
<FullScreenToggler />
</ActionsBar>
</ActionBarContainer>
);
};
6 changes: 3 additions & 3 deletions app/packages/looker-3d/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export const SHADE_BY_CHOICES: { label: string; value: ShadeBy }[] = [
{ label: "None", value: SHADE_BY_NONE },
];

export const PANEL_ORDER_VISIBILITY = 9;
export const PANEL_ORDER_VISIBILITY = -1;
export const PANEL_ORDER_ANIMATIONS = 1;
export const PANEL_ORDER_PCD_CONTROLS = 1;
export const PANEL_ORDER_LIGHTS = 10;
export const PANEL_ORDER_ANIMATIONS = 3;
export const PANEL_ORDER_LIGHTS = 999;
export const PANEL_ORDER_SETTINGS = 1000;

export const COLOR_POOL = [
Expand Down
6 changes: 3 additions & 3 deletions app/packages/looker-3d/src/containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export const Container = styled.div`
justify-content: center;
`;

export const LevaContainer = styled.div`
export const LevaContainer = styled.div<{ isSidebarVisible: boolean }>`
position: absolute;
bottom: 30vh;
left: 2.5vw;
top: 12vh;
right: ${(props) => (props.isSidebarVisible ? "23vw" : "3vw")};
z-index: 1000;
height: 0;
`;
Expand Down
5 changes: 4 additions & 1 deletion app/packages/looker-3d/src/fo3d/Leva.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { useFont, useTheme } from "@fiftyone/components";
import * as fos from "@fiftyone/state";
import { Leva as LevaOptions } from "leva";
import { createPortal } from "react-dom";
import { useRecoilValue } from "recoil";
import { LevaContainer } from "../containers";

function Leva() {
const theme = useTheme();
const font = useFont();
const isSidebarVisible = useRecoilValue(fos.sidebarVisible(true));

return (
<>
{createPortal(
<LevaContainer>
<LevaContainer isSidebarVisible={isSidebarVisible}>
<LevaOptions
theme={{
colors: {
Expand Down
Loading