mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix: when reloading page make sure that time picker history is converted to dateTime.
This commit is contained in:
parent
ea3d368e91
commit
d227353321
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { LocalStorageValueProvider } from '../LocalStorageValueProvider';
|
||||
import { TimeRange, isDateTime } from '@grafana/data';
|
||||
import { TimeRange, isDateTime, dateTime } from '@grafana/data';
|
||||
import { Props as TimePickerProps, TimePicker } from '@grafana/ui/src/components/TimePicker/TimePicker';
|
||||
|
||||
const LOCAL_STORAGE_KEY = 'grafana.dashboard.timepicker.history';
|
||||
@ -14,7 +14,7 @@ export const TimePickerWithHistory: React.FC<Props> = props => {
|
||||
return (
|
||||
<TimePicker
|
||||
{...props}
|
||||
history={values}
|
||||
history={convertIfJson(values)}
|
||||
onChange={value => {
|
||||
onAppendToHistory(value, values, onSaveToStore);
|
||||
props.onChange(value);
|
||||
@ -25,6 +25,21 @@ export const TimePickerWithHistory: React.FC<Props> = props => {
|
||||
</LocalStorageValueProvider>
|
||||
);
|
||||
};
|
||||
|
||||
function convertIfJson(history: TimeRange[]): TimeRange[] {
|
||||
return history.map(time => {
|
||||
if (isDateTime(time.from)) {
|
||||
return time;
|
||||
}
|
||||
|
||||
return {
|
||||
from: dateTime(time.from),
|
||||
to: dateTime(time.to),
|
||||
raw: time.raw,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function onAppendToHistory(toAppend: TimeRange, values: TimeRange[], onSaveToStore: (values: TimeRange[]) => void) {
|
||||
if (!isAbsolute(toAppend)) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user