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

Clear Release Code Number when Release Code Type is NONE_OPTION #467

Conversation

dmkirshon
Copy link
Contributor

@dmkirshon dmkirshon commented Dec 18, 2023

Add:

  • Handler for onValueChange Barcode Type Field prop so Barcode Number value is cleared on NONE_OPTION selection Type or Clearing the Type field.

Update:

  • Dropdown Select to handle onValueChange from Dropdown Select Field
  • Prop names to conform to "on" event handler convention

https://projectnewm.atlassian.net/browse/STUD-6

@dmkirshon dmkirshon self-assigned this Dec 18, 2023
Copy link

github-actions bot commented Dec 18, 2023

Visit the preview URL for this PR (updated for commit ca004dc):

https://newm-artist-portal--pr467-stud-6-clear-release-p03zsugk.web.app

(expires Thu, 15 Feb 2024 09:36:07 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: ec3483d4c62309afc398865bfd6a9fc9e03e1d46

@dmkirshon dmkirshon force-pushed the STUD-6_Clear-Release-Code-Number-field-when-Release-Code-Type-is-deselected_David-Kirshon branch from dbf4501 to b5509c6 Compare December 18, 2023 15:13
if (newValue === null || newValue === undefined) handleChange?.("");
else handleChange?.(newValue as string);
if (newValue === null || newValue === undefined) onValueChange?.("");
else onValueChange?.(newValue as string);
Copy link
Contributor

@scandycuz scandycuz Jan 9, 2024

Choose a reason for hiding this comment

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

The formatting here seems strange, haven't seen an if/else statement written this way before. Omitting brackets for single lines can be useful, but in this case, using the standard approach seems more conventional and readable. E.g.

if (newValue === null || newValue === undefined) {
  onValueChange?.("");
} else {
  onValueChange?.(newValue as string);
}

Copy link
Contributor

@scandycuz scandycuz Jan 9, 2024

Choose a reason for hiding this comment

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

I haven't tested it, but this seems like it could also work:

onValueChange?.(newValue ?? "")

Copy link
Contributor Author

@dmkirshon dmkirshon Jan 10, 2024

Choose a reason for hiding this comment

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

Updating to use the nullish coalescing operator ??

@dmkirshon dmkirshon requested a review from scandycuz January 10, 2024 09:18
Copy link
Contributor

@scandycuz scandycuz left a comment

Choose a reason for hiding this comment

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

Looking good but had a comment.

scandycuz
scandycuz previously approved these changes Jan 11, 2024
@scandycuz scandycuz dismissed their stale review January 11, 2024 07:07

One minor update

Copy link
Contributor

@scandycuz scandycuz left a comment

Choose a reason for hiding this comment

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

LGTM, but had some comments.

// Call the onChange from the Dropdown Select Field
if (typeof props.onValueChange === "function") {
props.onValueChange(newValue);
}
Copy link
Contributor

@scandycuz scandycuz Jan 11, 2024

Choose a reason for hiding this comment

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

The one change I'd make is to remove this call to props.onValueChange. E.g just:

onValueChange={ form.handleChange(props.name) }

I think that onValueChange (or potentially onChangeValue) is a better name than handleChange, since it starts with on, but the prop can essentially just do the same thing that the handleChange prop was doing, which was to serve as an alernative prop that accepts a string instead of an event. I don't believe there is a use case where it would be passed to the DropdownSelectField component.

Copy link
Contributor

@scandycuz scandycuz Jan 11, 2024

Choose a reason for hiding this comment

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

Also, changing the handleBlur prop name to onBlur overrides the field.onBlur prop, however, field.onBlur and form.handleBlur appear to be the same, in which case it should be possible to omit it. The full field component would just be:

const DropdownSelectField: ForwardRefRenderFunction<
  HTMLInputElement,
  DropdownSelectProps
> = (props, ref) => (
  <Field name={ props.name }>
    { ({ field, form, meta }: FieldProps) => (
      <DropdownSelect
        { ...field }
        { ...props }
        ref={ ref }
        errorMessage={ meta.touched ? meta.error : "" }
        onChangeValue={ form.handleChange(props.name) }
      />
    ) }
  </Field>
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the changes and don't see any issues cropping up, good call. I think some of it was left over from previous issues or how the trigger events were being handled in connection with the DropdownSelect.tsx component

@@ -5,19 +5,29 @@ import DropdownSelect, { DropdownSelectProps } from "../DropdownSelect";
const DropdownSelectField: ForwardRefRenderFunction<
HTMLInputElement,
DropdownSelectProps
Copy link
Contributor

@scandycuz scandycuz Jan 11, 2024

Choose a reason for hiding this comment

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

In the future, we could probably update the props for the field component to be more accurate as to which props it accepts, as apposed to just all of the DropdownSelectProps. For example, the onChange, onBlur, and onChangeValue props should be ommited since they wouldn't actually be passed to it and are instead handled internally using Formik.

Copy link
Contributor Author

@dmkirshon dmkirshon Jan 12, 2024

Choose a reason for hiding this comment

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

I updated the two component interfaces, it was bothering me too, let me know if it doesn't match up with what you envisioned.

We will need to update the other field/input components when they are touched. I believe they follow the same prop sharing pattern that you noted.

Edit: Had to update the interface reference for DropdownMultiSelect.tsx since it shared the DropdownSelect.tsx interface as well. We can clean up that components interface in a separate tasking as stated above.

@dmkirshon dmkirshon requested a review from scandycuz January 12, 2024 13:00
@dmkirshon dmkirshon force-pushed the STUD-6_Clear-Release-Code-Number-field-when-Release-Code-Type-is-deselected_David-Kirshon branch from 0c5a532 to da1487b Compare January 12, 2024 13:16
{ ...props }
errorMessage={ meta.touched ? meta.error : "" }
ref={ ref }
onChangeValue={ form.handleChange(props.name) }
Copy link
Contributor

@scandycuz scandycuz Jan 12, 2024

Choose a reason for hiding this comment

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

It's looking great, but had just one last suggestion. I was realizing that although this works for our needs, since we're always using the DropdownSelect field with Formik, it could be confusing if a user was using it as a standalone controlled component, as they would have to know to pass an onChangeValue prop to the component instead of anonChange prop.

I was looking at the MUI docs for their AutoComplete component to see how they handled it, and it looks like they just define the onChange prop for the component as having the same definition as the onChange prop for useAutocomplete, which I think is a bit more straightforward. It would be good to match that functionality, just for completeness. The updated code would look like:

// DropdownSelectField.tsx

...

export interface DropdownSelectFieldProps {
  extends Omit<HTMLProps<HTMLInputElement>, "as" | "ref" | "onChange"> {
  ...
}

...

const DropdownSelectField: ForwardRefRenderFunction<
  HTMLInputElement,
  DropdownSelectFieldProps
> = (props, ref) => {
  return (
    <Field name={ props.name }>
      { ({ field, form, meta }: FieldProps) => (
        <DropdownSelect
          { ...field }
          { ...props }
          errorMessage={ meta.touched ? meta.error : "" }
          ref={ ref }
          onChange={ (event, newValue) => {
            form.handleChange(props.name)(newValue);
          } }
        />
      ) }
    </Field>
  );
};

...
// DropdownSelect.tsx
...
interface DropdownSelectProps extends DropdownSelectFieldProps {
  readonly errorMessage?: string;
  readonly onChange?: (
    event: SyntheticEvent<Element, Event>,
    newValue: string
  ) => void;
}

...

const DropdownSelect: ForwardRefRenderFunction<
  HTMLInputElement,
  DropdownSelectProps
> = (
  {
    ...
    onChange,
  },
  ref: ForwardedRef<HTMLInputElement>
) => {
  } = useAutocomplete({
    ...
    onChange: (event, newValue) => {
      onChange?.(event, newValue ?? "");
    },
    ...
  });
  ...
}

...

@dmkirshon dmkirshon requested a review from scandycuz January 16, 2024 09:28
Copy link
Contributor

@scandycuz scandycuz left a comment

Choose a reason for hiding this comment

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

LGTM!

@dmkirshon dmkirshon merged commit 6207d25 into master Jan 17, 2024
3 checks passed
@dmkirshon dmkirshon deleted the STUD-6_Clear-Release-Code-Number-field-when-Release-Code-Type-is-deselected_David-Kirshon branch January 17, 2024 06:30
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