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
TimeRangePicker: Fix recently ranges only not showing all recent ranges #59836
Conversation
@@ -246,7 +245,8 @@ function mapToHistoryOptions(ranges?: TimeRange[], timeZone?: TimeZone): TimeOpt | |||
if (!Array.isArray(ranges) || ranges.length === 0) { | |||
return []; | |||
} | |||
return ranges.slice(ranges.length - 4).map((range) => mapRangeToTimeOption(range, timeZone)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing in a negative number returns the last n
items from the array. When there was 3 items in the array, this math would do ranges.slice(-1)
which would return only the last 1 item.
There's an outstanding issue where it appears the font size of the recently used time ranges has been increased (or caused by the switch to Inter), so they wrap onto two lines and the 4th item isn't shown. |
904c21f
to
f02958f
Compare
/> | ||
</section> | ||
</FocusScope> | ||
<div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get errors in tests when FocusScope doesn't have a wrapping div, but im not entirely sure why. This workaround isn't great....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we swap the order of FocusScope
and section
? then at least we don't have an extra element 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that works!
}, | ||
]; | ||
|
||
describe('ButtonSelect', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote theses tests to make sure that FocusScope wasn't entirely broken within jest, so they just came along for the ride 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, think we should just swap the FocusScope
/section
and remove the div
👍
* Fix not all recently used time ranges showing * Refactor time picker history to store simpler json objects * Don't store duplicate items * update todo tests: * Add tests for TimePickerWithHistory * better fix for focus scope issues in test (cherry picked from commit 6280780)
…0085) TimeRangePicker: Fix recent ranges not showing all items (#59836) * Fix not all recently used time ranges showing * Refactor time picker history to store simpler json objects * Don't store duplicate items * update todo tests: * Add tests for TimePickerWithHistory * better fix for focus scope issues in test (cherry picked from commit 6280780) Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com>
…afana#60085) TimeRangePicker: Fix recent ranges not showing all items (grafana#59836) * Fix not all recently used time ranges showing * Refactor time picker history to store simpler json objects * Don't store duplicate items * update todo tests: * Add tests for TimePickerWithHistory * better fix for focus scope issues in test (cherry picked from commit 6280780) Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com>
What is this feature?
{ to: string, from: string }
objects, rather thanTimeRage
itemsTimePickerWithHistory already limits the items saved to local storage to the most recent 4 items, so I don't believe there's a reason to also limit to 4 in the TimeRangeList component.
Related to / inspired by #54940
Special notes for your reviewer: