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

Make ImageView clickable/linkable in Python Panels #4996

Merged
merged 9 commits into from
Oct 29, 2024

Conversation

Br2850
Copy link
Contributor

@Br2850 Br2850 commented Oct 28, 2024

What changes are proposed in this pull request?

Give images the ability to:

  • Open links (via href)
  • Call operators w/ params
  • Added new .img() built in method to allow Python Panels a shortcut to define images

Updated docstrings and examples to correctly identify how to use .img() and ImageView

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

See screen recording below w/ code

 def on_load(self, ctx):
        ctx.panel.state.image_link = "https://i.imgur.com/TGEZj1Rl.jpg"

schema = {
            "height": "200px",
            "width": "200px",
            "alt": "My image alt text",
            "href": "https://voxel51.com",
            "operator": self.do_something,
            "prompt": True,
            "params": {"foo": "bar"},
        }
        panel.define_property(
            "image_link",
            types.String(),
            view=types.ImageView(**schema),
        )
Screen.Recording.2024-10-28.at.11.35.19.AM.mov

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

Summary by CodeRabbit

  • New Features

    • Enhanced ImageView component with additional properties for improved interactivity.
    • Introduced click handling that supports complex user interactions and external URL navigation.
    • Added a new img method to define image properties for display.
  • Documentation

    • Updated documentation for the ImageView class to include new parameters, improving clarity for developers.

@Br2850 Br2850 added the enhancement Code enhancement label Oct 28, 2024
@Br2850 Br2850 requested review from ritch and imanjra October 28, 2024 15:38
@Br2850 Br2850 self-assigned this Oct 28, 2024
Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Walkthrough

The pull request introduces enhancements to the ImageView component in ImageView.tsx and the ImageView class in types.py. The ImageView component now destructures additional properties from schema?.view, including href, operator, prompt, and params. New hooks for panel management are utilized, and an onClick function has been added to handle user interactions. The ImageView class constructor is updated to accept these new parameters, improving its configurability and documentation.

Changes

File Path Change Summary
app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx Expanded destructuring of schema?.view to include href, operator, prompt, and params; added handleClick, openLink, and onClick functions for enhanced interactivity.
fiftyone/operators/types.py Added img method to Object class for defining an image property; updated ImageView class documentation to include new parameters: height, width, alt, href, operator, prompt, and params.

Possibly related PRs

  • python panel and operator views tweaks and fixes #4580: This PR modifies the ImageView component in ImageView.tsx, which is directly related to the changes made in the main PR that also involves the ImageView component, enhancing its functionality with additional properties and event handling.

Suggested labels

app

Suggested reviewers

  • ritch
  • imanjra

🐰 In the meadow, bright and clear,
The ImageView hops, bringing cheer.
With new hooks and clicks to explore,
A world of images, we adore!
So gather 'round, both near and far,
Let's celebrate our coding star! 🌟


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.

@Br2850 Br2850 requested a review from allenleetc October 28, 2024 15:38
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: 3

🧹 Outside diff range and nitpick comments (1)
fiftyone/operators/types.py (1)

1780-1788: Consider enhancing the example to demonstrate both link and operator usage.

The example shows basic usage but could be more comprehensive by demonstrating both ways to make an image interactive:

  1. Opening a URL via href
  2. Calling an operator with parameters

Consider updating the example to show both cases:

def execute():
    return {"image": "https://voxel51.com/your/image.png"}

def resolve_output(self, ctx):
    # Example 1: Image with a link
    schema1 = {
        "height": "100px",
        "width": "100px",
        "alt": "Click to visit Voxel51",
        "href": "https://voxel51.com",
    }
    
    # Example 2: Image with an operator
    schema2 = {
        "height": "100px",
        "width": "100px",
        "alt": "Click to process image",
        "operator": self.do_something,
        "prompt": True,  # Show confirmation dialog
        "params": {"foo": "bar"},
    }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8e51280 and ddcdbe4.

📒 Files selected for processing (2)
  • app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx (2 hunks)
  • fiftyone/operators/types.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/ImageView.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 (3)
app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx (2)

