Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] use stored map buffer to generate queries for search sessions #91148

Merged
merged 8 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions x-pack/plugins/maps/public/actions/map_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ describe('map_actions', () => {
require('../selectors/map_selectors').getSearchSessionId = () => {
return searchSessionId;
};
require('../selectors/map_selectors').getSearchSessionMapBuffer = () => {
return undefined;
};
require('../selectors/map_selectors').getMapSettings = () => {
return {
autoFitToDataBounds: false,
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/maps/public/actions/map_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getTimeFilters,
getLayerList,
getSearchSessionId,
getSearchSessionMapBuffer,
} from '../selectors/map_selectors';
import {
CLEAR_GOTO,
Expand Down Expand Up @@ -229,12 +230,14 @@ export function setQuery({
filters = [],
forceRefresh = false,
searchSessionId,
searchSessionMapBuffer,
}: {
filters?: Filter[];
query?: Query;
timeFilters?: TimeRange;
forceRefresh?: boolean;
searchSessionId?: string;
searchSessionMapBuffer?: MapExtent;
}) {
return async (
dispatch: ThunkDispatch<MapStoreState, void, AnyAction>,
Expand All @@ -255,13 +258,15 @@ export function setQuery({
},
filters: filters ? filters : getFilters(getState()),
searchSessionId,
searchSessionMapBuffer,
};

const prevQueryContext = {
timeFilters: getTimeFilters(getState()),
query: getQuery(getState()),
filters: getFilters(getState()),
searchSessionId: getSearchSessionId(getState()),
searchSessionMapBuffer: getSearchSessionMapBuffer(getState()),
};

if (_.isEqual(nextQueryContext, prevQueryContext)) {
Expand Down
48 changes: 15 additions & 33 deletions x-pack/plugins/maps/public/embeddable/map_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
} from '../reducers/non_serializable_instances';
import {
getMapCenter,
getMapBuffer,
getMapZoom,
getHiddenLayerIds,
getQueryableUniqueIndexPatternIds,
Expand Down Expand Up @@ -140,11 +141,7 @@ export class MapEmbeddable
store.dispatch(disableScrollZoom());

this._dispatchSetQuery({
query: this.input.query,
timeRange: this.input.timeRange,
filters: this.input.filters,
forceRefresh: false,
searchSessionId: this.input.searchSessionId,
});
if (this.input.refreshConfig) {
this._dispatchSetRefreshConfig(this.input.refreshConfig);
Expand Down Expand Up @@ -219,11 +216,7 @@ export class MapEmbeddable
this.input.searchSessionId !== this._prevSearchSessionId
) {
this._dispatchSetQuery({
query: this.input.query,
timeRange: this.input.timeRange,
filters: this.input.filters,
forceRefresh: false,
searchSessionId: this.input.searchSessionId,
});
}

Expand All @@ -236,30 +229,22 @@ export class MapEmbeddable
}
}

_dispatchSetQuery({
query,
timeRange,
filters = [],
forceRefresh,
searchSessionId,
}: {
query?: Query;
timeRange?: TimeRange;
filters?: Filter[];
forceRefresh: boolean;
searchSessionId?: string;
}) {
this._prevTimeRange = timeRange;
this._prevQuery = query;
this._prevFilters = filters;
this._prevSearchSessionId = searchSessionId;
_dispatchSetQuery({ forceRefresh }: { forceRefresh: boolean }) {
this._prevTimeRange = this.input.timeRange;
this._prevQuery = this.input.query;
this._prevFilters = this.input.filters;
this._prevSearchSessionId = this.input.searchSessionId;
const enabledFilters = this.input.filters
? this.input.filters.filter((filter) => !filter.meta.disabled)
: [];
this._savedMap.getStore().dispatch<any>(
setQuery({
filters: filters.filter((filter) => !filter.meta.disabled),
query,
timeFilters: timeRange,
filters: enabledFilters,
query: this.input.query,
timeFilters: this.input.timeRange,
forceRefresh,
searchSessionId,
searchSessionId: this.input.searchSessionId,
searchSessionMapBuffer: this.input.mapBuffer,
})
);
}
Expand Down Expand Up @@ -410,11 +395,7 @@ export class MapEmbeddable

reload() {
this._dispatchSetQuery({
query: this.input.query,
timeRange: this.input.timeRange,
filters: this.input.filters,
forceRefresh: true,
searchSessionId: this.input.searchSessionId,
});
}

Expand All @@ -435,6 +416,7 @@ export class MapEmbeddable
lon: center.lon,
zoom,
},
mapBuffer: getMapBuffer(this._savedMap.getStore().getState()),
});
}

Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/maps/public/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SavedObjectEmbeddableInput,
} from '../../../../../src/plugins/embeddable/public';
import { RefreshInterval, Query, Filter, TimeRange } from '../../../../../src/plugins/data/common';
import { MapCenterAndZoom } from '../../common/descriptor_types';
import { MapCenterAndZoom, MapExtent } from '../../common/descriptor_types';
import { MapSavedObjectAttributes } from '../../common/map_saved_object_type';
import { MapSettings } from '../reducers/map';

Expand All @@ -25,6 +25,7 @@ interface MapEmbeddableState {
isLayerTOCOpen?: boolean;
openTOCDetails?: string[];
mapCenter?: MapCenterAndZoom;
mapBuffer?: MapExtent;
mapSettings?: Partial<MapSettings>;
hiddenLayers?: string[];
hideFilterActions?: boolean;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/maps/public/reducers/map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type MapContext = {
refreshTimerLastTriggeredAt?: string;
drawState?: DrawState;
searchSessionId?: string;
searchSessionMapBuffer?: MapExtent;
};

export type MapSettings = {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/maps/public/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function map(state = DEFAULT_MAP_STATE, action) {
};
return { ...state, mapState: { ...state.mapState, ...newMapState } };
case SET_QUERY:
const { query, timeFilters, filters, searchSessionId } = action;
const { query, timeFilters, filters, searchSessionId, searchSessionMapBuffer } = action;
return {
...state,
mapState: {
Expand All @@ -250,6 +250,7 @@ export function map(state = DEFAULT_MAP_STATE, action) {
timeFilters,
filters,
searchSessionId,
searchSessionMapBuffer,
},
};
case SET_REFRESH_CONFIG:
Expand Down
60 changes: 59 additions & 1 deletion x-pack/plugins/maps/public/selectors/map_selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,66 @@ jest.mock('../kibana_services', () => ({
},
}));

import { Filter } from '../../../../../src/plugins/data/public';
import { DEFAULT_MAP_STORE_STATE } from '../reducers/store';
import { getTimeFilters } from './map_selectors';
import { getDataFilters, getTimeFilters } from './map_selectors';

describe('getDataFilters', () => {
const mapExtent = {
maxLat: 1,
maxLon: 1,
minLat: 0,
minLon: 0,
};
const mapBuffer = {
maxLat: 1.5,
maxLon: 1.5,
minLat: -0.5,
minLon: -0.5,
};
const mapZoom = 4;
const timeFilters = { to: '2001-01-01', from: '2001-12-31' };
const refreshTimerLastTriggeredAt = '2001-01-01T00:00:00';
const query = undefined;
const filters: Filter[] = [];
const searchSessionId = '12345';
const searchSessionMapBuffer = {
maxLat: 1.25,
maxLon: 1.25,
minLat: -0.25,
minLon: -0.25,
};

test('should set buffer as searchSessionMapBuffer when using searchSessionId', () => {
const dataFilters = getDataFilters.resultFunc(
mapExtent,
mapBuffer,
mapZoom,
timeFilters,
refreshTimerLastTriggeredAt,
query,
filters,
searchSessionId,
searchSessionMapBuffer
);
expect(dataFilters.buffer).toEqual(searchSessionMapBuffer);
});

test('should fall back to screen buffer when using searchSessionId and searchSessionMapBuffer is not provided', () => {
const dataFilters = getDataFilters.resultFunc(
mapExtent,
mapBuffer,
mapZoom,
timeFilters,
refreshTimerLastTriggeredAt,
query,
filters,
searchSessionId,
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
undefined
);
expect(dataFilters.buffer).toEqual(mapBuffer);
});
});

describe('getTimeFilters', () => {
it('should return timeFilters when contained in state', () => {
Expand Down
9 changes: 7 additions & 2 deletions x-pack/plugins/maps/public/selectors/map_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ export const getFilters = ({ map }: MapStoreState): Filter[] => map.mapState.fil
export const getSearchSessionId = ({ map }: MapStoreState): string | undefined =>
map.mapState.searchSessionId;

export const getSearchSessionMapBuffer = ({ map }: MapStoreState): MapExtent | undefined =>
map.mapState.searchSessionMapBuffer;

export const isUsingSearch = (state: MapStoreState): boolean => {
const filters = getFilters(state).filter((filter) => !filter.meta.disabled);
const queryString = _.get(getQuery(state), 'query', '');
Expand Down Expand Up @@ -235,6 +238,7 @@ export const getDataFilters = createSelector(
getQuery,
getFilters,
getSearchSessionId,
getSearchSessionMapBuffer,
(
mapExtent,
mapBuffer,
Expand All @@ -243,11 +247,12 @@ export const getDataFilters = createSelector(
refreshTimerLastTriggeredAt,
query,
filters,
searchSessionId
searchSessionId,
searchSessionMapBuffer
) => {
return {
extent: mapExtent,
buffer: mapBuffer,
buffer: searchSessionId && searchSessionMapBuffer ? searchSessionMapBuffer : mapBuffer,
zoom: mapZoom,
timeFilters,
refreshTimerLastTriggeredAt,
Expand Down