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(ui): Select shows items in the list, small gap fixes for icons, d… #697

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

billcookie
Copy link
Contributor

@billcookie billcookie commented Dec 16, 2024

…isplay fixes

Overview

Select component was not displaying options when selected and other stylistic issues.

What I've done

  • Items are now displayed with Select Menu on the params for nodes
  • Small 8px gap added for the title of the drawer.
  • Icons fixed and centered and gap added for better UI

What I haven't done

How I tested

Manually

Screenshot

Which point I want you to review particularly

  • Possible refactors
  • Possible optimization

Memo

ofAny for react-jsonschema-form issue with null means that select will not work properly if OfAny has null.

Summary by CodeRabbit

  • New Features

    • Enhanced spacing in the ArrayFieldItemTemplate for improved layout.
    • Updated SelectWidget for better event handling and user interaction.
    • Improved tab spacing in the ParamEditor component.
  • Bug Fixes

    • Removed unnecessary commented-out code in SelectWidget for a cleaner structure.
    • Simplified props in ParamEditor to streamline the component's interface.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

The pull request introduces modifications to three TypeScript React components: ArrayFieldItemTemplate, SelectWidget, and ParamEditor. The changes primarily focus on improving UI layout, spacing, and code clarity. The ArrayFieldItemTemplate receives updated class names for better spacing, the SelectWidget streamlines its event handling and removes commented code, and the ParamEditor adjusts tab trigger spacing and removes unused prop types.

Changes

File Change Summary
ui/src/components/SchemaForm/Templates/ArrayFieldItemTemplate.tsx Updated div class names, added gap-1 for improved spacing, replaced py-4 with pt-4
ui/src/components/SchemaForm/Widgets/SelectWidget.tsx Removed commented code, added useState for selectedLabel, improved event handling with new handler functions, updated method signature
ui/src/features/Editor/components/RightPanel/components/ParamEditor/index.tsx Added gap-2 to TabsList, removed commented-out nodeType and nodeParameters props

Possibly related PRs

Suggested labels

engine

Suggested reviewers

  • KaWaite

Poem

🐰 Hop, hop, through the code we go,
Spacing tweaks make the UI glow.
Select and edit with newfound grace,
Refactoring leaves no wasted space.
A rabbit's touch, both swift and neat! 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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

netlify bot commented Dec 16, 2024

Deploy Preview for reearth-flow ready!

Name Link
🔨 Latest commit 20437e0
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/675f9461a816a8000849c117
😎 Deploy Preview https://deploy-preview-697--reearth-flow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@billcookie billcookie marked this pull request as ready for review December 16, 2024 02:11
@billcookie billcookie requested a review from KaWaite as a code owner December 16, 2024 02:11
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

🧹 Nitpick comments (3)
ui/src/components/SchemaForm/Templates/ArrayFieldItemTemplate.tsx (1)

35-39: Consider maintaining consistent vertical padding

While the added gap utilities improve spacing between elements, changing py-4 to pt-4 removes bottom padding which might affect layout consistency. Consider if bottom padding is still needed for visual balance.

-      <div className="pt-4">
+      <div className="py-4">
ui/src/components/SchemaForm/Widgets/SelectWidget.tsx (1)

59-70: Enhance accessibility for the dropdown trigger

The dropdown trigger button lacks proper ARIA attributes for better accessibility.

   <DropdownMenuTrigger
     className={`flex h-8 w-full items-center justify-between rounded border bg-background px-3 hover:bg-accent ${
       rawErrors.length > 0 ? "border-destructive" : ""
     }`}
     disabled={disabled || readonly}
     onBlur={handleBlur}
-    onFocus={handleFocus}>
+    onFocus={handleFocus}
+    aria-label={`Select ${placeholder}`}
+    aria-invalid={rawErrors.length > 0}>
ui/src/features/Editor/components/RightPanel/components/ParamEditor/index.tsx (1)

Line range hint 20-21: Address TODO comment for nodeParameters type

The TODO comment indicates that the type for nodeParameters needs to be defined.

Would you like me to help define a proper type for the nodeParameters based on its usage in the codebase?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2fa9aeb and 6ecd9b3.

📒 Files selected for processing (3)
  • ui/src/components/SchemaForm/Templates/ArrayFieldItemTemplate.tsx (1 hunks)
  • ui/src/components/SchemaForm/Widgets/SelectWidget.tsx (2 hunks)
  • ui/src/features/Editor/components/RightPanel/components/ParamEditor/index.tsx (1 hunks)
🔇 Additional comments (2)
ui/src/components/SchemaForm/Widgets/SelectWidget.tsx (1)

72-83: 🛠️ Refactor suggestion

Improve type safety in enumOptions mapping

The mapping of enumOptions uses any type and could be more type-safe.

-      {enumOptions?.map(({ value: optionValue, label }: any, i: number) => {
+      {enumOptions?.map(({ value: optionValue, label }, i) => {

Likely invalid or redundant comment.

ui/src/features/Editor/components/RightPanel/components/ParamEditor/index.tsx (1)

Line range hint 62-67: LGTM: Improved tab spacing

The addition of gap-2 class improves the visual spacing between tab triggers, aligning with the PR's spacing improvement objectives.

Comment on lines +33 to +39
const { enumOptions, enumDisabled } = options;
const [selectedLabel, setSelectedLabel] = useState(placeholder);

// const emptyValue = multiple ? [] : "";
const getCurrentLabel = () => {
const option = enumOptions?.find((opt: any) => opt.value === value);
return option ? option.label : placeholder;
};
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

Add type safety to enumOptions handling

The enumOptions handling lacks proper TypeScript types, which could lead to runtime errors.

-  const { enumOptions, enumDisabled } = options;
+  interface EnumOption {
+    value: string;
+    label: string;
+  }
+  const { enumOptions, enumDisabled } = options as { 
+    enumOptions?: EnumOption[];
+    enumDisabled?: string[];
+  };

-  const getCurrentLabel = () => {
-    const option = enumOptions?.find((opt: any) => opt.value === value);
+  const getCurrentLabel = () => {
+    const option = enumOptions?.find((opt: EnumOption) => opt.value === value);
     return option ? option.label : placeholder;
   };
📝 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
const { enumOptions, enumDisabled } = options;
const [selectedLabel, setSelectedLabel] = useState(placeholder);
// const emptyValue = multiple ? [] : "";
const getCurrentLabel = () => {
const option = enumOptions?.find((opt: any) => opt.value === value);
return option ? option.label : placeholder;
};
interface EnumOption {
value: string;
label: string;
}
const { enumOptions, enumDisabled } = options as {
enumOptions?: EnumOption[];
enumDisabled?: string[];
};
const [selectedLabel, setSelectedLabel] = useState(placeholder);
const getCurrentLabel = () => {
const option = enumOptions?.find((opt: EnumOption) => opt.value === value);
return option ? option.label : placeholder;
};

Comment on lines 46 to 56
const handleBlur = () => {
if (onBlur) {
onBlur(id, value);
}
};

const handleFocus = () => {
if (onFocus) {
onFocus(id, value);
}
};
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const handleBlur = () => {
if (onBlur) {
onBlur(id, value);
}
};
const handleFocus = () => {
if (onFocus) {
onFocus(id, value);
}
};
const handleBlur = () => onBlur?.(id, value);
const handleFocus = () => onFocus?.(id, value);

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 (3)
ui/src/components/SchemaForm/Widgets/SelectWidget.tsx (3)

24-31: Consider adding stricter TypeScript types for the props

While the component uses generics, some props could benefit from more specific types:

  • value could be constrained to match enumOption values
  • rawErrors could have a specific error type
>({
   id,
   options,
   disabled,
   readonly,
-  value,
+  value: string | number | null,
   onChange,
   onBlur,
   onFocus,
   placeholder,
-  rawErrors = [],
+  rawErrors: string[] = [],
}: WidgetProps<T, S, F>)

41-47: Optimize event handlers with useCallback

Consider memoizing the event handlers to prevent unnecessary re-renders of child components:

- const handleSelect = (value: any, label: string) => {
+ const handleSelect = useCallback((value: any, label: string) => {
    setSelectedLabel(label);
    onChange(value);
- };
+ }, [onChange]);

- const handleBlur = () => onBlur?.(id, value);
- const handleFocus = () => onFocus?.(id, value);
+ const handleBlur = useCallback(() => onBlur?.(id, value), [onBlur, id, value]);
+ const handleFocus = useCallback(() => onFocus?.(id, value), [onFocus, id, value]);

Line range hint 50-76: Enhance accessibility features

While using Radix UI provides good accessibility foundations, consider these improvements:

  • Add aria-label for the dropdown trigger
  • Add aria-invalid when there are errors
  • Consider adding aria-describedby for error messages
   <DropdownMenuTrigger
     className={`flex h-8 w-full items-center justify-between rounded border bg-background px-3 hover:bg-accent ${
       rawErrors.length > 0 ? "border-destructive" : ""
     }`}
     disabled={disabled || readonly}
+    aria-label={`Select ${placeholder}`}
+    aria-invalid={rawErrors.length > 0}
     onBlur={handleBlur}
     onFocus={handleFocus}>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ecd9b3 and 20437e0.

📒 Files selected for processing (1)
  • ui/src/components/SchemaForm/Widgets/SelectWidget.tsx (2 hunks)
🔇 Additional comments (3)
ui/src/components/SchemaForm/Widgets/SelectWidget.tsx (3)

33-34: Add type safety to enumOptions handling

The enumOptions handling still lacks proper TypeScript types, which could lead to runtime errors.


36-39: ⚠️ Potential issue

Potential state synchronization issue with selectedLabel

The selectedLabel state might get out of sync with the actual value when the value prop changes externally. Consider using a useEffect to update the selectedLabel when the value changes:

+ useEffect(() => {
+   const label = getCurrentLabel();
+   setSelectedLabel(label);
+ }, [value, enumOptions]);

Likely invalid or redundant comment.


33-39: Verify handling of null ofAny values

The PR mentions an issue with the ofAny function in react-jsonschema-form. Let's verify the handling of null values:

✅ Verification successful

Proper null handling is implemented in SelectWidget

The implementation correctly handles null/undefined values through:

  • Optional chaining on enumOptions?.find() and enumDisabled?.includes()
  • Fallback to placeholder when no option is found
  • Safe rendering with null checks in the template

The changes properly address the display issues by:

  1. Maintaining selected label state
  2. Providing fallback to placeholder for null values
  3. Safe iteration over options with proper null checks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ofAny usage and null handling
rg -A 5 "ofAny" 
rg -A 5 "const { enumOptions" 

Length of output: 157


Script:

#!/bin/bash
# Search for ofAny usage with proper escaping and context
rg -A 5 "ofAny\(" 

# Search for enumOptions with proper escaping
rg -A 5 "enumOptions.*=" 

# Search for SelectWidget implementations
ast-grep --pattern 'const SelectWidget = $_'

Length of output: 8832

@billcookie billcookie merged commit 5bab02a into main Dec 16, 2024
18 checks passed
@billcookie billcookie deleted the ui/investigate-fix-params-dropdown branch December 16, 2024 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants