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

Looker typing cleanup #5536

Draft
wants to merge 1 commit into
base: release/v1.4.0
Choose a base branch
from
Draft

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Mar 3, 2025

What changes are proposed in this pull request?

Linting types in Looker for a bit more readability. No functional changes

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

  • Refactor
    • Reorganized the rendering workflow for improved clarity and smoother asynchronous operations.
  • New Features
    • Introduced enhanced configurable options for processing tasks, delivering a more robust and responsive rendering experience.

Copy link
Contributor

coderabbitai bot commented Mar 3, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes refactor the internals of the Looker package to improve encapsulation and clarity. In the AbstractLooker class, property visibilities have been tightened by making several properties private and adding new private properties. Method parameters in refreshSample and loadSample have been restructured to nest related rendering options. Additionally, the asynchronous labels rendering manager and worker job types have been updated to support generics and consolidated parameters, along with updates to the processSample function for clearer option handling.

Changes

File Summary of Changes
app/.../lookers/abstract.ts Updated property visibilities (e.g., subscriptions from public to private); added new private properties (canvas, ctx, rootEvents, isSampleUpdating); restructured parameters in refreshSample and loadSample to nest rendering options.
app/.../worker/async-labels-rendering-manager.ts Introduced generic type parameters for the manager and related types; updated job and worker response definitions with consolidated options and schema; replaced forEach with a for...of loop for clarity.
app/.../worker/index.ts Redesigned ProcessSample interface to include an options object of type ProcessSampleOptions; updated processSample parameter handling; adjusted maskTargetsBuffers declaration to a constant.

Sequence Diagram(s)

sequenceDiagram
    participant AL as AbstractLooker
    participant AM as AsyncLabelsRenderingManager
    participant W as Worker
    AL->>AM: enqueueLabelPaintingJob({ sample, options })
    AM->>W: assignJobToFreeWorker(job)
    W-->>AM: WorkerResponse<S>
    AM-->>AL: AsyncJobResolutionResult<S>
Loading

Possibly related PRs

Suggested labels

documentation, app

Suggested reviewers

  • sashankaryal
  • tom-vx51

Poem

I'm a coding rabbit, hopping with glee,
Tightening properties, as neat as can be.
Options now nestled, async tasks in a row,
Workers and managers in a smooth flow.
My code burrows cheer with every new show! 🐇


🪧 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.
  • @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.

@benjaminpkane benjaminpkane self-assigned this Mar 3, 2025
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)
app/packages/looker/src/worker/index.ts (1)

318-327: Consider optional or default fields
Declaring all properties as required in ProcessSampleOptions might be too strict if some properties can be missing or have default behaviors. If that’s the case, consider marking them optional or providing defaults.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3a5d40f and 2f12ce0.

📒 Files selected for processing (3)
  • app/packages/looker/src/lookers/abstract.ts (4 hunks)
  • app/packages/looker/src/worker/async-labels-rendering-manager.ts (5 hunks)
  • app/packages/looker/src/worker/index.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: Review the Typescript and React code for co...

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

  • app/packages/looker/src/worker/index.ts
  • app/packages/looker/src/worker/async-labels-rendering-manager.ts
  • app/packages/looker/src/lookers/abstract.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-app
  • GitHub Check: lint / eslint
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build / build
🔇 Additional comments (21)
app/packages/looker/src/worker/index.ts (5)

11-15: Import usage looks consistent
The newly introduced imports (getCls, getFetchFunction, and setFetchFunction) appear properly utilized and align with the rest of the module.


328-332: Check intersection type correctness
Sample & FrameSample assumes all Sample instances always have frame attributes. Verify that no usage scenario lacks frame properties; otherwise, a more flexible type might be needed.


338-347: Destructuring approach is clear
The function signature effectively groups options fields. This improves readability and maintainability.


365-365: Initialize buffers array
Defining maskTargetsBuffers here clarifies that the gathered buffers are meant for subsequent transfer.


863-877: Consolidated worker arguments
Packaging options, sample, and uuid into workerArgs offers clarity when passing data to the worker. The approach is consistent with the rest of the system.

app/packages/looker/src/worker/async-labels-rendering-manager.ts (8)

5-5: Use of Schema
Importing Schema here integrates well with the typed approach in the rest of the file.


7-8: New imports for process-sample types
The imported types are used consistently for strongly-typed job submission and handling.


14-21: AsyncLabelsRenderingJob type enhancements
Specifying properties like options and sample within the job definition clarifies the data flow for label-rendering tasks.


23-27: AsyncJobResolutionResult
Defining a clear resolution result type promotes maintainable asynchronous patterns.


28-33: WorkerResponse type
Including both sample and coloring in the worker’s response clarifies the data returned to the main thread.


39-39: Use of pendingJobs map
Storing jobs keyed by sample is a straightforward approach to avoid redundant label-processing tasks.


165-165: Generic AsyncLabelsRenderingManager
Allowing a generic sample type broadens the manager’s compatibility with different sample structures.


171-197: enqueueLabelPaintingJob modifications
Leveraging the new consolidated options structure and generics improves the API’s clarity, reduces parameter sprawl, and assists in type safety.

app/packages/looker/src/lookers/abstract.ts (8)

85-88: Refactoring core properties into private fields
This grants stricter encapsulation, ensuring these fields are only accessible internally.


92-92: Privatizing eventTarget
Restricting eventTarget to class-internal usage reduces unintended external manipulation of events.


96-96: Private resizeObserver
Localizing the resize logic within the class prevents misuse or accidental external control.


100-100: Introduce isSampleUpdating flag
This boolean effectively prevents concurrent sample loading, improving reliability.


104-110: Protected fields for internal usage
Defining these fields as protected supports controlled extension in subclasses while preserving internal invariants.


110-110: Public uuid
Exposing a unique identifier can help track looker instances, especially in multi-instance scenarios.


171-171: Initialize asyncLabelsRenderingManager
Instantiating a dedicated manager streamlines label rendering tasks and aligns with the new typed approach.


612-623: Refactor refreshSample with consolidated options
Grouping the rendering parameters under an options object in the job request improves clarity, reduces argument length, and ensures consistent usage across the codebase.

@benjaminpkane benjaminpkane marked this pull request as draft March 3, 2025 23:55
@benjaminpkane benjaminpkane changed the base branch from develop to release/v1.4.0 March 10, 2025 16:06
@benjaminpkane benjaminpkane force-pushed the looker-typing-cleanup branch from 2f12ce0 to 1a4bd93 Compare March 11, 2025 22:17
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.

1 participant