5-6: LGTM: Hook imports follow React conventions

The new hook imports are properly organized and follow React naming conventions.


21-22: LGTM: Proper hook usage

Hooks are correctly implemented at the top level of the component.

fiftyone/operators/types.py (1)

1798-1805: LGTM! Parameters are well-documented and align with requirements.

The new parameters (height, width, alt, href, operator, prompt, params) are properly documented and provide the necessary functionality to make images clickable/linkable as specified in the PR objectives.

Comment on lines 10 to 18
const {
height,
width,
alt,
href,
operator,
prompt = false,
params,
} = schema?.view || {};
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

Add TypeScript type definitions for props and schema

The component lacks proper TypeScript types for its props and schema structure. This could lead to runtime errors if invalid props are passed.

Consider adding type definitions:

interface ImageViewProps {
  schema: {
    view?: {
      height?: number;
      width?: number;
      alt?: string;
      href?: string;
      operator?: string;
      prompt?: boolean;
      params?: Record<string, unknown>;
    };
    default?: string;
  };
  data?: string;
}

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: 1

🧹 Outside diff range and nitpick comments (1)
app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx (1)

49-49: Update cursor style to indicate interactivity when 'operator' is defined

Currently, the cursor changes to a pointer only when href is defined. However, the image is also interactive when an operator is specified. To improve user experience, update the cursor style to indicate interactivity whenever either href or operator is defined.

Apply this diff to adjust the cursor styling:

         onClick={onClick}
-        style={{ cursor: href ? "pointer" : "default" }} // Change cursor based on href
+        style={{ cursor: (href || operator) ? "pointer" : "default" }} // Change cursor based on href or operator
         {...getComponentProps(props, "image")}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ddcdbe4 and c16b621.

📒 Files selected for processing (1)
  • app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/ImageView.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.

@Br2850 Br2850 requested a review from a team October 28, 2024 18:00
fiftyone/operators/types.py Outdated Show resolved Hide resolved
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c16b621 and 3f15d26.

📒 Files selected for processing (2)
  • app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx (2 hunks)
  • fiftyone/operators/types.py (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/ImageView.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 (4)
app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx (2)

11-20: LGTM! Clean implementation of new parameters

The destructuring is well-organized with sensible defaults for prompt and cursor. The new parameters align well with the PR objectives for making images clickable and linkable.


59-60: LGTM! Clean implementation of click handling and cursor feedback

The cursor styling provides good visual feedback for clickable images, and the implementation is clean and straightforward.

fiftyone/operators/types.py (2)

312-370: LGTM! Well-implemented image configuration method.

The new img method provides a clean interface for configuring clickable/linkable images in Python Panels. The implementation is thorough and well-documented.


Line range hint 1840-1865: LGTM! Clear and comprehensive documentation.

The updated ImageView docstring accurately describes all new parameters and provides helpful examples for both URL links and operator execution.

Br2850 and others added 2 commits October 29, 2024 15:09
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3f15d26 and b479488.

📒 Files selected for processing (1)
  • app/packages/core/src/plugins/SchemaIO/components/ImageView.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/ImageView.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.

Comment on lines +37 to +39
if (result?.error) {
console.log(result?.error);
console.log(result?.errorMessage);
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

Enhance error handling with Toast notifications

Currently, errors are only logged to the console. Users won't be aware if an operation fails.

          if (result?.error) {
-            console.log(result?.error);
-            console.log(result?.errorMessage);
+            import { toast } from "@fiftyone/spaces";
+            toast.error(`Operation failed: ${result?.errorMessage || 'Unknown error'}`);
+            console.error('Operation failed:', { error: result?.error, message: result?.errorMessage });

Committable suggestion was skipped due to low confidence.

@Br2850 Br2850 requested a review from ritch October 29, 2024 20:51
@Br2850 Br2850 merged commit 23bfaf9 into develop Oct 29, 2024
13 checks passed
@Br2850 Br2850 deleted the feat/linkable-images branch October 29, 2024 22:24
@coderabbitai coderabbitai bot mentioned this pull request Nov 25, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Code enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants