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 detach to spotlight #5157

Merged
merged 2 commits into from
Nov 20, 2024
Merged

Add detach to spotlight #5157

merged 2 commits into from
Nov 20, 2024

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Nov 20, 2024

What changes are proposed in this pull request?

Looker instances should be detached when a spotlight instance is destroyed

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 detach method for the Spotlight instance to enhance looker management.
    • Added an optional detach method to the SpotlightConfig interface for configurable detachment behavior.
  • Bug Fixes

    • Updated the #destroyItems method in the Row class to allow for more explicit handling of item destruction based on a new parameter.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

This pull request introduces enhancements to the Spotlight functionality within the Grid component by adding a new detach method. This method allows the Spotlight instance to detach lookers as needed. Additionally, modifications to the Row class's #destroyItems method enable it to conditionally use either the destroy or detach methods based on a new parameter. Furthermore, the SpotlightConfig interface is updated to include an optional detach method, allowing for configuration of detachment behavior.

Changes

File Path Change Summary
app/packages/core/src/components/Grid/Grid.tsx Added method detach(id: { description: string }) to Spotlight instance.
app/packages/spotlight/src/row.ts Updated #destroyItems() method to accept a parameter destroyItems = false, altering control flow.
app/packages/spotlight/src/types.ts Added optional method detach?: (id: ID) => void; to SpotlightConfig interface.

Possibly related PRs

  • Spotlight cleanup #5015: The changes in this PR involve the destroy method in the Spotlight class, which is relevant to the new detach method added in the main PR, as both methods are part of the lifecycle management of the Spotlight instance.

Suggested reviewers

  • sashankaryal
  • tom-vx51
  • ritch

🐇 In the spotlight, a new way to play,
With detach to help, come what may!
Items can part, or stay in the fray,
Enhancements abound, hip-hip-hooray!
A hop and a skip, let’s brighten the day! 🌟


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

🧹 Outside diff range and nitpick comments (3)
app/packages/spotlight/src/types.ts (1)

61-61: Consider adding JSDoc documentation

To improve maintainability and provide better IDE support, consider adding JSDoc documentation for the new detach method explaining its purpose and parameters.

+ /** Detaches a Looker instance associated with the given ID */
  detach?: (id: ID) => void;
app/packages/core/src/components/Grid/Grid.tsx (1)

Line range hint 31-68: Enhance type safety for Spotlight configuration

Consider adding explicit TypeScript interfaces for the Spotlight configuration and looker types to improve type safety and documentation.

Add these type definitions:

interface SpotlightLooker {
  destroy(): void;
  detach(): void;
  disable(): void;
  attach(element: HTMLElement, dimensions: unknown): void;
}

interface SpotlightConfig<T, S> {
  destroy: (id: { description: string }) => void;
  detach: (id: { description: string }) => void;
  // ... other config properties
}
app/packages/spotlight/src/row.ts (1)

234-235: Enhance type safety and error handling in the destroy/detach logic.

The implementation correctly supports both destroy and detach operations with proper error handling. Consider these improvements:

  1. Add type narrowing for better type safety
  2. Enhance error reporting with operation context
-  #destroyItems(destroyItems = false) {
-    const destroy = destroyItems ? this.#config.destroy : this.#config.detach;
+  #destroyItems(destroyItems = false) {
+    const operation = destroyItems ? 'destroy' : 'detach';
+    const handler = destroyItems ? this.#config.destroy : this.#config.detach;
+    
+    if (!handler) {
+      return;
+    }

     const errors = [];
     for (const item of this.#row) {
       try {
-        destroy(item.item.id);
+        handler(item.item.id);
       } catch (e) {
-        errors.push(e);
+        errors.push(`Failed to ${operation} item ${item.item.id.description}: ${e}`);
       }
     }

     if (errors.length > 0) {
-      console.error("Errors occurred during row destruction:", errors);
+      console.error(`Errors occurred during row ${operation}:`, errors);
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9967d21 and 6647a9d.

📒 Files selected for processing (3)
  • app/packages/core/src/components/Grid/Grid.tsx (1 hunks)
  • app/packages/spotlight/src/row.ts (2 hunks)
  • app/packages/spotlight/src/types.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/packages/core/src/components/Grid/Grid.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/spotlight/src/row.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/spotlight/src/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.

📓 Learnings (1)
app/packages/spotlight/src/row.ts (1)
Learnt from: tom-vx51
PR: voxel51/fiftyone#5015
File: app/packages/spotlight/src/row.ts:122-125
Timestamp: 2024-11-12T12:36:39.324Z
Learning: In the `Row` class of `app/packages/spotlight/src/row.ts`, ensure that the `destroy` method includes error handling to prevent memory leaks due to cleanup errors.
🔇 Additional comments (3)
app/packages/spotlight/src/types.ts (1)

61-61: LGTM! The detach method is well-integrated

The addition of the optional detach method to SpotlightConfig interface aligns well with the PR objective and follows the existing pattern of the destroy method. The type signature is correct and maintains consistency with the interface's generic parameters.

app/packages/core/src/components/Grid/Grid.tsx (1)

Line range hint 147-157: Verify cleanup behavior for detached items

The cleanup in useLayoutEffect only calls destroy. Verify if detached items also need cleanup during component unmount.

app/packages/spotlight/src/row.ts (1)

123-123: LGTM! Clean implementation of conditional destroy/detach behavior.

The change correctly propagates the destroyItems flag to the private method while maintaining backward compatibility.

Copy link
Contributor

@sashankaryal sashankaryal left a comment

Choose a reason for hiding this comment

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

thanks for the fix

@benjaminpkane benjaminpkane merged commit 453fbd0 into release/v1.1.0 Nov 20, 2024
11 checks passed
@benjaminpkane benjaminpkane deleted the bugfix/detach branch November 20, 2024 19:56
@coderabbitai coderabbitai bot mentioned this pull request Dec 2, 2024
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