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

SliderView tweaks #4901

Merged
merged 3 commits into from
Oct 10, 2024
Merged

SliderView tweaks #4901

merged 3 commits into from
Oct 10, 2024

Conversation

manivoxel51
Copy link
Contributor

@manivoxel51 manivoxel51 commented Oct 7, 2024

What changes are proposed in this pull request?

  • double slider improvements based on recent figma designs
  • supports two different units (% or flt)
  • supports min and max input texts in both units
  • slider value is in sync with input fields

@imanjra @lanzhenw @ brian.B feel free to comment/commit/merge

I know @ritch is proposing a solution where a slider would be part of the plotly which would be great! this is improving our in house slider. https://voxel51.atlassian.net/browse/TEAMS-3536

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

Manually created a plugin using the slider mimicking data quality panel

Screen.Recording.2024-10-06.at.7.58.34.PM.mov

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 Header component to conditionally render the Markdown component based on the presence of a label.
    • Improved SliderView component with new input fields for minimum and maximum values, allowing for unit selection and dynamic behavior based on view configuration.
    • Added support for value formatting in the slider with a new utility function.
  • Bug Fixes

    • Prevented unnecessary rendering of the Markdown component when label is undefined or null.
  • Documentation

    • Updated type definitions for better clarity and usage.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes introduced in this pull request involve modifications to two components: Header and SliderView. In the Header component, conditional rendering of the Markdown component is implemented to prevent rendering with undefined or null values. For the SliderView component, significant enhancements include new imports from Material-UI, the addition of a new type and interface, and updates to state management and rendering logic to improve user interaction and input handling.

Changes

File Path Change Summary
app/packages/core/src/plugins/SchemaIO/components/Header.tsx - Conditional rendering added for Markdown component based on label existence.
- Type definition updated: errors: []errors: any[].
app/packages/core/src/plugins/SchemaIO/components/SliderView.tsx - New imports from Material-UI added.
- New type ValueFormat defined.
- New interface SliderInputFieldProps and component SliderInputField created.
- Updated state management and rendering logic for dynamic behavior based on view configuration.
- Adjusted calculations for min and max values.

Suggested reviewers

  • ritch

"In the meadow where bunnies play,
The Header shines in a brand new way.
With sliders that dance and values that gleam,
Our code hops forward, a coder's dream!
So let’s celebrate with a joyful cheer,
For changes that bring us all good cheer! 🐰✨"


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

🧹 Outside diff range and nitpick comments (1)
app/packages/core/src/plugins/SchemaIO/components/Header.tsx (1)

Line range hint 132-132: Consider using a more specific type for errors

The type of errors has been changed from [] to any[]. While this allows for more flexibility, it reduces type safety. Consider using a more specific type instead of any[]. For example:

errors: Error[]; // If using standard Error objects
// or
errors: { message: string; code?: number }[]; // If using a custom error structure

This will provide better type checking and improve code maintainability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c8e6de2 and ea3fc53.

📒 Files selected for processing (2)
  • app/packages/core/src/plugins/SchemaIO/components/Header.tsx (1 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/SliderView.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/packages/core/src/plugins/SchemaIO/components/Header.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/core/src/plugins/SchemaIO/components/SliderView.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.

🪛 Biome
app/packages/core/src/plugins/SchemaIO/components/SliderView.tsx

[error] 201-201: Avoid the delete operator which can impact performance.

(lint/performance/noDelete)


[error] 134-134: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

🔇 Additional comments (1)
app/packages/core/src/plugins/SchemaIO/components/Header.tsx (1)

68-72: Improved conditional rendering of the label

The changes introduce a conditional rendering for the Markdown component, which is a good improvement. This prevents rendering the Markdown component when the label is falsy, adhering to React best practices and potentially improving performance by avoiding unnecessary renders.

}
} else {
const floatValue = parseFloat(value);
if (!isNaN(floatValue)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use Number.isNaN instead of isNaN for accurate type checking

The global isNaN function performs type coercion, which can lead to unexpected results. Using Number.isNaN ensures that the check is performed without type coercion, making it safer for numerical validations.

Apply this diff to fix the issue:

-          if (!isNaN(floatValue)) {
+          if (!Number.isNaN(floatValue)) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!isNaN(floatValue)) {
if (!Number.isNaN(floatValue)) {
🧰 Tools
🪛 Biome

[error] 134-134: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

);

if (labelPosition === "left") {
delete props?.schema?.view?.label;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using the delete operator; consider alternative approaches

Using the delete operator can impact performance in JavaScript. Instead of deleting the property, consider setting it to undefined or creating a new object without the label property.

Apply this diff to refactor the code:

-    delete props?.schema?.view?.label;
+    props = {
+      ...props,
+      schema: {
+        ...props.schema,
+        view: {
+          ...props.schema.view,
+          label: undefined,
+        },
+      },
+    };

Alternatively, you can avoid modifying props directly and adjust the rendering logic to conditionally display the label based on labelPosition.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
delete props?.schema?.view?.label;
props = {
...props,
schema: {
...props.schema,
view: {
...props.schema.view,
label: undefined,
},
},
};
🧰 Tools
🪛 Biome

[error] 201-201: Avoid the delete operator which can impact performance.

(lint/performance/noDelete)

@Br2850 Br2850 changed the base branch from develop to feat/fo-assistant October 10, 2024 15:33
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.

👍🏽

@Br2850 Br2850 merged commit b402b8c into feat/fo-assistant Oct 10, 2024
11 checks passed
@Br2850 Br2850 deleted the feat/sliderView-with-input-text branch October 10, 2024 15:34
@coderabbitai coderabbitai bot mentioned this pull request Oct 11, 2024
7 tasks
@lanzhenw lanzhenw restored the feat/sliderView-with-input-text branch October 14, 2024 19:53
@coderabbitai coderabbitai bot mentioned this pull request Oct 18, 2024
7 tasks
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