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 reload_on_navigation for modal panels #4846

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

sashankaryal
Copy link
Contributor

@sashankaryal sashankaryal commented Sep 25, 2024

Makes it possible to force remounting of panels when navigating between samples

Summary by CodeRabbit

  • New Features

    • Introduced a configurable reloadOnNavigation option for panel behavior during navigation.
    • Added support for displaying help content in the panel's tooltip via a new help_markdown parameter.
  • Bug Fixes

    • Enhanced safety in accessing group IDs to prevent errors when retrieving modal information.
  • Documentation

    • Updated documentation to reflect new parameters and their usage in the panel configuration.

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes introduce a new reloadOnNavigation property to various components and functions related to panel behavior in the application. This property allows for configurable panel reloading during navigation events, enhancing the flexibility of how panels react to user interactions. The updates span multiple files, including TypeScript and Python, affecting both the front-end and back-end implementations.

Changes

File Path Change Summary
app/packages/operators/src/Panel/register.tsx Added reloadOnNavigation property to panelOptions in registerPanel function, configurable based on execution context parameters.
app/packages/plugins/src/index.ts Introduced optional reloadOnNavigation property in PanelOptions type, indicating remount behavior for modal plugins during navigation.
app/packages/spaces/src/components/Panel.tsx Updated panel component to utilize useRecoilValue for modal unique ID, modified rendering logic based on modal status and reloadOnNavigation. Added variables for state management.
app/packages/state/src/recoil/groups.ts Modified groupId selector to use optional chaining for safer access to modalSelector.
fiftyone/operators/operations.py Added reload_on_navigation parameter to register_panel function, allowing control over panel reloading on navigation, with updated documentation.
fiftyone/operators/panel.py Updated PanelConfig class to include reload_on_navigation and help_markdown parameters, modifying the constructor and related methods to accommodate these changes.

Possibly related PRs

  • fix modal navigation bug #4803: The changes in this PR involve enhancements to modal navigation, which relates to the new reloadOnNavigation property introduced in the main PR, as both involve handling navigation behavior in panel contexts.

Suggested reviewers

  • imanjra

Poem

🐇 In the land of panels, so bright and new,
A reloadOnNavigation is here for you!
With each little hop, and every sweet turn,
The panels will dance, and the users will learn.
So let’s celebrate change, with a joyful cheer,
For navigation’s magic is finally here! ✨


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.

@sashankaryal sashankaryal self-assigned this Sep 25, 2024
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: 0

🧹 Outside diff range and nitpick comments (4)
fiftyone/operators/panel.py (2)

49-49: LGTM: New parameter added correctly.

The reload_on_navigation parameter has been added to the constructor with a default value of False, which is good for backward compatibility.

Consider adding type hinting for the reload_on_navigation parameter:

-    reload_on_navigation=False,
+    reload_on_navigation: bool = False,

This would improve code readability and help with static type checking.


77-77: LGTM: Consistent updates to serialization and startup configuration.

The reload_on_navigation parameter has been correctly added to both the to_json method of PanelConfig and the panel_config dictionary in the on_startup method of Panel. This ensures that the new configuration option is properly serialized and passed to the panel during startup.

Consider adding a comment in the on_startup method to explain the purpose of the reload_on_navigation option:

# Add reload_on_navigation to allow dynamic reloading of non-modal panels
"reload_on_navigation": self.config.reload_on_navigation,

This would help other developers understand the purpose of this configuration option.

Also applies to: 117-117

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

328-333: LGTM! Consider enhancing the documentation slightly.

The addition of the reloadOnNavigation property is well-implemented and properly documented. It's an optional boolean property that allows for more dynamic behavior of modal plugins.

Consider slightly expanding the documentation to provide more context:

/**
 * If true, the plugin will be remounted when the user navigates to a different sample or group.
 * This is only applicable to plugins that are displayed in a modal.
 * Use this when the plugin needs to reset its state or re-fetch data on navigation.
 */
reloadOnNavigation?: boolean;

This additional information helps developers understand when they might want to use this property.

fiftyone/operators/operations.py (1)

308-308: LGTM! Consider a minor docstring improvement.

The implementation of the new reload_on_navigation parameter looks good. It's correctly added to the method signature and the params dictionary, with a sensible default value of False to maintain backward compatibility.

The docstring provides clear information about the parameter's purpose and limitations. However, to enhance clarity, consider slightly rewording the docstring:

-            reload_on_navigation (False): whether to reload the panel when the
-                user navigates to a new page. This is only applicable to panels
-                that are not shown in a modal
+            reload_on_navigation (False): whether to reload the panel when the
+                user navigates between samples. This is only applicable to panels
+                that are not displayed in a modal

This minor change aligns the docstring more closely with the PR description, which mentions navigation between samples rather than pages.

Also applies to: 335-337, 367-367

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4845d52 and 02ba861.

📒 Files selected for processing (6)
  • app/packages/operators/src/Panel/register.tsx (1 hunks)
  • app/packages/plugins/src/index.ts (1 hunks)
  • app/packages/spaces/src/components/Panel.tsx (4 hunks)
  • app/packages/state/src/recoil/groups.ts (1 hunks)
  • fiftyone/operators/operations.py (3 hunks)
  • fiftyone/operators/panel.py (5 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
app/packages/operators/src/Panel/register.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/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.

app/packages/state/src/recoil/groups.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.

🔇 Additional comments not posted (10)
app/packages/operators/src/Panel/register.tsx (1)

26-26: LGTM! The change aligns well with the PR objectives.

The addition of the reloadOnNavigation property to panelOptions is a well-implemented feature that directly addresses the PR's goal of allowing forced remounting of modal panels during navigation between samples. The implementation is clean, focused, and uses the execution context appropriately.

fiftyone/operators/panel.py (3)

31-36: LGTM: Clear and concise documentation for new parameters.

The additions to the class docstring for PanelConfig are well-written and accurately describe the new reload_on_navigation and help_markdown parameters. This documentation will help developers understand the purpose and usage of these new features.


62-62: LGTM: Attribute correctly set in the initializer.

The self.reload_on_navigation attribute is properly set to the value of the reload_on_navigation parameter in the __init__ method. This ensures that the new configuration option is stored in the instance.


Line range hint 31-117: Summary: Well-implemented feature for panel reloading on navigation.

The changes introduce a new reload_on_navigation option for panel configurations. This feature allows non-modal panels to be reloaded when the user navigates to a new page, potentially improving the user experience by ensuring that panel content stays up-to-date.

Key points:

  1. The feature is well-documented in the class docstring.
  2. The implementation is consistent across the PanelConfig and Panel classes.
  3. The changes maintain backward compatibility with existing code.

Overall, this is a solid implementation that enhances the flexibility of the panel system. Good job!

app/packages/state/src/recoil/groups.ts (1)

392-392: Approve the change with a suggestion for further investigation.

The introduction of optional chaining (?.) is a good improvement. It makes the code more robust by safely handling cases where get(modalSelector) might return null or undefined.

However, it would be beneficial to investigate why modalSelector could potentially return null or undefined. This change suggests a possible edge case that wasn't handled before. Consider adding a comment explaining this scenario or updating the modalSelector documentation if necessary.

To verify the modalSelector implementation and its potential to return null or undefined, you can run the following script:

This script will help us understand the implementation of modalSelector and how it's used throughout the codebase, which could provide insights into scenarios where it might return null or undefined.

✅ Verification successful

Verified: Optional chaining in groupId selector is appropriate

The modalSelector can indeed return null, making the use of optional chaining (?.) in the groupId selector correct and necessary to prevent potential runtime errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Investigate the implementation of modalSelector

# Search for the modalSelector definition
echo "modalSelector definition:"
rg --type typescript "const\s+modalSelector\s*=\s*selector" -A 10

# Search for places where modalSelector is used
echo "\nUsages of modalSelector:"
rg --type typescript "modalSelector" -C 2

Length of output: 303


Script:

#!/bin/bash
# Description: Investigate the implementation of modalSelector

# Search for the modalSelector definition
echo "modalSelector definition:"
rg "const\s+modalSelector\s*=\s*selector" --glob "*.ts" --glob "*.tsx" -A 10

# Search for places where modalSelector is used
echo "\nUsages of modalSelector:"
rg "modalSelector" --glob "*.ts" --glob "*.tsx" -C 2

Length of output: 15716


Script:

#!/bin/bash
# Description: Investigate the implementation of modalSelector

# Search for the modalSelector definition
echo "modalSelector definition:"
rg "const\s+modalSelector\s*=\s*sessionAtom" --glob "*.ts" --glob "*.tsx" -A 10

# Search for places where modalSelector is used
echo "\nUsages of modalSelector:"
rg "modalSelector" --glob "*.ts" --glob "*.tsx" -C 2

Length of output: 16396

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

328-333: Verify the impact on existing plugins and usage.

The addition of the reloadOnNavigation property is well-isolated and shouldn't break existing functionality. However, it's important to ensure that this new feature is properly integrated into the plugin system.

To verify the integration and usage of this new property, please run the following checks:

These checks will help ensure that the new property is properly integrated and identify any areas that might need additional attention.

✅ Verification successful

Impact of adding reloadOnNavigation on existing plugins and usage verified.

No issues found. The new property is properly integrated and does not break existing functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing usage of reloadOnNavigation and verify plugin system integration

# Check for any existing usage of reloadOnNavigation in the codebase
echo "Checking for existing usage of reloadOnNavigation:"
rg --type typescript 'reloadOnNavigation'

# Check the plugin system implementation for handling of this new property
echo "Checking plugin system implementation:"
rg --type typescript 'reloadOnNavigation' app/packages/plugins/src

# Verify if there are any TODOs or FIXMEs related to this feature
echo "Checking for related TODOs or FIXMEs:"
rg --type typescript -e 'TODO.*reload' -e 'FIXME.*reload' app/packages/plugins/src

Length of output: 581


Script:

#!/bin/bash
# Description: Check for existing usage of reloadOnNavigation and verify plugin system integration by searching .ts and .tsx files

# Check for any existing usage of reloadOnNavigation in the codebase
echo "Checking for existing usage of reloadOnNavigation in .ts and .tsx files:"
rg 'reloadOnNavigation' --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx

# Check the plugin system implementation for handling of this new property
echo "Checking plugin system implementation for reloadOnNavigation in app/packages/plugins/src:"
rg 'reloadOnNavigation' --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx app/packages/plugins/src

# Verify if there are any TODOs or FIXMEs related to this feature
echo "Checking for related TODOs or FIXMEs in .ts and .tsx files within app/packages/plugins/src:"
rg -e 'TODO.*reload' -e 'FIXME.*reload' --type-add 'ts=*.ts' --type-add 'tsx=*.tsx' -t ts -t tsx app/packages/plugins/src

Length of output: 1027


Script:

#!/bin/bash
# Description: Check for existing usage of reloadOnNavigation and verify plugin system integration by searching .ts and .tsx files

# Check for any existing usage of reloadOnNavigation in .ts and .tsx files
echo "Checking for existing usage of reloadOnNavigation in .ts and .tsx files:"
rg 'reloadOnNavigation' -g '*.ts' -g '*.tsx'

# Check the plugin system implementation for handling of this new property
echo "Checking plugin system implementation for reloadOnNavigation in app/packages/plugins/src:"
rg 'reloadOnNavigation' -g '*.ts' -g '*.tsx' app/packages/plugins/src

# Verify if there are any TODOs or FIXMEs related to this feature
echo "Checking for related TODOs or FIXMEs in .ts and .tsx files within app/packages/plugins/src:"
rg -e 'TODO.*reload' -e 'FIXME.*reload' -g '*.ts' -g '*.tsx' app/packages/plugins/src

Length of output: 1100

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

23-24: Approved: Correct retrieval of thisModalUniqueId

The thisModalUniqueId is properly obtained using useRecoilValue, ensuring that the component responds to changes in the current modal's unique ID.


45-47: Approved: Proper destructuring of panel to include panelOptions

Including panelOptions in the destructuring of panel allows for conditional logic based on the panel's options, such as reloadOnNavigation.


47-47: Approved: Correctly determining if the component should be re-keyed

The shouldKeyComponent variable accurately reflects whether the component should force a remount based on isModalPanel and panelOptions?.reloadOnNavigation.


58-62: Approved: Proper use of the key prop to control component remounting

Using the key prop with the value {shouldKeyComponent ? thisModalUniqueId : panelName} effectively forces the component to remount when necessary, aligning with the PR's objective to reload modal panels on navigation.

@ritch ritch merged commit a84d41e into develop Sep 25, 2024
13 checks passed
@ritch ritch deleted the enhancement/support-panel-rerender-on-navigation branch September 25, 2024 22:47
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