mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeRangePicker: do not swap time ranges when to
is before from
(#78915)
This commit is contained in:
parent
65535a3b3f
commit
d28284c8f1
@ -111,6 +111,9 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
|
|
||||||
const variant = isSynced ? 'active' : isOnCanvas ? 'canvas' : 'default';
|
const variant = isSynced ? 'active' : isOnCanvas ? 'canvas' : 'default';
|
||||||
|
|
||||||
|
const isFromAfterTo = value?.to?.isBefore(value.from);
|
||||||
|
const timePickerIcon = isFromAfterTo ? 'exclamation-triangle' : 'clock-nine';
|
||||||
|
|
||||||
const currentTimeRange = formattedRange(value, timeZone);
|
const currentTimeRange = formattedRange(value, timeZone);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -138,7 +141,7 @@ export function TimeRangePicker(props: TimeRangePickerProps) {
|
|||||||
})}
|
})}
|
||||||
aria-controls="TimePickerContent"
|
aria-controls="TimePickerContent"
|
||||||
onClick={onToolbarButtonSwitch}
|
onClick={onToolbarButtonSwitch}
|
||||||
icon="clock-nine"
|
icon={timePickerIcon}
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
variant={variant}
|
variant={variant}
|
||||||
>
|
>
|
||||||
|
@ -210,26 +210,26 @@ describe('timeSrv', () => {
|
|||||||
expect(time.to.valueOf()).toEqual(1410337650000);
|
expect(time.to.valueOf()).toEqual(1410337650000);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('corrects inverted from/to dates in ms', () => {
|
it('does not correct inverted from/to dates in ms', () => {
|
||||||
locationService.push('/d/id?from=1621436828909&to=1621436818909');
|
locationService.push('/d/id?from=1621436828909&to=1621436818909');
|
||||||
|
|
||||||
timeSrv = new TimeSrv(new ContextSrvStub());
|
timeSrv = new TimeSrv(new ContextSrvStub());
|
||||||
|
|
||||||
timeSrv.init(_dashboard);
|
timeSrv.init(_dashboard);
|
||||||
const time = timeSrv.timeRange();
|
const time = timeSrv.timeRange();
|
||||||
expect(time.from.valueOf()).toEqual(1621436818909);
|
expect(time.from.valueOf()).toEqual(1621436828909);
|
||||||
expect(time.to.valueOf()).toEqual(1621436828909);
|
expect(time.to.valueOf()).toEqual(1621436818909);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('corrects inverted from/to dates as relative times', () => {
|
it('does not correct inverted from/to dates as relative times', () => {
|
||||||
locationService.push('/d/id?from=now&to=now-1h');
|
locationService.push('/d/id?from=now&to=now-1h');
|
||||||
|
|
||||||
timeSrv = new TimeSrv(new ContextSrvStub());
|
timeSrv = new TimeSrv(new ContextSrvStub());
|
||||||
|
|
||||||
timeSrv.init(_dashboard);
|
timeSrv.init(_dashboard);
|
||||||
const time = timeSrv.timeRange();
|
const time = timeSrv.timeRange();
|
||||||
expect(time.raw.from).toBe('now-1h');
|
expect(time.raw.from).toBe('now');
|
||||||
expect(time.raw.to).toBe('now');
|
expect(time.raw.to).toBe('now-1h');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -70,22 +70,6 @@ export class TimeSrv {
|
|||||||
// remember time at load so we can go back to it
|
// remember time at load so we can go back to it
|
||||||
this.timeAtLoad = cloneDeep(this.time);
|
this.timeAtLoad = cloneDeep(this.time);
|
||||||
|
|
||||||
const range = rangeUtil.convertRawToRange(
|
|
||||||
this.time,
|
|
||||||
this.timeModel?.getTimezone(),
|
|
||||||
this.timeModel?.fiscalYearStartMonth
|
|
||||||
);
|
|
||||||
|
|
||||||
if (range.to.isBefore(range.from)) {
|
|
||||||
this.setTime(
|
|
||||||
{
|
|
||||||
from: range.raw.to,
|
|
||||||
to: range.raw.from,
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.refresh) {
|
if (this.refresh) {
|
||||||
this.setAutoRefresh(this.refresh);
|
this.setAutoRefresh(this.refresh);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user