mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
Explore: Fix TimeSrv initializations (#73903)
Ensure TimeSrv is re-initializes
This commit is contained in:
parent
557b1654f9
commit
291ca54010
@ -7,6 +7,13 @@ import { ExploreItemState } from 'app/types';
|
||||
import { createDefaultInitialState } from './helpers';
|
||||
import { changeRangeAction, timeReducer, updateTime } from './time';
|
||||
|
||||
const mockTimeSrv = {
|
||||
init: jest.fn(),
|
||||
};
|
||||
jest.mock('app/features/dashboard/services/TimeSrv', () => ({
|
||||
...jest.requireActual('app/features/dashboard/services/TimeSrv'),
|
||||
getTimeSrv: () => mockTimeSrv,
|
||||
}));
|
||||
const mockTemplateSrv = {
|
||||
updateTimeRange: jest.fn(),
|
||||
};
|
||||
@ -22,6 +29,8 @@ describe('Explore item reducer', () => {
|
||||
const { dispatch } = configureStore(state);
|
||||
dispatch(updateTime({ exploreId: 'left' }));
|
||||
expect(mockTemplateSrv.updateTimeRange).toBeCalledWith(state.explore.panes.left.range);
|
||||
expect(mockTimeSrv.init).toBeCalled();
|
||||
expect(mockTemplateSrv.updateTimeRange).toBeCalledWith(state.explore.panes.left.range);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -5,6 +5,7 @@ import { getTemplateSrv } from '@grafana/runtime';
|
||||
import { RefreshPicker } from '@grafana/ui';
|
||||
import { getTimeRange, refreshIntervalToSortOrder, stopQueryState } from 'app/core/utils/explore';
|
||||
import { getShiftedTimeRange, getZoomedTimeRange } from 'app/core/utils/timePicker';
|
||||
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { sortLogsResult } from 'app/features/logs/utils';
|
||||
import { getFiscalYearStartMonth, getTimeZone } from 'app/features/profile/state/selectors';
|
||||
import { ExploreItemState, ThunkDispatch, ThunkResult } from 'app/types';
|
||||
@ -21,6 +22,7 @@ export interface ChangeRangePayload {
|
||||
range: TimeRange;
|
||||
absoluteRange: AbsoluteTimeRange;
|
||||
}
|
||||
|
||||
export const changeRangeAction = createAction<ChangeRangePayload>('explore/changeRange');
|
||||
|
||||
/**
|
||||
@ -30,6 +32,7 @@ export interface ChangeRefreshIntervalPayload {
|
||||
exploreId: string;
|
||||
refreshInterval: string;
|
||||
}
|
||||
|
||||
export const changeRefreshInterval = createAction<ChangeRefreshIntervalPayload>('explore/changeRefreshInterval');
|
||||
|
||||
export const updateTimeRange = (options: {
|
||||
@ -78,6 +81,13 @@ export const updateTime = (config: {
|
||||
const range = getTimeRange(timeZone, rawRange, fiscalYearStartMonth);
|
||||
const absoluteRange: AbsoluteTimeRange = { from: range.from.valueOf(), to: range.to.valueOf() };
|
||||
|
||||
// @deprecated - set because some internal plugins read the range this way; please use QueryEditorProps.range instead
|
||||
getTimeSrv().init({
|
||||
timepicker: {},
|
||||
getTimezone: () => timeZone,
|
||||
timeRangeUpdated(timeRange) {},
|
||||
time: range.raw,
|
||||
});
|
||||
// After re-initializing TimeSrv we need to update the time range in Template service for interpolation
|
||||
// of __from and __to variables
|
||||
getTemplateSrv().updateTimeRange(range);
|
||||
|
Loading…
Reference in New Issue
Block a user