Skip to content

area/ui: Support typing multiple units in relative range picker#5006

Merged
yomete merged 3 commits into
mainfrom
relative-multiple-units
Sep 12, 2024
Merged

area/ui: Support typing multiple units in relative range picker#5006
yomete merged 3 commits into
mainfrom
relative-multiple-units

Conversation

@yomete
Copy link
Copy Markdown
Contributor

@yomete yomete commented Aug 22, 2024

Fixes #4986

@yomete yomete requested a review from a team as a code owner August 22, 2024 08:36
@alwaysmeticulous
Copy link
Copy Markdown

alwaysmeticulous Bot commented Aug 22, 2024

🤖 Meticulous spotted visual differences in 2 of 637 screens tested: view and approve differences detected.

Last updated for commit b03417a. This comment will update as new commits are pushed.

@yomete yomete changed the title area/ui: Support typing multiple units in relative range picker (wip) area/ui: Support typing multiple units in relative range picker Aug 22, 2024
Copy link
Copy Markdown
Member

@metalmatze metalmatze left a comment

Choose a reason for hiding this comment

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

Looks really good!
I wonder if our life could be easier if this abstraction could simple work on seconds or milliseconds (which is what JS uses) rather than floating point numbers? Maybe I'm missing some context and what I'm saying doesn't make sense.


describe('parseInput', () => {
it('should parse single unit inputs correctly', () => {
expect(parseInput('30s')).toEqual({value: 30, unit: UNITS.SECOND});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's going to happen for something like 90s vs 1m30s? Are both parsed as 90s?

Suggested change
expect(parseInput('30s')).toEqual({value: 30, unit: UNITS.SECOND});
expect(parseInput('90s')).toEqual({value: 90, unit: UNITS.SECOND});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good questions.

To answer the test question (and maybe the first one) internally, and as a request to the backend they are both processed and parsed as 90s but in the UI component, it will be parsed as 1m30s, and this is because the logic favours the higher unit over the lower ones.

Regarding the suggestion to work with seconds or milliseconds instead of floating-point numbers, the floating point numbers are only being used to format the human readable text that shows up in the RelativeDatepicker component. This allows us to preserve the user's input format when possible. But as mentioned, we still send the timerange in milliseconds to the backend.

If you think there might be advantages to using milliseconds throughout the entire component, I'm open to discussing potential improvements or alternative implementations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't have a strong opinion on how it gets represented internally. I was thinking that maybe there was an easier way. Seems like it's already pretty good, so please ignore my suggestion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feel free to merge this as is too.

@yomete yomete merged commit 81c6cc7 into main Sep 12, 2024
@yomete yomete deleted the relative-multiple-units branch November 7, 2024 13:17
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.

area/ui: The relative rangepicker does not support typing in multiple units

2 participants