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

Fix App dataset color scheme assignment #5478

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Feb 7, 2025

What changes are proposed in this pull request?

Minimal change to fix #5410 with a test

To reproduce

import fiftyone as fo
import fiftyone.zoo as foz

color_scheme = fo.ColorScheme(
    color_by="field",
    opacity=0.7,
    color_pool=["#ffffff"],
    fields=[
        {
            "path": "ground_truth",
            "fieldColor": "#000000",
        }
    ],
)
dataset = foz.load_zoo_dataset("quickstart")

dataset.app_config.color_scheme = color_scheme
dataset.save()

session = fo.launch_app()
# navigate to "quickstart" in the App

Recording shows correct behavior

Screen.Recording.2025-02-07.at.4.35.48.PM.mov

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

Test case for assignSession

Release Notes

  • Fixed color scheme defaults when changing datasets in the App

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
    • Improved dataset transitions: When switching datasets, the app now reliably applies your visual theme settings—ensuring a more consistent and predictable appearance.

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

The pull request refactors how session updates occur by extracting the inline logic into a new function called assignSession. This function centralizes the updating of the session object by setting default values and using the ensureColorScheme utility. In addition, a new Vitest test suite confirms that invoking assignSession correctly updates the session’s color scheme—specifically the colorPool property—when transitioning datasets, while preserving the existing unsubscribe behavior.

Changes

File(s) Change Summary
app/.../onSetDataset.ts Added the assignSession function to centralize session updates. This function updates session properties (including the colorScheme via ensureColorScheme) and retains the unsubscribe call.
app/.../onSetDataset.test.ts Introduced a new Vitest test suite to validate assignSession. The test checks that the session’s colorPool is updated correctly based on new settings.

Sequence Diagram(s)

sequenceDiagram
  participant Tester as Test Suite
  participant Client as assignSession Caller
  participant AS as assignSession
  participant ECS as ensureColorScheme
  participant Sub as Subscription

  Tester->>Client: Initialize session & settings
  Client->>AS: Call assignSession(session, settings)
  AS->>ECS: Update colorScheme settings
  ECS-->>AS: Return updated colorScheme
  AS->>Sub: Unsubscribe from session updates
  AS-->>Client: Return updated session
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure session’s color scheme is correctly set on dataset change (#5410)

Suggested labels

bug, app

Suggested reviewers

  • sashankaryal
  • brimoor
  • imanjra

Poem

I'm a little rabbit in a code-filled warren,
Hopping through functions with a joyful cheer.
AssignSession guides the color schemes bright,
Testing ensures they shine just right.
With each new hop, our code dances free—
Burrowing deep in logic, happy as can be!
🐇💻

✨ 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/app/src/useSetters/onSetDataset.test.ts (1)

5-12: Enhance test coverage for assignSession function.

While the basic color scheme test is good, consider adding tests for:

  • Other session properties (selectedLabels, selectedSamples, etc.)
  • Edge cases (null/undefined settings)
  • Config parameter effects on color scheme

Here's a suggested test expansion:

describe("test session assignment for dataset transition", () => {
  it("assigns color scheme settings", () => {
    const session = { ...SESSION_DEFAULT };
    assignSession(session, { colorScheme: { colorPool: ["#ffffff"] } });
    expect(session.colorScheme.colorPool).toEqual(["#ffffff"]);
  });

  it("resets session properties", () => {
    const session = { 
      ...SESSION_DEFAULT,
      selectedLabels: ["label1"],
      selectedSamples: new Set(["sample1"]),
      fieldVisibilityStage: "some_stage"
    };
    assignSession(session, {});
    expect(session.selectedLabels).toEqual([]);
    expect(session.selectedSamples.size).toBe(0);
    expect(session.fieldVisibilityStage).toBeUndefined();
  });

  it("handles undefined settings gracefully", () => {
    const session = { ...SESSION_DEFAULT };
    assignSession(session, {});
    expect(session.sessionGroupSlice).toBeUndefined();
  });
});
app/packages/app/src/useSetters/onSetDataset.ts (1)

59-70: Simplify type definition for better readability.

Consider extracting the complex nested type into a separate type alias for better maintainability.

type DatasetAppConfig = NonNullable<NonNullable<ResponseFrom<DatasetPageQuery>["dataset"]>["appConfig"]>;

type SessionSettings = {
  colorScheme?: Partial<DatasetAppConfig["colorScheme"]>;
  config?: ResponseFrom<DatasetPageQuery>["config"];
  groupSlice?: null | string;
};

export const assignSession = (
  session: Session,
  settings: SessionSettings
) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 55cdc1f and 7f7fa40.

📒 Files selected for processing (2)
  • app/packages/app/src/useSetters/onSetDataset.test.ts (1 hunks)
  • app/packages/app/src/useSetters/onSetDataset.ts (3 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/app/src/useSetters/onSetDataset.ts
  • app/packages/app/src/useSetters/onSetDataset.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test / test-app
  • GitHub Check: lint / eslint
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
🔇 Additional comments (2)
app/packages/app/src/useSetters/onSetDataset.ts (2)

31-38: LGTM! Clean implementation of session assignment.

The refactoring improves code organization by centralizing session update logic while maintaining the existing unsubscribe behavior.


71-80: LGTM! Clear session reset and update logic.

The implementation properly resets session state and applies new settings in a predictable order.

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.

[BUG] Color scheme not persisting
1 participant