Commit d2273533 by Marcus Andersson Committed by GitHub

Fix: when reloading page make sure that time picker history is converted to dateTime.

parent ea3d368e
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment