[Lens] Chart is not updating with Refresh button (#114135)

This commit is contained in:
Marta Bondyra 2021-10-07 12:57:38 +02:00 committed by GitHub
parent 136eafe5a7
commit f50345f8ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -1142,6 +1142,27 @@ describe('Lens App', () => {
});
});
it('dispatches update to searchSessionId and dateRange when the user hits refresh', async () => {
const { instance, services, lensStore } = await mountWith({});
act(() =>
instance.find(services.navigation.ui.TopNavMenu).prop('onQuerySubmit')!({
dateRange: { from: 'now-7d', to: 'now' },
})
);
instance.update();
expect(lensStore.dispatch).toHaveBeenCalledWith({
type: 'lens/setState',
payload: {
resolvedDateRange: {
fromDate: '2021-01-10T04:00:00.000Z',
toDate: '2021-01-10T08:00:00.000Z',
},
searchSessionId: 'sessionId-2',
},
});
});
it('updates the state if session id changes from the outside', async () => {
const sessionIdS = new Subject<string>();
const services = makeDefaultServices(sessionIdS, 'sessionId-1');

View file

@ -27,7 +27,7 @@ import {
LensAppState,
DispatchSetState,
} from '../state_management';
import { getIndexPatternsObjects, getIndexPatternsIds } from '../utils';
import { getIndexPatternsObjects, getIndexPatternsIds, getResolvedDateRange } from '../utils';
function getLensTopNavConfig(options: {
showSaveAndReturn: boolean;
@ -363,8 +363,11 @@ export const LensTopNavMenu = ({
trackUiEvent('app_date_change');
} else {
// Query has changed, renew the session id.
// Time change will be picked up by the time subscription
dispatchSetState({ searchSessionId: data.search.session.start() });
// recalculate resolvedDateRange (relevant for relative time range)
dispatchSetState({
searchSessionId: data.search.session.start(),
resolvedDateRange: getResolvedDateRange(data.query.timefilter.timefilter),
});
trackUiEvent('app_query_change');
}
if (newQuery) {