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

cherrypick commits for 1.4.0 #5566

Merged
merged 2 commits into from
Mar 11, 2025
Merged

cherrypick commits for 1.4.0 #5566

merged 2 commits into from
Mar 11, 2025

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Mar 11, 2025

What changes are proposed in this pull request?

(Please fill in changes proposed in this fix)

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

(Details)

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

  • New Features
    • Enhanced input handling for more reliable default behaviors when fields are empty or modified.
    • Improved panel state updates, ensuring smoother and more predictable UI interactions.
  • Refactor
    • Streamlined value processing and state merging logic to deliver consistent and stable user experiences.

@imanjra imanjra requested a review from a team March 11, 2025 17:23
Copy link
Contributor

coderabbitai bot commented Mar 11, 2025

Walkthrough

The pull request refactors the coercion logic in the SchemaIO component by moving the local coerceValue function to an external utility. The onIOChange callback now passes (path, value, schema) to the utility version of coerceValue. New utility functions—shouldCoerceValue and an updated coerceValue—evaluate whether to coerce empty arrays or strings based on user interaction and schema defaults. Additionally, the state merging logic in the custom panel hooks has been updated using lodash’s mergeWith with a customizer for array values and improved type safety.

Changes

File(s) Summary
app/.../SchemaIO/(index.tsx, utils/index.ts) Removed the local coerceValue function from the component; updated onIOChange to call an external coerceValue(path, value, schema). Added new utility functions (shouldCoerceValue and coerceValue) to determine and apply value coercion based on schema.
app/.../operators/src/useCustomPanelHooks.ts Introduced lodash’s mergeWith for merging state in handlePanelStateChange with a custom function to overwrite array entries, and updated the state type from any to unknown for improved type safety.

Sequence Diagram(s)

sequenceDiagram
  participant UI as User/Input
  participant SC as SchemaIOComponent
  participant UT as utils/coerceValue
  participant VT as shouldCoerceValue

  UI->>SC: Trigger onIOChange(path, value, schema)
  SC->>UT: Call coerceValue(path, value, schema)
  UT->>VT: Evaluate shouldCoerceValue(path, schema)
  VT-->>UT: Return coercion decision
  UT-->>SC: Return coerced or original value
Loading
sequenceDiagram
  participant Event as Panel State Update
  participant Hook as handlePanelStateChange
  participant Merge as lodash.mergeWith

  Event->>Hook: Pass new state update
  Hook->>Merge: Merge current & new state (custom array handling)
  Merge-->>Hook: Return merged state
  Hook-->>Event: Reflect updated state
Loading

Possibly related PRs

Suggested reviewers

  • ritch
  • brimoor

Poem

I'm a bunny hopping through these lines,
New utilities making our code shine.
Schema changes so crisp and clean,
With merge logic fit for a dream.
Leaping ahead, our code's divine! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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 (1)
app/packages/core/src/plugins/SchemaIO/utils/index.ts (1)

159-174: Add type annotations to coerceValue parameters

The implementation of coerceValue looks good and appropriately uses the shouldCoerceValue helper. However, the function lacks type annotations for its parameters, which would improve type safety and code documentation.

-export function coerceValue(path, value, schema) {
+export function coerceValue(path: string, value: any, schema: SchemaType) {
  const { type } = schema;

  if (!shouldCoerceValue(path, schema)) {
    return value;
  }

  // coerce the value to None if it is an empty string or empty array
  if (type === "array" && Array.isArray(value) && value.length === 0) {
    return null;
  }
  if (type === "string" && value === "") {
    return null;
  }
  return value;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eee32c4 and 67b8c5b.

📒 Files selected for processing (3)
  • app/packages/core/src/plugins/SchemaIO/index.tsx (2 hunks)
  • app/packages/core/src/plugins/SchemaIO/utils/index.ts (2 hunks)
  • app/packages/operators/src/useCustomPanelHooks.ts (2 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/operators/src/useCustomPanelHooks.ts
  • app/packages/core/src/plugins/SchemaIO/utils/index.ts
  • app/packages/core/src/plugins/SchemaIO/index.tsx
⏰ 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-python (ubuntu-latest-m, 3.9)
  • GitHub Check: test / test-app
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
🔇 Additional comments (6)
app/packages/operators/src/useCustomPanelHooks.ts (2)

1-1: Good addition of mergeWith import

Adding mergeWith from lodash is appropriate for implementing custom merge logic.


193-200: Improved state merging logic with better array handling

The implementation now correctly handles array values by using mergeWith with a customizer function. Arrays will be overwritten instead of merged, which prevents unexpected merge behavior. Also, the type change from any to unknown improves type safety.

app/packages/core/src/plugins/SchemaIO/index.tsx (2)

6-6: Good refactoring of coerceValue to a utility function

Moving the coercion logic to a separate utility module improves modularity and code organization.


24-24: Updated function call to match new signature

The coerceValue function call has been updated to include the path parameter, which is necessary for the new implementation that considers user interactions with specific paths.

app/packages/core/src/plugins/SchemaIO/utils/index.ts (2)

12-12: Good addition of isPathUserChanged import

This import is necessary for the new coercion logic that considers whether a path has been modified by user interaction.


133-157: Well-designed helper function for coercion decisions

The shouldCoerceValue function properly encapsulates the logic for determining when values should be coerced, taking into account:

  1. Whether the path was changed by the user
  2. Special handling for empty arrays and strings with matching default values

This makes the coercion logic more maintainable and explicit.

Copy link
Contributor

@Br2850 Br2850 left a comment

Choose a reason for hiding this comment

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

👍🏽

Copy link
Contributor

@manivoxel51 manivoxel51 left a comment

Choose a reason for hiding this comment

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

🍨

@imanjra imanjra merged commit 0292f24 into release/v1.4.0 Mar 11, 2025
12 checks passed
@imanjra imanjra deleted the im-cp-1.4.0-x1 branch March 11, 2025 18:08
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.

3 participants