Dashboards: Allow custom quick time ranges specified in dashboard model (#93724)

* TimeRangePicker: allow to customize quick ranges per dashboard

* TimeRangePicker: show selected custom time range using its name

* rangeutil: add tests for describeTextRange + quickRanges

* Fix up tests, and add an extra case for hidden time ranges

* Don't construct an object to find options, add findRangeInOptions util

* fix type errors detected by TypeScript

---------

Co-authored-by: joshhunt <josh@trtr.co>
This commit is contained in:
Sergey Naumov
2025-02-04 14:36:28 +00:00
committed by GitHub
co-authored by joshhunt
parent cfae9d20d2
commit eb2f8182c0
10 changed files with 96 additions and 28 deletions
+14
View File
@@ -29,6 +29,18 @@ const (
DashboardCursorSyncTooltip DashboardCursorSync = 2
)
// Counterpart for TypeScript's TimeOption type.
type TimeOption struct {
Display string `json:"display"`
From string `json:"from"`
To string `json:"to"`
}
// NewTimeOption creates a new TimeOption object.
func NewTimeOption() *TimeOption {
return &TimeOption{}
}
// Time picker configuration
// It defines the default config for the time picker and the refresh picker for the specific dashboard.
type TimePickerConfig struct {
@@ -38,6 +50,8 @@ type TimePickerConfig struct {
RefreshIntervals []string `json:"refresh_intervals,omitempty"`
// Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard.
TimeOptions []string `json:"time_options,omitempty"`
// Quick ranges for time picker.
QuickRanges []TimeOption `json:"quick_ranges,omitempty"`
// Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values.
NowDelay *string `json:"nowDelay,omitempty"`
}