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, DropDownView minor improvements #4993

Merged
merged 7 commits into from
Oct 30, 2024
Merged

SliderView, DropDownView minor improvements #4993

merged 7 commits into from
Oct 30, 2024

Conversation

manivoxel51
Copy link
Contributor

@manivoxel51 manivoxel51 commented Oct 25, 2024

What changes are proposed in this pull request?

  • don't show the unit dropdown after chat with design - use % for now and wait for feedback
  • SliderView is now using defaultValue and is uncontrolled!
  • DropdownView gets a new prop to allow re-clicking a dropdown option if enabled. This helps for example the cliking on "Reset Threshold" in Data Quality Panel.
  • uncontrolled slider - use defaultValue instead of value prop
  • Had to use useEffect for resetting data from external sources.

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

Screen Shot 2024-10-25 at 3 27 29 PM

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
    • Standardized percentage formatting for slider inputs with updated labels ("Min %" and "Max %").
    • Removed unit selection option from slider input fields.
    • Enhanced dropdown interactivity with the addition of addOnClickToMenuItems for immediate updates upon menu item selection.
  • Bug Fixes
    • Improved handling and validation of percentage values in input fields.

Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request focus on the SliderView and DropdownView components within their respective files. In SliderView.tsx, the value prop is changed to defaultValue, and the UnitSelection prop is set to null. The input handling logic is refined, with updates to the labels for minimum and maximum inputs. In DropdownView.tsx, a new prop addOnClickToMenuItems is introduced, enhancing the handling of menu item clicks and centralizing the change logic through a new handleOnChange function.

Changes

File Change Summary
app/packages/core/src/plugins/SchemaIO/components/SliderView.tsx - Changed value prop to defaultValue in SliderInputField and Slider.
- Updated label props to "Min %" and "Max %".
- Set UnitSelection prop to null.
- Removed handleInputChange and integrated its logic into handleKeyDown.
- Simplified handleSliderChange and updated handleSliderCommit.
app/packages/core/src/plugins/SchemaIO/components/DropdownView.tsx - Added new prop addOnClickToMenuItems in view object.
- Defined handleOnChange function for centralized dropdown change handling.
- Updated onChange handler for Select to use handleOnChange.
- Modified MenuItem components to conditionally call handleOnChange.

Possibly related PRs

  • SliderView tweaks #4901: This PR makes enhancements to the SliderView component, which is directly related to the main PR's modifications of the same component, focusing on improving user interaction and functionality.
  • slider onchange event improvement #4921: This PR also modifies the SliderView component by introducing debouncing and throttling to the slider's onchange event, which aligns with the main PR's changes to input handling and slider interactions.

Suggested reviewers

  • lanzhenw
  • imanjra
  • Br2850

🐇 In the meadow, the sliders now gleam,
With percentages flowing like a sweet dream.
"Min %" and "Max %" they proudly display,
A refined interface, hip-hip-hooray!
Input values dance, validated with care,
In the world of sliders, there's joy in the air! 🌼


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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d44e464 and 9714930.

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

🔇 Additional comments (3)
app/packages/core/src/plugins/SchemaIO/components/SliderView.tsx (3)

88-88: 🛠️ Refactor suggestion

Remove unused unit selection code.

Since unit selection has been removed, the following can be cleaned up:

  1. Remove the UnitSelection component definition
  2. Remove the unit state and setUnit
  3. Remove the ValueFormat type if not used elsewhere

This will improve code maintainability and reduce bundle size.

#!/bin/bash
# Check if ValueFormat type is used elsewhere
rg "ValueFormat[^a-zA-Z]" 

77-88: Update TypeScript types to reflect removed prop.

The value_format prop has been removed and replaced with a hardcoded constant. Ensure that this prop is also removed from the component's TypeScript interface/type definitions.

#!/bin/bash
# Search for any remaining references to value_format in type definitions
rg -t ts -t tsx "value_format.*interface|interface.*value_format|value_format.*type|type.*value_format" 

230-230: Verify uncontrolled component behavior.

Changing from value to defaultValue makes this an uncontrolled component. While this aligns with the PR objectives, please ensure that:

  1. No other components need to programmatically update this slider
  2. The component properly handles initial values and resets
✅ Verification successful

Based on the search results, I can see that the SliderView component is only used in a few specific places, primarily through schema configurations in JSON and as a type definition in Python. There are no direct references showing other components trying to programmatically update the slider's value. Additionally, the component is properly handling initial values through the defaultValue prop with fallback to [min, max].

Change to uncontrolled component is safe to proceed

The codebase analysis shows no components attempting to programmatically control this slider's value after initial render, making the switch to an uncontrolled component using defaultValue appropriate and safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components that might try to update this slider
rg -A 5 "SliderView.*value.*=" 

Length of output: 749


Script:

#!/bin/bash
# Search for any references to SliderView component
rg -A 5 "SliderView" 

# Search for any state updates or refs that might control the slider
ast-grep --pattern 'const [$_] = useState($$$)'

# Look for any parent components that might pass value props
rg -A 5 "<SliderView.*value"

Length of output: 12652

Comment on lines 244 to 248
label="Min %"
value={minText}
onChange={(e) => handleInputChange(e, true)}
onKeyDown={(e) => handleKeyDown(e, true)}
UnitSelection={UnitSelection}
UnitSelection={null}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clean up unused unit-related code.

While the unit selection has been removed and labels hardcoded to "%", there's still unit-related logic that can be simplified:

  1. The handleInputChange function still handles both "%" and "flt" units
  2. The UnitSelection component is defined but never used

Consider cleaning up the unused code:

  const handleInputChange = (e, isMin: boolean) => {
    const value = e.target.value;
    if (!value) {
      isMin ? setMinText("") : setMaxText("");
-   } else if (unit === "%") {
+   } else {
      const percentageValue = parseInt(value);
      if (percentageValue >= 0 && percentageValue <= 100) {
        isMin
          ? setMinText(percentageValue.toFixed())
          : setMaxText(percentageValue.toFixed());
      }
-   } else {
-     const floatValue = parseFloat(value);
-     if (!Number.isNaN(floatValue)) {
-       isMin ? setMinText(value) : setMaxText(value);
-     }
    }
  };

Also applies to: 253-257

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.

Left 2 comments about considering code for the future. I think it’s best we still give the Python Panel user the power when it comes to how the uniting looks. But if they choose %, we just render all the % options that are currently being hardcoded

@Br2850
Copy link
Contributor

Br2850 commented Oct 25, 2024

Awesome LGTM

@manivoxel51 manivoxel51 changed the title Remove unit selection from slider and use defaultValue SliderView, DropDownView minor improvements Oct 30, 2024
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

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

43-53: Consider adding type safety and validation.

While the implementation is solid, consider these improvements:

  1. Add explicit type for the value parameter
  2. Validate separator when splitting/joining arrays
- const handleOnChange = useCallback(
-   (value: any) => {
+ const handleOnChange = useCallback(
+   (value: string | string[]) => {
+     if (separator.length === 0) {
+       console.warn('Empty separator may cause unexpected behavior');
+     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 72a17e2 and c967ea1.

📒 Files selected for processing (2)
  • app/packages/core/src/plugins/SchemaIO/components/DropdownView.tsx (4 hunks)
  • app/packages/core/src/plugins/SchemaIO/components/SliderView.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/packages/core/src/plugins/SchemaIO/components/SliderView.tsx
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/core/src/plugins/SchemaIO/components/DropdownView.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.

🔇 Additional comments (3)
app/packages/core/src/plugins/SchemaIO/components/DropdownView.tsx (3)

2-2: LGTM: Clean import and prop additions.

The changes follow React best practices with proper hook imports and clear prop defaults.

Also applies to: 36-36


55-62: LGTM: Clean effect hook relocation.

The effect hook maintains proper organization while preserving the existing dynamic import logic.


203-207: Verify click handler behavior with multi-select.

The current implementation might have these edge cases:

  1. Double event firing (onClick + onChange)
  2. Unexpected behavior with multi-select mode

Let's verify the multi-select behavior:

Consider this safer implementation:

 onClick={() => {
   if (addOnClickToMenuItems) {
+    if (multiple) {
+      // Handle multi-select case
+      const newValue = selected.includes(value)
+        ? selected.filter(v => v !== value)
+        : [...selected, value];
+      handleOnChange(newValue);
+    } else {
       handleOnChange(value);
+    }
   }
 }}

@lanzhenw
Copy link
Contributor

LGTM

@lanzhenw lanzhenw merged commit ff8dce8 into develop Oct 30, 2024
10 of 11 checks passed
@lanzhenw lanzhenw deleted the bug/cleanup branch October 30, 2024 01:57
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