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(site): fix floating number on duration fields #13209

Merged
merged 18 commits into from May 17, 2024
Merged

Conversation

BrunoQuaresma
Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma commented May 8, 2024

Demo about the new <DurationField /> component.

Screen.Recording.2024-05-08.at.14.11.24.mov

Storybook on Chromatic: https://624de63c6aacee003aa84340-wnakkqswca.chromatic.com/?path=/story/components-durationfield--hours

@BrunoQuaresma BrunoQuaresma self-assigned this May 8, 2024
@stirby
Copy link
Collaborator

stirby commented May 8, 2024

Related: #13071

Assuming this will interpret units when the page loads? Just wondering how it looks if I change the value via CLI.

Can we add a tooltip when "Days" is greyed out explaining why it's blocked?

"Set duration to a multiple of 24 hours to change units."

Copy link
Contributor

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

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

I think this looks good so far!
It actually reminds me of the component I built out for my Coder take-home, though obviously, using MUI simplifies the code a lot more compared to using HTML inputs

site/src/components/DurationField/DurationField.tsx Outdated Show resolved Hide resolved
site/src/components/DurationField/DurationField.tsx Outdated Show resolved Hide resolved
site/src/components/DurationField/DurationField.tsx Outdated Show resolved Hide resolved
site/src/components/DurationField/DurationField.tsx Outdated Show resolved Hide resolved
@Parkreiner
Copy link
Contributor

Parkreiner commented May 8, 2024

@stirby Yeah, the way the component is set up right now is that it will default to days whenever the numeric value originally passed in is cleanly divisible by 24 hours. Otherwise, it uses hours

@BrunoQuaresma
Copy link
Collaborator Author

@Parkreiner thanks for the review. Did you have time to play around with it in the storybook? I'm going to create tests for it after being sure the UX is good enough.

@BrunoQuaresma
Copy link
Collaborator Author

@Parkreiner after implementing this component into the form I realized you were right about two things:

  • It is better to only have the value as a number instead of having to deal with undefined.
  • We need to handle external value updates to avoid a wrong state in the time unit.
    🙏

@BrunoQuaresma
Copy link
Collaborator Author

@Parkreiner I updated the code a bit and would love a second round of review.

@stirby I would appreciate it if you could QA the "Time until dormant" field experience and let me know if it is an improvement compared to what we have.

A quick demo:

Screen.Recording.2024-05-09.at.14.10.41.mov

Copy link

github-actions bot commented May 9, 2024


✔️ PR 13209 Updated successfully.
🚀 Access the credentials here.

cc: @BrunoQuaresma

@Parkreiner
Copy link
Contributor

@BrunoQuaresma Have a couple of things to wrap up today, but at the very latest, I'll do a real round of review tomorrow morning

Copy link
Contributor

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

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

I think this looks really good!
I don't know how much more you need to update the code to get the failing tests to pass, but if you think they just need a few tiny tweaks, I can go ahead and approve, just to make sure you're not blocked

site/src/utils/time.ts Show resolved Hide resolved
site/src/components/DurationField/DurationField.tsx Outdated Show resolved Hide resolved
site/src/components/DurationField/DurationField.tsx Outdated Show resolved Hide resolved
site/src/components/DurationField/DurationField.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

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

Okay, cool – approving

@stirby
Copy link
Collaborator

stirby commented May 10, 2024

@BrunoQuaresma, few things.

I like the improved error tooltip, but it seems to appear only under certain conditions:

Screen.Recording.2024-05-10.at.11.58.41.AM.mov

It seems like if I enter an incorrect value right after switching units, the error appears. I'm also able to sometimes apply the float values, but it uses the integer.

Can we change the conditional to be more consistent? IE showing up any time there's an incorrect value?

Also:

  • Should we make the entry box fill the width like the old one?
  • Could we apply it to the other options?

ui_component_dormancy

Looks great otherwise, nice work.

@BrunoQuaresma
Copy link
Collaborator Author

@stirby I would appreciate another QA round. I updated the preview with the latest changes 🙏

Copy link
Collaborator

@stirby stirby 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, feels good. Did you remove the ability to enter decimals? I think it's a clean solution.

Would ask that @Parkreiner takes one more look.

@Parkreiner
Copy link
Contributor

@stirby Yeah, I can do another once-over in about an hour

Copy link
Contributor

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

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

Yup, I think the component's in a good spot now

</div>

{helperText && (
<FormHelperText error={props.error}>{helperText}</FormHelperText>
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there a reason why props.error wasn't destructured from the props at the top of the component?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it is used by the TextField props as well.

Comment on lines +48 to +53
if (
action.unit === "days" &&
!canConvertDurationToDays(currentDurationMs)
) {
return state;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just making sure: this is just a precaution/double-bookkeeping, right? Even though the UI has the disabled check to prevent the days unit from being selected at certain points, the reducer is also enforcing that the state update can't go through, in case the UI is set up wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think it can be useful to have it in the reducer + disabled attribute. Wdyt?

@BrunoQuaresma BrunoQuaresma marked this pull request as ready for review May 17, 2024 18:25
@BrunoQuaresma BrunoQuaresma merged commit 4af0f09 into main May 17, 2024
33 checks passed
@BrunoQuaresma BrunoQuaresma deleted the bq/fix-float-input branch May 17, 2024 18:26
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants