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(datetime): add dev warnings when setting out of bounds value #25513

Merged
merged 6 commits into from
Jun 22, 2022

Conversation

averyjohnston
Copy link
Contributor

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Originally, assigning a value to ion-datetime that's sufficiently earlier than the min or later than the max would lead to a disabled month being displayed, and the user being unable to navigate in either direction. This was mostly resolved here #25351 since both assigning a value and leaving it to the default go through the processValue function. The dev experience just needs some polish.

Issue URL: #24881

What is the new behavior?

Console warnings for out-of-bounds values are now printed when either assigning an initial value, or updating it programmatically.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Tests for console warnings have been flaky in the past, so I didn't include one. I did add a test to ensure an in-bounds month is displayed, though, since the existing tests only cover datetimes with no initial value.

@averyjohnston averyjohnston requested a review from a team as a code owner June 21, 2022 18:17
@github-actions github-actions bot added the package: core @ionic/core package label Jun 21, 2022
@averyjohnston averyjohnston removed the request for review from a team June 21, 2022 19:53
Copy link
Contributor

@sean-perkins sean-perkins left a comment

Choose a reason for hiding this comment

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

Tested locally and it does exactly what it needs to do. Great work 👍 I agree that adding tests for the contents of the warning message has been flaky and does not introduce value here.

~ Would there be any value to the developer if the warning message included the values back to them? For example:

[Ionic Warning]: The value (2021-05-01) passed to ion-datetime is earlier than the min (2021-06-01) or later than the max (2021-10).

or:

[Ionic Warning]: The value passed to ion-datetime is earlier than the min or later than the max. { min: "2021-06-01", value: "2021-05-01", max: "2021-06-30" }

Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

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

Good to go once the comment below is addressed

core/src/components/datetime/test/minmax/datetime.e2e.ts Outdated Show resolved Hide resolved
@liamdebeasi
Copy link
Contributor

Tested locally and it does exactly what it needs to do. Great work 👍 I agree that adding tests for the contents of the warning message has been flaky and does not introduce value here.

~ Would there be any value to the developer if the warning message included the values back to them? For example:

[Ionic Warning]: The value (2021-05-01) passed to ion-datetime is earlier than the min (2021-06-01) or later than the max (2021-10).

or:

[Ionic Warning]: The value passed to ion-datetime is earlier than the min or later than the max. { min: "2021-06-01", value: "2021-05-01", max: "2021-06-30" }

If it's not too hard, I think it would provide for a nice DX to have a more specific message.

Could do something like this:

[Ionic Warning]: The value provided to ion-datetime is out of bounds.

Max Date: 2021-04-25
Min Date: 2021-06-01
Value: 2021-03-01

At least for me, listing the values on separate lines makes the warning easy to scan.

@sean-perkins
Copy link
Contributor

Agreed, I was thinking just use the second argument of console.warn to pass an object of the min, max and value.

@averyjohnston
Copy link
Contributor Author

I like that multiline formatting 👀 I'll pull it into a separate util too.

@averyjohnston
Copy link
Contributor Author

I went with logging the min/max/value as stringified objects, so we don't have to worry about date formatting across locales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants