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

TimeRangePicker: Fix recently ranges only not showing all recent ranges #59836

Merged
merged 6 commits into from Dec 9, 2022

Conversation

joshhunt
Copy link
Contributor

@joshhunt joshhunt commented Dec 5, 2022

What is this feature?

  • Fixes an issue where if you had three saved time ranges, it would only show one.
  • Prevents duplicate time ranges from being stored in the history.
  • Refactors the JSON saved to local storage to be simpler { to: string, from: string } objects, rather than TimeRage items

TimePickerWithHistory 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:

@@ -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));
Copy link
Contributor Author

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.

@joshhunt
Copy link
Contributor Author

joshhunt commented Dec 5, 2022

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.

@joshhunt joshhunt force-pushed the joshhunt/time-range-picker-history-refactor branch from 904c21f to f02958f Compare December 7, 2022 13:17
@joshhunt joshhunt marked this pull request as ready for review December 8, 2022 15:17
@joshhunt joshhunt requested a review from a team December 8, 2022 15:17
@joshhunt joshhunt requested review from a team as code owners December 8, 2022 15:17
@joshhunt joshhunt requested review from oscarkilhed, zoltanbedi, ashharrison90 and JoaoSilvaGrafana and removed request for a team December 8, 2022 15:17
/>
</section>
</FocusScope>
<div>
Copy link
Contributor Author

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....

Copy link
Contributor

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 🤔

Copy link
Contributor Author

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', () => {
Copy link
Contributor Author

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 😅

Copy link
Contributor

@ashharrison90 ashharrison90 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, think we should just swap the FocusScope/section and remove the div 👍

@joshhunt joshhunt merged commit 6280780 into main Dec 9, 2022
@joshhunt joshhunt deleted the joshhunt/time-range-picker-history-refactor branch December 9, 2022 11:28
grafanabot pushed a commit that referenced this pull request Dec 9, 2022
* 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)
@joshhunt joshhunt changed the title TimeRangePicker: Fix recent ranges not showing all items TimeRangePicker: Fix recently ranges only not showing all recent ranges Dec 9, 2022
joshhunt added a commit that referenced this pull request Dec 9, 2022
…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>
GuYounes pushed a commit to paul-wurth/BIXpert that referenced this pull request Feb 8, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants