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

Feat : integrated form composer with Searchable dropdown #1258

Open
wants to merge 2 commits into
base: sandbox-develop
Choose a base branch
from

Conversation

ashish-egov
Copy link
Contributor

No description provided.

Copy link
Contributor

coderabbitai bot commented Aug 8, 2024

Walkthrough

Walkthrough

The recent updates enhance the CustomWidgets.js file by refining the CustomDatePicker and CustomDropdown components for improved usability and design. New components, CheckBox and EnumBasedDropdown, leverage the react-select library, offering better dropdown functionality and flexibility. The FormComposer file has been streamlined to import these components, promoting modularity and maintainability across the application.

Changes

Files Change Summary
.../CustomWidgets.js Enhanced CustomDatePicker with improved styling; updated CustomDropdown to use react-select with new event handling and custom styles.
.../hoc/FormComposer/CheckBox.js, .../components/organisms/FormComposer/CheckBox.js Introduced a new reusable CheckBox component, supporting checked state management and improved accessibility.
.../hoc/FormComposer/EnumBasedDropdown.js, .../components/organisms/FormComposer/EnumBasedDropdown.js Added a new EnumBasedDropdown component that utilizes react-select for dropdowns based on enum values, enhancing user interface and functionality.
.../hoc/FormComposer/index.js, .../components/organisms/FormComposer/index.js Refactored FormComposer to import CheckBox and EnumBasedDropdown, improving modularity and reducing complexity.

Poem

In a garden of code where widgets bloom,
A date picker dances, dispelling the gloom.
Checkboxes hop and dropdowns flourish bright,
With styles so lovely, they bring pure delight.
Modular changes, now easy to find,
A rabbit’s delight, with a hop and a bind! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

Outside diff range, codebase verification and nitpick comments (6)
micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/CheckBox.js (1)

11-11: Consider using relative units for consistent styling.

Using vh and vw for dimensions might lead to inconsistent sizes across different screen sizes. Consider using rem or em for better consistency.

11c11
<                 style={{ width: '2vh', height: '2vw' }}
---
>                 style={{ width: '1rem', height: '1rem' }}
micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/EnumBasedDropdown.js (2)

10-31: Ensure consistency in styling units.

Consider using consistent units like rem for all dimensions to ensure uniformity across different screen sizes.

23c23
<             border: '0.063rem solid #787878',
---
>             border: '1px solid #787878',

33-37: Clarify the purpose of option formatting with a comment.

Add a comment to explain why options are formatted in this way.

33c33
<     // Convert enum values to the format expected by react-select
---
>     // Format options to match the `react-select` expected structure
micro-frontends/sandbox-ui/packages/components/src/CustomWidgets.js (3)

10-24: Ensure consistent use of styling units.

For consistency, consider using rem for all dimensions and spacing.

21c21
<         border: '0.063rem solid #787878',
---
>         border: '1px solid #787878',

43-45: Clarify the purpose of the handleChange function with a comment.

Add a comment to explain the logic behind extracting the value from selectedOption.

43c43
<     const handleChange = (selectedOption) => {
---
>     // Extract value from selected option and trigger onChange

70-74: Clarify the purpose of option formatting with a comment.

Add a comment to explain why options are formatted in this way.

70c70
<     // Convert options to the format expected by react-select
---
>     // Format options to match the `react-select` expected structure
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9db0b93 and 7ba2896.

Files ignored due to path filters (1)
  • micro-frontends/sandbox-ui/package.json is excluded by !**/*.json
Files selected for processing (4)
  • micro-frontends/sandbox-ui/packages/components/src/CustomWidgets.js (2 hunks)
  • micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/CheckBox.js (1 hunks)
  • micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/EnumBasedDropdown.js (1 hunks)
  • micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/index.js (2 hunks)
Additional context used
Path-based instructions (4)
micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/CheckBox.js (1)

Pattern **/*.js: check

micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/EnumBasedDropdown.js (1)

Pattern **/*.js: check

micro-frontends/sandbox-ui/packages/components/src/CustomWidgets.js (1)

Pattern **/*.js: check

micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/index.js (1)

Pattern **/*.js: check

Additional comments not posted (8)
micro-frontends/sandbox-ui/packages/components/src/hoc/FormComposer/index.js (8)

8-9: Imports look good.

The imports for EnumBasedDropdown and CheckBox are correctly added, enhancing modularity.


Line range hint 60-109:
Array field rendering logic is correct.

The RenderArrayField component correctly handles array fields using useFieldArray. The button styles and logic for adding/removing fields are well implemented.


Line range hint 111-127:
Recursion in findUIDependencies is well implemented.

The function correctly handles the recursive search for UI dependencies within the schema.


Line range hint 129-141:
Dependent field rendering logic is sound.

The RenderDependentField component correctly handles rendering fields based on dependencies.


Line range hint 143-204:
Field rendering logic is comprehensive.

The RenderField component effectively handles various field types, integrating well with other components.


Line range hint 206-334:
Form composition logic is robust.

The FormComposer component effectively manages form composition, including handling dependencies and form submission.


Line range hint 336-348:
Card component styling is appropriate.

The Card component provides a well-styled container for form fields, enhancing the UI.


Line range hint 33-57:
Verify integration of EnumBasedDropdown and CheckBox.

Ensure that the EnumBasedDropdown and CheckBox components are functioning as expected within the RenderIndividualField component.

Verification successful

Integration of EnumBasedDropdown and CheckBox Verified

The EnumBasedDropdown and CheckBox components are correctly integrated and used within the RenderIndividualField component. No issues were found with their usage.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `EnumBasedDropdown` and `CheckBox` components.

# Test: Search for the usage of `EnumBasedDropdown` and `CheckBox` in the codebase. Expect: Proper usage and no errors.
rg --type js 'EnumBasedDropdown|CheckBox'

Length of output: 10916

Comment on lines 3 to 15
export const CheckBox = ({ checked, onChange, label }) => {
return (
<label style={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}>
{label}
<input
type="checkbox"
checked={checked}
onChange={onChange}
style={{ width: '2vh', height: '2vw' }}
/>
</label>
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhance accessibility with htmlFor and id attributes.

To improve accessibility, associate the <label> with the <input> using htmlFor and id attributes.

3c3
< export const CheckBox = ({ checked, onChange, label }) => {
---
> export const CheckBox = ({ checked, onChange, label, id }) => {
5c5
<         <label style={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}>
---
>         <label htmlFor={id} style={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}>
11c11
<                 type="checkbox"
---
>                 id={id} type="checkbox"
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
export const CheckBox = ({ checked, onChange, label }) => {
return (
<label style={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}>
{label}
<input
type="checkbox"
checked={checked}
onChange={onChange}
style={{ width: '2vh', height: '2vw' }}
/>
</label>
);
};
export const CheckBox = ({ checked, onChange, label, id }) => {
return (
<label htmlFor={id} style={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}>
{label}
<input
id={id} type="checkbox"
checked={checked}
onChange={onChange}
style={{ width: '2vh', height: '2vw' }}
/>
</label>
);
};

Copy link
Collaborator

@jagankumar-egov jagankumar-egov left a comment

Choose a reason for hiding this comment

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

we already have dropdown component
https://unified-dev.digit.org/storybook/?path=/story/atoms-dropdown--dropdown
syncup with swathi if needed

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

Outside diff range, codebase verification and nitpick comments (5)
micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/CheckBox.js (2)

5-6: Improve accessibility by associating the label with the checkbox.

Consider adding an id to the input and using a htmlFor attribute in the label for better accessibility.

+ const id = `checkbox-${label.replace(/\s+/g, '-').toLowerCase()}`;

  return (
    <label htmlFor={id} style={{ display: 'flex', flexDirection: 'column', alignItems: 'start' }}>
      {label}
      <input
        type="checkbox"
        id={id}
        checked={checked}
        onChange={onChange}
        style={{ width: '2vh', height: '2vw' }}
      />
    </label>
  );

11-11: Review the styling units for consistency.

Using vh and vw for width and height can lead to inconsistent sizing across different screen sizes. Consider using rem or px for more predictable sizing.

- style={{ width: '2vh', height: '2vw' }}
+ style={{ width: '16px', height: '16px' }}
micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/EnumBasedDropdown.js (2)

5-8: Add prop validation for better maintainability.

Consider using PropTypes to validate the props passed to the component. This helps in catching bugs and improving code readability.

import PropTypes from 'prop-types';

EnumBasedDropdown.propTypes = {
  options: PropTypes.arrayOf(PropTypes.string).isRequired,
  value: PropTypes.string.isRequired,
  onChange: PropTypes.func.isRequired,
};

10-31: Consider externalizing styles for better reusability.

The custom styles defined in the component can be moved to a separate stylesheet or a style object outside the component to enhance reusability and maintainability.

const customStyles = {
  control: (base) => ({
    ...base,
    width: '100%',
    boxSizing: 'border-box',
    paddingLeft: 0,
    outline: '0.125rem solid transparent',
    outlineOffset: '0.125rem',
    height: '2.5rem',
    backgroundColor: '#fff',
    fontStyle: 'normal',
    fontFamily: 'Roboto',
    fontSize: '1rem',
    border: '0.063rem solid #787878',
    color: '#363636',
    lineHeight: '1.5rem',
    borderRadius: 0,
  }),
  valueContainer: (base) => ({
    ...base
  })
};
micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/index.js (1)

583-584: Ensure the submit button is consistently styled.

The submit button outside the conditional layout logic lacks styling. Ensure it matches the style of other buttons for a consistent user experience.

- {!submitHandler && <button type="submit">Submit</button>}
+ {!submitHandler && <button type="submit" style={buttonStyles}>Submit</button>}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ba2896 and 2be840e.

Files selected for processing (3)
  • micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/CheckBox.js (1 hunks)
  • micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/EnumBasedDropdown.js (1 hunks)
  • micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/index.js (6 hunks)
Additional context used
Path-based instructions (3)
micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/CheckBox.js (1)

Pattern **/*.js: check

micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/EnumBasedDropdown.js (1)

Pattern **/*.js: check

micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/index.js (1)

Pattern **/*.js: check

Additional comments not posted (2)
micro-frontends/sandbox-ui/packages/components/src/components/organisms/FormComposer/index.js (2)

316-316: Ensure consistent parameter formatting.

The parameter formatting change is minor but helps improve readability. Ensure this consistency is maintained throughout the codebase.


544-565: Consider extracting button rendering logic for better readability.

Similar to the previous section, extracting the button rendering logic into a separate function or component can reduce duplication and improve readability.

Comment on lines +472 to +493
{!(uiLayout?.hideTabNavigateButtons) && <>
{currentTab > 0 && (
<Button
label="Previous"
onClick={() => setCurrentTab((prev) => prev - 1)}
style={buttonStyles}
/>
)}
{currentTab < uiLayout?.layouts.length - 1 && (
<Button
label="Next"
onClick={() => setCurrentTab((prev) => prev + 1)}
style={buttonStyles}
/>
)}
{currentTab === uiLayout?.layouts.length - 1 && (
<Button
label="Submit"
type="submit"
style={buttonStyles}
/>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting button rendering logic for better readability.

The logic for rendering navigation buttons is repeated. Consider extracting it into a separate function or component to reduce duplication and improve readability.

const renderNavigationButtons = (currentTab, uiLayout, buttonStyles, setCurrentTab) => (
  <>
    {currentTab > 0 && (
      <Button
        label="Previous"
        onClick={() => setCurrentTab((prev) => prev - 1)}
        style={buttonStyles}
      />
    )}
    {currentTab < uiLayout?.layouts.length - 1 && (
      <Button
        label="Next"
        onClick={() => setCurrentTab((prev) => prev + 1)}
        style={buttonStyles}
      />
    )}
    {currentTab === uiLayout?.layouts.length - 1 && (
      <Button
        label="Submit"
        type="submit"
        style={buttonStyles}
      />
    )}
  </>
);

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