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

add modal context to panel and operator views & fix zIndex of ArrowNavView #5052

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Nov 6, 2024

What changes are proposed in this pull request?

  • add modal context to panel and operator views
    • Available in panel at props.isModalPanel
    • Available in operator view at props.otherProps.isModalPanel
  • fix zIndex of ArrowNavView

How is this patch tested? If it is not, please explain why.

Using ArrowNavView

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

See above

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Introduced isModalPanel property to various components, enhancing modal state management.
    • Added otherProps to components for greater flexibility in passing additional properties.
  • Bug Fixes

    • Improved styling logic for navigation arrows based on modal state.
  • Refactor

    • Updated method signatures across multiple components to include new properties, maintaining existing functionality.
  • Chores

    • Enhanced type definitions for better flexibility in component props.

Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes introduce a new parameter otherProps to the OperatorIOComponent and related components, allowing them to accept additional properties. This modification enhances the flexibility of the components by enabling the forwarding of extra props to child components like SchemaIOComponent. Furthermore, the isModalPanel property is added to several components, allowing them to manage modal behavior more effectively. The overall structure and functionality of the components remain unchanged, with no alterations to existing error handling or core logic.

Changes

File Path Change Summary
app/packages/core/src/plugins/OperatorIO/index.tsx Added ...otherProps to OperatorIOComponent for passing additional properties.
app/packages/core/src/plugins/SchemaIO/components/ArrowNavView.tsx Included otherProps in ArrowNavView, allowing extraction of isModalPanel for zIndex control. Updated styles for navigation arrows.
app/packages/core/src/plugins/SchemaIO/utils/types.ts Added otherProps: { [key: string]: any } to ViewPropsType for flexibility in props.
app/packages/operators/src/CustomPanel.tsx Added isModalPanel to CustomPanel props and updated defineCustomPanel to handle modal states.
app/packages/operators/src/useCustomPanelHooks.ts Introduced isModalPanel?: boolean to CustomPanelProps for managing modal behavior.
app/packages/plugins/src/index.ts Added isModalPanel?: boolean to PluginComponentProps type for modal panel specification.
app/packages/spaces/src/components/Panel.tsx Included isModalPanel in Panel component props for better data flow to child components.

Possibly related PRs

Suggested labels

feature, plugins, app

Suggested reviewers

  • ritch
  • benjaminpkane

Poem

🐰 In the meadow where changes bloom,
New props sprout, dispelling gloom.
Modal panels dance with grace,
Flexibility finds its place.
With every click, a new delight,
Our components shine, oh what a sight! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (10)
app/packages/core/src/plugins/OperatorIO/index.tsx (2)

Line range hint 6-20: Add TypeScript type definitions for better type safety.

Since this is a TypeScript file, the component and its props should be properly typed. This will provide better type safety and documentation.

+interface OperatorIOProps {
+  schema: any; // Replace 'any' with actual schema type
+  onChange: (data: any) => void;
+  type: 'input' | 'output';
+  data: any;
+  errors?: any;
+  layout?: any;
+  onPathChange?: (path: string) => void;
+  initialData?: any;
+  id: string;
+  shouldClearUseKeyStores?: boolean;
+  isModalPanel?: boolean;
+  [key: string]: any;
+}

-function OperatorIOComponent(props) {
+function OperatorIOComponent(props: OperatorIOProps) {

Line range hint 23-34: LGTM! Consider destructuring otherProps for clarity.

The implementation correctly forwards additional props to SchemaIOComponent, which aligns with the PR's objective of supporting modal context. However, for better clarity, consider destructuring the specific props you're interested in.

-      otherProps={otherProps}
+      otherProps={{ isModalPanel: otherProps.isModalPanel, ...otherProps }}
app/packages/core/src/plugins/SchemaIO/utils/types.ts (1)

66-66: Add JSDoc documentation for the otherProps property.

Similar to how other experimental features are documented (like relativeLayout), please add JSDoc comments explaining the purpose and usage of otherProps, particularly mentioning its role in modal context handling.

+  /**
+   * Additional properties passed to the view component.
+   * Currently used for modal context via isModalPanel.
+   */
   otherProps: { [key: string]: any };
app/packages/spaces/src/components/Panel.tsx (3)

Line range hint 15-17: Update TypeScript type definitions for proper type safety

The isModalPanel prop is being destructured but isn't properly typed in the component's props interface. This could lead to type-checking issues.

Update the type definition:

- function Panel(props: PanelProps) {
+ function Panel(props: PanelProps & { isModalPanel?: boolean }) {

Line range hint 41-62: Add JSDoc comments to document modal behavior

The modal-specific logic is well-implemented, but adding documentation would improve maintainability and developer experience.

Add JSDoc comments to explain the modal behavior:

+ /**
+  * Renders the panel content with modal context support.
+  * When isModalPanel is true:
+  * - Component is re-mounted on navigation if panelOptions.reloadOnNavigation is true
+  * - Specific modal styling is applied
+  * @param {boolean} isModalPanel - Whether the panel is rendered in a modal context
+  */
  return (
    <StyledPanel
      $isModalPanel={isModalPanel}

Line range hint 69-71: Enhance React.memo comparison function

The current memo comparison only checks node.id, but isModalPanel also affects rendering. This could lead to unnecessary re-renders.

Update the memo comparison:

export default React.memo(Panel, (prevProps, nextProps) => {
-  return prevProps?.node?.id === nextProps?.node?.id;
+  return prevProps?.node?.id === nextProps?.node?.id && 
+         prevProps?.isModalPanel === nextProps?.isModalPanel;
});
app/packages/core/src/plugins/SchemaIO/components/ArrowNavView.tsx (1)

23-24: Optimize style composition with useMemo.

The style objects are being recreated on every render. Consider memoizing the computed styles for better performance.

Apply this optimization:

+import { useMemo } from 'react';
+
 export default function ArrowNavView(props: ArrowNavViewProps) {
   // ...
-  const backwardStyles = positionBasedStyleBackward[position] || {};
-  const forwardStyles = positionBasedStyleForward[position] || {};
+  const { backwardStyles, forwardStyles } = useMemo(() => ({
+    backwardStyles: {
+      ...(positionBasedStyleBackward[position] || {}),
+      zIndex
+    },
+    forwardStyles: {
+      ...(positionBasedStyleForward[position] || {}),
+      zIndex
+    }
+  }), [position, zIndex]);

   return (
     <>
       {backward && (
         <Arrow
-          style={{ ...backwardStyles, zIndex }}
+          style={backwardStyles}
           // ...
         />
       )}
       {forward && (
         <Arrow
           $isRight
-          style={{ ...forwardStyles, zIndex }}
+          style={forwardStyles}
           // ...
         />
       )}
     </>
   );

Also applies to: 32-32, 45-45

app/packages/operators/src/CustomPanel.tsx (2)

19-19: Consider adding runtime type validation for isModalPanel prop.

While the TypeScript interface ensures type safety at compile time, consider adding runtime validation for the isModalPanel prop to prevent potential issues with undefined or non-boolean values.

-  const { panelId, dimensions, panelName, panelLabel, isModalPanel } = props;
+  const { panelId, dimensions, panelName, panelLabel, isModalPanel = false } = props;

126-149: Add JSDoc documentation for the isModalPanel prop.

The implementation looks good, but consider adding documentation to explain the purpose and usage of the isModalPanel prop for better maintainability.

 export function defineCustomPanel({
   on_load,
   on_change,
   on_unload,
   on_change_ctx,
   on_change_view,
   on_change_dataset,
   on_change_current_sample,
   on_change_selected,
   on_change_selected_labels,
   on_change_extended_selection,
   on_change_group_slice,
   on_change_spaces,
   panel_name,
   panel_label,
 }) {
+  /**
+   * @param props - Component props
+   * @param props.isModalPanel - Indicates if the panel is rendered in a modal context
+   * @returns React component with modal context awareness
+   */
   return (props) => {
app/packages/plugins/src/index.ts (1)

385-385: LGTM! Consider adding JSDoc documentation.

The addition of the optional isModalPanel property to PluginComponentProps is well-typed and backward compatible. However, adding JSDoc documentation would help developers understand its purpose and usage.

Consider adding documentation like this:

type PluginComponentProps<T> = T & {
  panelNode?: unknown;
  dimensions?: unknown;
+ /** Indicates whether the component is rendered within a modal panel */
  isModalPanel?: boolean;
};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4e4bb1a and ab8a832.

📒 Files selected for processing (7)
  • app/packages/core/src/plugins/OperatorIO/index.tsx (2 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/ArrowNavView.tsx (3 hunks)
  • app/packages/core/src/plugins/SchemaIO/utils/types.ts (1 hunks)
  • app/packages/operators/src/CustomPanel.tsx (3 hunks)
  • app/packages/operators/src/useCustomPanelHooks.ts (1 hunks)
  • app/packages/plugins/src/index.ts (1 hunks)
  • app/packages/spaces/src/components/Panel.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
app/packages/core/src/plugins/OperatorIO/index.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/plugins/SchemaIO/components/ArrowNavView.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/plugins/SchemaIO/utils/types.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/operators/src/CustomPanel.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/operators/src/useCustomPanelHooks.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/plugins/src/index.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/spaces/src/components/Panel.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (5)
app/packages/spaces/src/components/Panel.tsx (1)

61-63: LGTM: Clean prop forwarding implementation

The explicit forwarding of isModalPanel to the child component follows React best practices and maintains clear data flow.

app/packages/core/src/plugins/SchemaIO/components/ArrowNavView.tsx (1)

25-26: Verify zIndex values don't conflict with other components.

The zIndex values (1000 and 1501) should be checked against other components to ensure proper layering in the application.

app/packages/operators/src/CustomPanel.tsx (1)

92-92: LGTM! Prop forwarding implemented correctly.

The isModalPanel prop is properly passed down to the OperatorIO component, following React's props drilling pattern.

app/packages/operators/src/useCustomPanelHooks.ts (2)

34-34: LGTM: Clean interface extension.

The addition of the optional isModalPanel property is well-typed and maintains backward compatibility.


34-34: Add documentation and verify modal-specific behavior.

The isModalPanel property is added but:

  1. Its purpose and usage are not documented
  2. It might need special handling in modal contexts

Consider:

  • Adding JSDoc comments explaining the property's purpose and expected behavior
  • Verifying if modal panels require specific state management or event handling

Let's verify the property's usage across the codebase:

✅ Verification successful

Let me try a different search strategy to verify the usage of this property.


The isModalPanel property is correctly used and serves a clear purpose

The property is actively used throughout the codebase to:

  • Control z-index values for proper modal layering (ArrowNavView.tsx)
  • Determine panel scope and reload behavior (Panel.tsx)
  • Apply modal-specific styling via styled components
  • Handle modal-specific state management

Key usages found in:

  • app/packages/core/src/plugins/SchemaIO/components/ArrowNavView.tsx: Controls z-index layering
  • app/packages/spaces/src/components/Panel.tsx: Manages modal-specific panel behavior and styling
  • app/packages/operators/src/CustomPanel.tsx: Propagates the modal state to child components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how isModalPanel is used across the codebase

# Search for isModalPanel usage
echo "Searching for isModalPanel usage..."
rg "isModalPanel" -t ts -t tsx

# Search for modal-related panel components
echo "Searching for modal-related panel components..."
ast-grep --pattern 'interface $_ extends CustomPanelProps {
  $$$
}'

Length of output: 315


Script:

#!/bin/bash
# Search for isModalPanel with ripgrep including TypeScript files
echo "Searching for isModalPanel in TypeScript files..."
rg "isModalPanel" --type-add 'ts:*.{ts,tsx}' -t ts

# Search for modal-related components and interfaces
echo "Searching for modal and panel related components..."
rg "Modal.*Panel|Panel.*Modal" --type-add 'ts:*.{ts,tsx}' -t ts -A 3

# Look for CustomPanel related interfaces and types
echo "Searching for CustomPanel related types..."
rg "CustomPanel" --type-add 'ts:*.{ts,tsx}' -t ts -A 3

Length of output: 16596

@@ -63,6 +63,7 @@ export type ViewPropsType<Schema extends SchemaType = SchemaType> = {
ROWS: number;
};
autoFocused?: React.MutableRefObject<boolean>;
otherProps: { [key: string]: any };
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using a more specific type for otherProps.

Instead of using a loose index signature with any, consider creating a specific interface for the known additional properties. This will provide better type safety and IDE support.

-  otherProps: { [key: string]: any };
+  otherProps: {
+    isModalPanel?: boolean;
+    // Add other known properties here
+  };

Committable suggestion skipped: line range outside the PR's diff.

@@ -9,7 +9,7 @@ import React from "react";
import { ViewPropsType } from "../utils/types";

export default function ArrowNavView(props: ViewPropsType) {
const { schema } = props;
const { schema, otherProps } = props;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update type definitions for better type safety.

The component's props type definition doesn't match its usage. The otherProps is implicitly typed as any, which bypasses TypeScript's type checking benefits.

Apply this diff to improve type safety:

-export default function ArrowNavView(props: ViewPropsType) {
+interface ArrowNavViewProps extends ViewPropsType {
+  otherProps: {
+    isModalPanel?: boolean;
+  };
+}
+
+export default function ArrowNavView(props: ArrowNavViewProps) {

Also, consider extracting the zIndex values as named constants:

+const Z_INDEX = {
+  DEFAULT: 1000,
+  MODAL: 1501,
+} as const;
+
 export default function ArrowNavView(props: ArrowNavViewProps) {
   // ...
-  const zIndex = isModalPanel ? 1501 : 1000;
+  const zIndex = isModalPanel ? Z_INDEX.MODAL : Z_INDEX.DEFAULT;

Also applies to: 25-26

@imanjra imanjra requested a review from a team November 6, 2024 18:31
Copy link
Contributor

@Br2850 Br2850 left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏽

@imanjra imanjra merged commit 3331aa0 into develop Nov 6, 2024
11 checks passed
@imanjra imanjra deleted the bugfix/arrow-nav-zindex branch November 6, 2024 18:42
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