Skip to content

Commit

Permalink
[Maps] fix multi-select query from Controls visualization not always …
Browse files Browse the repository at this point in the history
…getting applied to map in dashboard (#87310)

* [Maps] fix multi-select query from Controls visualization not always getting applied to map in dashboard

* fix underlying problem in blended layer

* clean-up

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
nreese and kibanamachine authored Jan 7, 2021
1 parent 9d4ef37 commit 8cb6226
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion x-pack/plugins/maps/public/actions/data_request_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,15 @@ function endDataLoad(
data: object,
meta: DataMeta
) {
return async (
return (
dispatch: ThunkDispatch<MapStoreState, void, AnyAction>,
getState: () => MapStoreState
) => {
dispatch(unregisterCancelCallback(requestToken));
const dataRequest = getDataRequestDescriptor(getState(), layerId, dataId);
if (dataRequest && dataRequest.dataRequestToken !== requestToken) {
throw new DataRequestAbortError();
}

const features = data && 'features' in data ? (data as FeatureCollection).features : [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import { IVectorSource } from '../../sources/vector_source';
import { LICENSED_FEATURES } from '../../../licensed_features';
import { ESSearchSource } from '../../sources/es_search_source/es_search_source';
import { isSearchSourceAbortError } from '../../sources/es_source/es_source';

const ACTIVE_COUNT_DATA_ID = 'ACTIVE_COUNT_DATA_ID';

Expand Down Expand Up @@ -311,14 +312,16 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
let isSyncClustered;
try {
syncContext.startLoading(dataRequestId, requestToken, searchFilters);
const abortController = new AbortController();
syncContext.registerCancelCallback(requestToken, () => abortController.abort());
const searchSource = await this._documentSource.makeSearchSource(searchFilters, 0);
const resp = await searchSource.fetch();
const resp = await searchSource.fetch({ abortSignal: abortController.signal });
const maxResultWindow = await this._documentSource.getMaxResultWindow();
isSyncClustered = resp.hits.total > maxResultWindow;
const countData = { isSyncClustered } as CountData;
syncContext.stopLoading(dataRequestId, requestToken, countData, searchFilters);
} catch (error) {
if (!(error instanceof DataRequestAbortError)) {
if (!(error instanceof DataRequestAbortError) || !isSearchSourceAbortError(error)) {
syncContext.onLoadError(dataRequestId, requestToken, error.message);
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ import {
} from '../../../../../../../src/plugins/inspector/common/adapters';
import { isValidStringConfig } from '../../util/valid_string_config';

export function isSearchSourceAbortError(error: Error) {
return error.name === 'AbortError';
}

export interface IESSource extends IVectorSource {
isESSource(): true;
getId(): string;
Expand Down Expand Up @@ -191,7 +195,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
if (inspectorRequest) {
inspectorRequest.error(error);
}
if (error.name === 'AbortError') {
if (isSearchSourceAbortError(error)) {
throw new DataRequestAbortError();
}

Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/maps/public/embeddable/map_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export class MapEmbeddable

this._savedMap = new SavedMap({ mapEmbeddableInput: initialInput });
this._initializeSaveMap();
this._subscription = this.getInput$().subscribe((input) => this.onContainerStateChanged(input));
this._subscription = this.getUpdated$().subscribe(() =>
this.onContainerStateChanged(this.input)
);
}

private async _initializeSaveMap() {
Expand Down

0 comments on commit 8cb6226

Please sign in to comment.