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

Optimize modal sample tagging (#5417) for 1.3.1 #5513

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

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Feb 24, 2025

Cherry pick #5417 for 1.3.1

Release Notes

  • Optimized :ref:modal tagging <app-tagging>

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

    • Improved how tagging operations process and organize grouping data to deliver more reliable tag management.
    • Streamlined aggregation handling to enhance the consistency and clarity of data displayed in grouped views.
    • Enhanced state management for sample identification, contributing to a smoother overall user experience.
  • Chores

    • Optimized internal data mappings and import structures for improved system consistency.

* tag counts with respect to modal sample/group

* group issues

* simplify, some cleanup

* revert slice view change

* fix e2e
@benjaminpkane benjaminpkane added the enhancement Code enhancement label Feb 24, 2025
@benjaminpkane benjaminpkane self-assigned this Feb 24, 2025
Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Walkthrough

The changes reorganize the data fetching and payload construction within the tagging functionality. In the core components, the logic now distinguishes between a new "mode" value obtained via a group statistics function and "currentSlices" fetched separately. Similar adjustments have been made in utility functions to better structure the data passed to downstream operations. Additionally, updates in the state management modules adjust slice handling, aggregation paths, and type safety. The backend logic for mixed view handling in aggregations was also simplified.

Changes

File(s) Change Summary
app/.../Actions/Tagger.tsx & app/.../Actions/utils.tsx Modified tagging logic: In useTagCallback, the previous fetching of slices was split into new variables—mode (from groupStatistics) and currentSlices (from fos.currentSlices)—and payloads updated accordingly. Additionally, functions like tagStatistics and tagParameters now reorder and add properties (currentSlices) for clearer data handling.
app/.../state/src/recoil/aggregations.ts, app/.../state/src/recoil/modal.ts, and app/.../state/src/recoil/pathData/tags.ts Updated state logic: Added imports (e.g., groupSlices, groupStatistics), refined the aggregation flow to use these new values, updated type definitions in selectors (e.g., sidebarSampleId now explicitly typed), and reworked conditional logic for aggregation path formation and tag count selectors.
fiftyone/server/aggregations.py Removed a conditional block that handled mixed views for group slices, thereby simplifying the aggregation resolver’s logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Tagger
    participant FosModule
    participant TagAPI

    User->>Tagger: Initiate tagging action
    Tagger->>FosModule: Call groupStatistics(modal) → obtain mode
    Tagger->>FosModule: Call currentSlices(modal) → obtain currentSlices
    Tagger->>FosModule: Call groupSlices(modal) → obtain slices
    Tagger->>TagAPI: Submit payload { mode, currentSlices, slices }
Loading

Possibly related PRs

Suggested labels

app

Suggested reviewers

  • brimoor
  • imanjra

Poem

Hop, hop! I'm a rabbit, full of cheer,
Skipping through code changes, loud and clear.
New modes and slices in a rhythmic dance,
Tagging data with a swift, fine enhance.
With whiskers twitching, I applaud this prance!
🐰🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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)
app/packages/core/src/components/Actions/utils.tsx (2)

87-91: LGTM! Consider adding type assertions for better type safety.

The restructuring of the group data object improves clarity by separating current and group slices. The changes align well with the PR's objective of optimizing modal sample tagging.

Consider adding type assertions to ensure type safety:

-                  currentSlices: get(fos.currentSlices(modal)),
-                  mode: get(groupStatistics(modal)),
-                  slice: get(fos.currentSlice(modal)),
-                  slices: get(fos.groupSlices),
+                  currentSlices: get(fos.currentSlices(modal)) as string[] | null,
+                  mode: get(groupStatistics(modal)) as "group" | "slice",
+                  slice: get(fos.currentSlice(modal)) as string | null,
+                  slices: get(fos.groupSlices) as string[] | null,

159-159: LGTM! Consider using early return pattern for better readability.

The changes improve type safety and simplify the logic for handling non-group mode. The condition update for shouldShowCurrentSample is more precise.

Consider using early return pattern for better readability:

-  if (groupData && !groups) {
-    groupData.slices = groupData.currentSlices;
-  }
+  if (!groupData || groups) return;
+  groupData.slices = groupData.currentSlices;

Also applies to: 168-168, 170-172

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e2a660c and 1b7e196.

📒 Files selected for processing (6)
  • app/packages/core/src/components/Actions/Tagger.tsx (2 hunks)
  • app/packages/core/src/components/Actions/utils.tsx (5 hunks)
  • app/packages/state/src/recoil/aggregations.ts (3 hunks)
  • app/packages/state/src/recoil/modal.ts (2 hunks)
  • app/packages/state/src/recoil/pathData/tags.ts (3 hunks)
  • fiftyone/server/aggregations.py (0 hunks)
💤 Files with no reviewable changes (1)
  • fiftyone/server/aggregations.py
🧰 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/core/src/components/Actions/Tagger.tsx
  • app/packages/state/src/recoil/modal.ts
  • app/packages/core/src/components/Actions/utils.tsx
  • app/packages/state/src/recoil/pathData/tags.ts
  • app/packages/state/src/recoil/aggregations.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • 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
  • GitHub Check: build
🔇 Additional comments (11)
app/packages/state/src/recoil/pathData/tags.ts (3)

3-3: LGTM: Added import for groupStatistics.

The new import is correctly added and will be used to determine the mixed parameter value.


14-23: LGTM: Improved aggregation logic.

The aggregation parameters are now correctly determined using groupStatistics(modal), making the mixed parameter dynamic based on group mode.


56-62: LGTM: Consistent use of groupStatistics.

The same pattern is correctly applied to the sample tag counts selector.

app/packages/core/src/components/Actions/Tagger.tsx (2)

351-355: LGTM: Improved data fetching organization.

The code now correctly separates:

  • Mode from group statistics
  • Current slices
  • Group slices

This restructuring improves code clarity and maintainability.


370-374: LGTM: Enhanced group data structure.

The group data object now properly includes:

  • Mode from group statistics
  • Current slices for immediate context
  • Group slices for broader context
app/packages/state/src/recoil/modal.ts (2)

32-32: LGTM: Enhanced type safety with explicit return type.

The selector now correctly specifies its return type as null | string.


44-44: LGTM: Improved type safety for sample ID.

The code now correctly type casts sample?.sample?._id to string, addressing the type concern noted in the comment above.

app/packages/state/src/recoil/aggregations.ts (3)

8-14: LGTM: Well-organized imports.

The imports are now properly grouped and include all necessary group-related functions.


85-85: LGTM: Improved slice handling logic.

The code now correctly uses groupSlices for mixed state and currentSlices otherwise.


159-163: LGTM: Enhanced path generation logic.

The code now:

  • Uses spread operator for better array handling
  • Correctly prepends 'tags' for non-numeric, non-frames paths
  • Maintains better separation of concerns

Also applies to: 170-173

app/packages/core/src/components/Actions/utils.tsx (1)

135-135: LGTM! Simplified return statement improves code clarity.

The direct return of tags from tagStatistics removes unnecessary complexity while maintaining the same functionality.

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.

3 participants