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 support for tooltip overwrite #5351

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

minhtuev
Copy link
Contributor

@minhtuev minhtuev commented Jan 7, 2025

What changes are proposed in this pull request?

Allowed users to easily overwrite tooltips in TableView and updated tests

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

  • Local testing

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.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

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 a required value parameter for tooltips, enhancing tooltip functionality.
    • Updated add_tooltip method in TableView to include an overwrite parameter for managing existing tooltips.
  • Bug Fixes

    • Improved error handling for tooltip management when attempting to overwrite existing tooltips.
    • Enhanced validation for tooltip updates, ensuring correct behavior based on the overwrite parameter.

@minhtuev minhtuev requested a review from imanjra January 7, 2025 01:54
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request introduces significant changes to the Tooltip and TableView classes. A new required value parameter has been added to the Tooltip constructor, and the clone and to_json methods have been updated accordingly. In the TableView class, the add_tooltip method now accepts an overwrite parameter, allowing for the replacement of existing tooltips based on its value. This change enhances the functionality and flexibility of tooltip management within the table view.

Changes

File Change Summary
fiftyone/operators/types.py Updated Tooltip constructor to require value parameter; modified clone and to_json methods to include value; updated add_tooltip method to include overwrite parameter.
tests/unittests/operators/tableview_tests.py Added tests for add_tooltip method to verify behavior with overwrite parameter.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • ritch
  • imanjra
  • CamronStaley

Poem

🐰 A tooltip's tale, now more refined
With overwrite flag, flexibility designed
No more errors when adding anew
A rabbit's code, both flexible and true!
Hop along, sweet tooltip, find your place 🎉


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@minhtuev minhtuev requested a review from ritch January 7, 2025 01:54
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

🧹 Nitpick comments (2)
fiftyone/operators/types.py (1)

1909-1919: LGTM! Consider adding docstring for the new parameter.

The implementation of the overwrite parameter is clean and logical. The default value of True maintains backward compatibility while providing flexibility to prevent accidental overwrites when needed.

Add parameter documentation:

 def add_tooltip(self, row, column, value, overwrite=True, **kwargs):
+    """
+    Args:
+        overwrite (True): whether to overwrite an existing tooltip at the same position
+    """
tests/unittests/operators/tableview_tests.py (1)

46-48: Add more test cases for comprehensive coverage.

While the basic functionality is tested, consider adding the following test cases:

  1. Verify tooltip attributes are properly updated when overwriting
  2. Verify the error message when overwrite=False
  3. Verify the tooltip map is updated correctly after overwrite
 table.add_tooltip(1, 1, "Tooltip 1")
 table.add_tooltip(1, 2, "Tooltip 2")
 
 with self.assertRaises(ValueError):
     table.add_tooltip(1, 1, "Tooltip 3", overwrite=False)
 
 table.add_tooltip(1, 1, "Tooltip 3")
+
+# Test tooltip attributes are updated
+table.add_tooltip(1, 1, "Tooltip 4", color="red")
+self.assertEqual(table._tooltip_map[(1, 1)].value, "Tooltip 4")
+self.assertEqual(table._tooltip_map[(1, 1)].color, "red")
+
+# Test error message
+with self.assertRaisesRegex(ValueError, "Tooltip for row '1' and column '1' already exists"):
+    table.add_tooltip(1, 1, "Tooltip 5", overwrite=False)
+
+# Test tooltip map consistency
+table.add_tooltip(1, 1, "Tooltip 6")
+self.assertEqual(len(table.tooltips), 2)  # Should still have only 2 tooltips
+self.assertEqual(table._tooltip_map[(1, 1)].value, "Tooltip 6")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7f361b and 1f3031a.

📒 Files selected for processing (2)
  • fiftyone/operators/types.py (1 hunks)
  • tests/unittests/operators/tableview_tests.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test / test-app
  • GitHub Check: build / build
  • GitHub Check: lint / eslint
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build

@minhtuev minhtuev force-pushed the feat/support-tooltip-overwrite branch from 962464a to 92d05f2 Compare January 7, 2025 01:59
Copy link
Contributor

@kaixi-wang kaixi-wang left a comment

Choose a reason for hiding this comment

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

Someone else with more understanding of panels can correct me, but I'm not sure if this is necessary under the current implementation as it seems like the panel instance/table doesn't persist over multiple renders so every time you get new data, the tooltip is new.

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

🧹 Nitpick comments (1)
fiftyone/operators/types.py (1)

1915-1925: Enhance the error message for better clarity.

Consider providing more context in the error message by including the existing tooltip's value.

-                raise ValueError(
-                    f"Tooltip for row '{row}' and column '{column}' already exists"
-                )
+                raise ValueError(
+                    f"Tooltip for row '{row}' and column '{column}' already exists with value '{self._tooltip_map[(row, column)].value}'. Set overwrite=True to replace it."
+                )
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f3031a and 8dfc0a7.

📒 Files selected for processing (2)
  • fiftyone/operators/types.py (2 hunks)
  • tests/unittests/operators/tableview_tests.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.9)
  • GitHub Check: test / test-app
  • GitHub Check: lint / eslint
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build
🔇 Additional comments (2)
tests/unittests/operators/tableview_tests.py (1)

47-60: LGTM! Comprehensive test coverage for tooltip overwrite functionality.

The test case thoroughly validates:

  • Overwriting existing tooltip
  • Tooltip value update
  • Additional arguments storage
  • JSON representation correctness
fiftyone/operators/types.py (1)

1851-1867: LGTM! Well-structured changes to the Tooltip class.

The changes properly integrate the required value parameter throughout the class implementation.

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