Skip to content

Conversation

@bnussman-akamai
Copy link
Member

Description 📝

  • Makes errors that are notices scroll into view on the Linode Create flow ⛔️

Preview 📷

Screen.Recording.2024-05-09.at.4.53.39.PM.mov

How to test 🧪

Prerequisites

  • Turn on Linode Create v2 flag using local dev tools 🏴

Verification steps

  • Verify all errors scroll into view ↕️
  • Test error states in general 👀

As an Author I have considered 🤔

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@bnussman-akamai bnussman-akamai self-assigned this May 9, 2024
@bnussman-akamai bnussman-akamai marked this pull request as ready for review May 13, 2024 14:37
@bnussman-akamai bnussman-akamai requested a review from a team as a code owner May 13, 2024 14:37
@bnussman-akamai bnussman-akamai requested review from cpathipa and dwiley-akamai and removed request for a team May 13, 2024 14:37
Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

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

The error handling works well!

I know you're probably trying to keep the scope small and handle error handling for the linode create v2 only - can't help but wonder how this will scale when trying to implement more forms with react-hook-forms. It's a lot of ref business which can get a little overwhelming from a developer persepctive.

Not that i have a better solution to suggest, just wanted to raise the thought. I was also working with refs on a POC for the formik error handling (it's far more constraining since it's already implemented everywhere those are field errors which react-hook-forms already handles well), but perhaps there's something to explore here too about parsing a larger ref (aka a form container) for errors. Again, not saying it's better than what you propose here, just trying to add water to the well

@github-actions
Copy link

github-actions bot commented May 14, 2024

Coverage Report:
Base Coverage: 81.55%
Current Coverage: 81.55%

Copy link
Contributor

@dwiley-akamai dwiley-akamai left a comment

Choose a reason for hiding this comment

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

When the password complexity doesn't meet the minimum requirement, the error doesn't get scrolled into view:

Video
Screen.Recording.2024-05-15.at.11.19.45.AM.mov

@bnussman-akamai
Copy link
Member Author

I re-requested reviews because scrolling errors into view works as expected using a new temporary solution. When we decide on a new util, we can adopt it here later. Just trying to keep this effort moving

@jcallahan-akamai jcallahan-akamai removed the request for review from cpathipa May 21, 2024 15:04
Copy link
Contributor

@dwiley-akamai dwiley-akamai left a comment

Choose a reason for hiding this comment

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

The scrolling of errors into view looked good across the board from my testing ✅
Code review ✅

@abailly-akamai abailly-akamai force-pushed the M3-8092-linode-create-refactor-scroll-to-errors branch from aad32a3 to 1b11b25 Compare May 21, 2024 17:36
@abailly-akamai
Copy link
Contributor

@bnussman-akamai so here's the gist!

In react-hook-form, you can use the handleSubmit function to perform validation and then scroll to the error. The handleSubmit function takes two arguments: the first is the function to execute when the form is valid, and the second is the function to execute when the form is invalid.

I pushed a small fix to do it that way - please test and lemme know if we're at parity otherwise I'll revert it.

https://linode.github.io/manager/development-guide/05-fetching-data.html#scrolling-to-errors

Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

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

Looks good and works as expected! (granted i contributed, maybe another review could be useful)

defaultValues,
mode: 'onBlur',
resolver: linodeCreateResolvers[params.type ?? 'Distributions'],
shouldFocusError: false, // We handle this ourselves with `scrollErrorIntoView`
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we're at a place for an abstraction to load a default config, but perhaps something to consider as the plugin usage grow. Cause so far as i can understand, to achieve consistency in our forms we already have

mode: 'onBlur',
shouldFocusError: false,

as default values.

If not an abstraction, maybe an importable config down the line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think an improbable config is a good medium!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants