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

refactor: add methods to make setting invalid overridable #4097

Merged
merged 4 commits into from
Jun 28, 2022

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Jun 27, 2022

Description

  • Added a protected method _shouldSetInvalid(invalid) that determines whether the invalid property should be updated to the given invalid state (by default: always true).
  • Added a protected method _setInvalid(invalid) that updates the invalid property to the given invalid state if it passes _shouldSetInvalid. This method is supposed to be used by the web components wherever they need to update invalid internally instead of manipulating the property directly.

The main purpose of _shouldSetInvalid is to make it possible later for Flow to prevent the web components from committing client-side validation success: the final decision on whether a component is valid will be made by the server.

Part of #4081

Type of change

  • Internal

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen vursen changed the title refactor: refactor: add protected methods for controlling validation result commitment Jun 27, 2022
@vursen vursen changed the title refactor: add protected methods for controlling validation result commitment refactor: add methods for controlling validation result commitment Jun 27, 2022
@vursen vursen changed the base branch from master to feat/validated-event June 27, 2022 06:49
@vursen vursen force-pushed the refactor/commit-validation-result branch 2 times, most recently from 4facd4e to 6118dde Compare June 27, 2022 07:12
Base automatically changed from feat/validated-event to master June 27, 2022 09:00
@DiegoCardoso
Copy link
Contributor

The main purpose of _shouldCommitValidationResult is to make it possible for Flow to later prevent setting invalid to true on the client-side: only the server will decide when the validation is considered successful.

If I understood it correctly, it should be the other way around. The Flow counterpart should allow the web component to set invalid to true, but disallow it to set it back to false. (ping @yuriy-fix)

@vursen
Copy link
Contributor Author

vursen commented Jun 27, 2022

If I understood it correctly, it should be the other way around. The Flow counterpart should allow the web component to set invalid to true, but disallow it to set it back to false.

Ah, you are right 👍 . It is just a typo by the way. I corrected the description.

@vursen vursen force-pushed the refactor/commit-validation-result branch from 6118dde to b087222 Compare June 27, 2022 09:25
@vursen vursen changed the title refactor: add methods for controlling validation result commitment refactor: add methods for controlling the validation result commitment Jun 27, 2022
@vursen vursen force-pushed the refactor/commit-validation-result branch from b41eb21 to 7a71d4c Compare June 27, 2022 11:51
@vursen vursen marked this pull request as ready for review June 27, 2022 14:38
Copy link
Member

@web-padawan web-padawan left a comment

Choose a reason for hiding this comment

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

Would it make sense to simplify method names e.g. _shouldSetInvalid() and _setInvalid() to better describe what they do?

@vursen
Copy link
Contributor Author

vursen commented Jun 27, 2022

Would it make sense to simplify method names e.g. _shouldSetInvalid() and _setInvalid() to better describe what they do?

My concern at the beginning was that this naming might be confusing especially when you override shouldSetInvalid and then anyway set invalid on your own, but now when I think about that again, I see that the alternative naming brings more overhead than solves anything.

So I agree to use more straightforward naming. 👍 This way it will be in line with setFocused() and shouldSetFocus().

@vursen vursen force-pushed the refactor/commit-validation-result branch 2 times, most recently from 55a477a to 243acbf Compare June 28, 2022 05:23
@vursen vursen force-pushed the refactor/commit-validation-result branch from 243acbf to 5c55014 Compare June 28, 2022 05:29
@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vursen vursen changed the title refactor: add methods for controlling the validation result commitment refactor: add methods for controlling which invalid state can be set Jun 28, 2022
@vursen vursen changed the title refactor: add methods for controlling which invalid state can be set refactor: add methods for controlling setting the invalid state Jun 28, 2022
Copy link
Contributor

@DiegoCardoso DiegoCardoso left a comment

Choose a reason for hiding this comment

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

I have noticed that ErrorController implements setInvalid, but didn't check if it might affect the new behavior. Could you double check it?

@vursen vursen removed the request for review from yuriy-fix June 28, 2022 08:22
@vursen vursen requested a review from yuriy-fix June 28, 2022 08:23
@web-padawan
Copy link
Member

I have noticed that ErrorController implements setInvalid, but didn't check if it might affect the new behavior

The new method is actually in the ValidateMixin and it has nothing to do with controllers. Unlike mixins that wrap each other (and can override methods), controllers are separate objects that do not have this caveat.

@DiegoCardoso
Copy link
Contributor

The new method is actually in the ValidateMixin and it has nothing to do with controllers. Unlike mixins that wrap each other (and can override methods), controllers are separate objects that do not have this caveat.

Ah, right. I wasn't fully aware of the difference between mixins and controllers. Got it now, thanks.

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