Skip to content

Commit 4937cb3

Browse files
committed
Merge branch 'master' of github.com:elastic/kibana into fix/tweak-public-path-before-imports
2 parents a97b319 + e28028b commit 4937cb3

21 files changed

Lines changed: 250 additions & 161 deletions

File tree

x-pack/plugins/apm/public/context/LoadingIndicatorContext.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { EuiPortal, EuiProgress } from '@elastic/eui';
7+
import { pick } from 'lodash';
78
import React, { Fragment, useMemo, useReducer } from 'react';
89
import { useDelayedVisibility } from '../components/shared/useDelayedVisibility';
910

1011
export const LoadingIndicatorContext = React.createContext({
1112
statuses: {},
12-
dispatchStatus: (action: Action) => undefined as void,
13+
dispatchStatus: (action: Action) => {},
1314
});
1415

1516
interface State {
@@ -22,14 +23,13 @@ interface Action {
2223
}
2324

2425
function reducer(statuses: State, action: Action) {
25-
// add loading status
26-
if (action.isLoading) {
27-
return { ...statuses, [action.id]: true };
28-
}
29-
30-
// remove loading status
31-
const { [action.id]: statusToRemove, ...restStatuses } = statuses;
32-
return restStatuses;
26+
// Return an object with only the ids with `true` as their value, so that ids
27+
// that previously had `false` are removed and do not remain hanging around in
28+
// the object.
29+
return pick(
30+
{ ...statuses, [action.id.toString()]: action.isLoading },
31+
Boolean
32+
);
3333
}
3434

3535
function getIsAnyLoading(statuses: State) {

x-pack/plugins/maps/common/constants.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ export enum FIELD_ORIGIN {
7272
}
7373
export const JOIN_FIELD_NAME_PREFIX = '__kbnjoin__';
7474

75-
export const SOURCE_DATA_ID_ORIGIN = 'source';
76-
export const META_ID_ORIGIN_SUFFIX = 'meta';
77-
export const SOURCE_META_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${META_ID_ORIGIN_SUFFIX}`;
78-
export const FORMATTERS_ID_ORIGIN_SUFFIX = 'formatters';
79-
export const SOURCE_FORMATTERS_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${FORMATTERS_ID_ORIGIN_SUFFIX}`;
75+
export const META_DATA_REQUEST_ID_SUFFIX = 'meta';
76+
export const FORMATTERS_DATA_REQUEST_ID_SUFFIX = 'formatters';
77+
export const SOURCE_DATA_REQUEST_ID = 'source';
78+
export const SOURCE_META_DATA_REQUEST_ID = `${SOURCE_DATA_REQUEST_ID}_${META_DATA_REQUEST_ID_SUFFIX}`;
79+
export const SOURCE_FORMATTERS_DATA_REQUEST_ID = `${SOURCE_DATA_REQUEST_ID}_${FORMATTERS_DATA_REQUEST_ID_SUFFIX}`;
80+
export const SOURCE_BOUNDS_DATA_REQUEST_ID = `${SOURCE_DATA_REQUEST_ID}_bounds`;
8081

8182
export const MIN_ZOOM = 0;
8283
export const MAX_ZOOM = 24;

x-pack/plugins/maps/public/actions/data_request_actions.ts

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
/* eslint-disable @typescript-eslint/consistent-type-definitions */
77

88
import { Dispatch } from 'redux';
9+
// @ts-ignore
10+
import turf from 'turf';
911
import { FeatureCollection } from 'geojson';
1012
import { MapStoreState } from '../reducers/store';
11-
import { LAYER_TYPE, SOURCE_DATA_ID_ORIGIN } from '../../common/constants';
13+
import { LAYER_TYPE, SOURCE_DATA_REQUEST_ID } from '../../common/constants';
1214
import {
1315
getDataFilters,
1416
getDataRequestDescriptor,
17+
getFittableLayers,
1518
getLayerById,
1619
getLayerList,
1720
} from '../selectors/map_selectors';
@@ -27,13 +30,15 @@ import {
2730
LAYER_DATA_LOAD_ENDED,
2831
LAYER_DATA_LOAD_ERROR,
2932
LAYER_DATA_LOAD_STARTED,
33+
SET_GOTO,
3034
SET_LAYER_ERROR_STATUS,
3135
SET_LAYER_STYLE_META,
3236
UPDATE_LAYER_PROP,
3337
UPDATE_SOURCE_DATA_REQUEST,
3438
} from './map_action_constants';
3539
import { ILayer } from '../classes/layers/layer';
36-
import { DataMeta, MapFilters } from '../../common/descriptor_types';
40+
import { DataMeta, MapExtent, MapFilters } from '../../common/descriptor_types';
41+
import { DataRequestAbortError } from '../classes/util/data_request';
3742

3843
export type DataRequestContext = {
3944
startLoading(dataId: string, requestToken: symbol, meta: DataMeta): void;
@@ -269,11 +274,107 @@ export function updateSourceDataRequest(layerId: string, newData: unknown) {
269274
return (dispatch: Dispatch) => {
270275
dispatch({
271276
type: UPDATE_SOURCE_DATA_REQUEST,
272-
dataId: SOURCE_DATA_ID_ORIGIN,
277+
dataId: SOURCE_DATA_REQUEST_ID,
273278
layerId,
274279
newData,
275280
});
276281

277282
dispatch<any>(updateStyleMeta(layerId));
278283
};
279284
}
285+
286+
export function fitToLayerExtent(layerId: string) {
287+
return async (dispatch: Dispatch, getState: () => MapStoreState) => {
288+
const targetLayer = getLayerById(layerId, getState());
289+
290+
if (targetLayer) {
291+
try {
292+
const bounds = await targetLayer.getBounds(
293+
getDataRequestContext(dispatch, getState, layerId)
294+
);
295+
if (bounds) {
296+
await dispatch(setGotoWithBounds(bounds));
297+
}
298+
} catch (error) {
299+
if (!(error instanceof DataRequestAbortError)) {
300+
// eslint-disable-next-line no-console
301+
console.warn(
302+
'Unhandled getBounds error for layer. Only DataRequestAbortError should be surfaced',
303+
error
304+
);
305+
}
306+
// new fitToLayerExtent request has superseded this thread of execution. Results no longer needed.
307+
return;
308+
}
309+
}
310+
};
311+
}
312+
313+
export function fitToDataBounds() {
314+
return async (dispatch: Dispatch, getState: () => MapStoreState) => {
315+
const layerList = getFittableLayers(getState());
316+
317+
if (!layerList.length) {
318+
return;
319+
}
320+
321+
const boundsPromises = layerList.map(async (layer: ILayer) => {
322+
return layer.getBounds(getDataRequestContext(dispatch, getState, layer.getId()));
323+
});
324+
325+
let bounds;
326+
try {
327+
bounds = await Promise.all(boundsPromises);
328+
} catch (error) {
329+
if (!(error instanceof DataRequestAbortError)) {
330+
// eslint-disable-next-line no-console
331+
console.warn(
332+
'Unhandled getBounds error for layer. Only DataRequestAbortError should be surfaced',
333+
error
334+
);
335+
}
336+
// new fitToDataBounds request has superseded this thread of execution. Results no longer needed.
337+
return;
338+
}
339+
340+
const corners = [];
341+
for (let i = 0; i < bounds.length; i++) {
342+
const b = bounds[i];
343+
344+
// filter out undefined bounds (uses Infinity due to turf responses)
345+
if (
346+
b === null ||
347+
b.minLon === Infinity ||
348+
b.maxLon === Infinity ||
349+
b.minLat === -Infinity ||
350+
b.maxLat === -Infinity
351+
) {
352+
continue;
353+
}
354+
355+
corners.push([b.minLon, b.minLat]);
356+
corners.push([b.maxLon, b.maxLat]);
357+
}
358+
359+
if (!corners.length) {
360+
return;
361+
}
362+
363+
const turfUnionBbox = turf.bbox(turf.multiPoint(corners));
364+
const dataBounds = {
365+
minLon: turfUnionBbox[0],
366+
minLat: turfUnionBbox[1],
367+
maxLon: turfUnionBbox[2],
368+
maxLat: turfUnionBbox[3],
369+
};
370+
371+
dispatch(setGotoWithBounds(dataBounds));
372+
};
373+
}
374+
375+
function setGotoWithBounds(bounds: MapExtent) {
376+
return {
377+
type: SET_GOTO,
378+
bounds,
379+
};
380+
}

x-pack/plugins/maps/public/actions/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export * from './ui_actions';
99
export * from './map_actions';
1010
export * from './map_action_constants';
1111
export * from './layer_actions';
12-
export { cancelAllInFlightRequests, DataRequestContext } from './data_request_actions';
12+
export {
13+
cancelAllInFlightRequests,
14+
DataRequestContext,
15+
fitToLayerExtent,
16+
fitToDataBounds,
17+
} from './data_request_actions';
1318
export {
1419
closeOnClickTooltip,
1520
openOnClickTooltip,

x-pack/plugins/maps/public/actions/map_actions.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import turfBooleanContains from '@turf/boolean-contains';
1212
import { Filter, Query, TimeRange } from 'src/plugins/data/public';
1313
import { MapStoreState } from '../reducers/store';
1414
import {
15-
getLayerById,
1615
getDataFilters,
1716
getWaitingForMapReadyLayerListRaw,
1817
getQuery,
19-
getFittableLayers,
2018
} from '../selectors/map_selectors';
2119
import {
2220
CLEAR_GOTO,
@@ -184,76 +182,6 @@ export function disableScrollZoom() {
184182
return { type: SET_SCROLL_ZOOM, scrollZoom: false };
185183
}
186184

187-
export function fitToLayerExtent(layerId: string) {
188-
return async (dispatch: Dispatch, getState: () => MapStoreState) => {
189-
const targetLayer = getLayerById(layerId, getState());
190-
191-
if (targetLayer) {
192-
const dataFilters = getDataFilters(getState());
193-
const bounds = await targetLayer.getBounds(dataFilters);
194-
if (bounds) {
195-
await dispatch(setGotoWithBounds(bounds));
196-
}
197-
}
198-
};
199-
}
200-
201-
export function fitToDataBounds() {
202-
return async (dispatch: Dispatch, getState: () => MapStoreState) => {
203-
const layerList = getFittableLayers(getState());
204-
205-
if (!layerList.length) {
206-
return;
207-
}
208-
209-
const dataFilters = getDataFilters(getState());
210-
const boundsPromises = layerList.map(async (layer) => {
211-
return layer.getBounds(dataFilters);
212-
});
213-
214-
const bounds = await Promise.all(boundsPromises);
215-
const corners = [];
216-
for (let i = 0; i < bounds.length; i++) {
217-
const b = bounds[i];
218-
219-
// filter out undefined bounds (uses Infinity due to turf responses)
220-
if (
221-
b === null ||
222-
b.minLon === Infinity ||
223-
b.maxLon === Infinity ||
224-
b.minLat === -Infinity ||
225-
b.maxLat === -Infinity
226-
) {
227-
continue;
228-
}
229-
230-
corners.push([b.minLon, b.minLat]);
231-
corners.push([b.maxLon, b.maxLat]);
232-
}
233-
234-
if (!corners.length) {
235-
return;
236-
}
237-
238-
const turfUnionBbox = turf.bbox(turf.multiPoint(corners));
239-
const dataBounds = {
240-
minLon: turfUnionBbox[0],
241-
minLat: turfUnionBbox[1],
242-
maxLon: turfUnionBbox[2],
243-
maxLat: turfUnionBbox[3],
244-
};
245-
246-
dispatch(setGotoWithBounds(dataBounds));
247-
};
248-
}
249-
250-
export function setGotoWithBounds(bounds: MapExtent) {
251-
return {
252-
type: SET_GOTO,
253-
bounds,
254-
};
255-
}
256-
257185
export function setGotoWithCenter({ lat, lon, zoom }: MapCenterAndZoom) {
258186
return {
259187
type: SET_GOTO,

x-pack/plugins/maps/public/classes/joins/inner_join.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import { ESTermSource } from '../sources/es_term_source';
88
import { getComputedFieldNamePrefix } from '../styles/vector/style_util';
9-
import { META_ID_ORIGIN_SUFFIX, FORMATTERS_ID_ORIGIN_SUFFIX } from '../../../common/constants';
9+
import {
10+
META_DATA_REQUEST_ID_SUFFIX,
11+
FORMATTERS_DATA_REQUEST_ID_SUFFIX,
12+
} from '../../../common/constants';
1013

1114
export class InnerJoin {
1215
constructor(joinDescriptor, leftSource) {
@@ -42,11 +45,11 @@ export class InnerJoin {
4245
}
4346

4447
getSourceMetaDataRequestId() {
45-
return `${this.getSourceDataRequestId()}_${META_ID_ORIGIN_SUFFIX}`;
48+
return `${this.getSourceDataRequestId()}_${META_DATA_REQUEST_ID_SUFFIX}`;
4649
}
4750

4851
getSourceFormattersDataRequestId() {
49-
return `${this.getSourceDataRequestId()}_${FORMATTERS_ID_ORIGIN_SUFFIX}`;
52+
return `${this.getSourceDataRequestId()}_${FORMATTERS_DATA_REQUEST_ID_SUFFIX}`;
5053
}
5154

5255
getLeftField() {

x-pack/plugins/maps/public/classes/layers/layer.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@ import {
1717
MAX_ZOOM,
1818
MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER,
1919
MIN_ZOOM,
20-
SOURCE_DATA_ID_ORIGIN,
20+
SOURCE_DATA_REQUEST_ID,
2121
} from '../../../common/constants';
2222
import { copyPersistentState } from '../../reducers/util';
23-
import {
24-
LayerDescriptor,
25-
MapExtent,
26-
MapFilters,
27-
StyleDescriptor,
28-
} from '../../../common/descriptor_types';
23+
import { LayerDescriptor, MapExtent, StyleDescriptor } from '../../../common/descriptor_types';
2924
import { Attribution, ImmutableSourceProperty, ISource, SourceEditorArgs } from '../sources/source';
3025
import { DataRequestContext } from '../../actions';
3126
import { IStyle } from '../styles/style';
3227

3328
export interface ILayer {
34-
getBounds(mapFilters: MapFilters): Promise<MapExtent>;
29+
getBounds(dataRequestContext: DataRequestContext): Promise<MapExtent | null>;
3530
getDataRequest(id: string): DataRequest | undefined;
3631
getDisplayName(source?: ISource): Promise<string>;
3732
getId(): string;
@@ -401,7 +396,7 @@ export class AbstractLayer implements ILayer {
401396
}
402397

403398
getSourceDataRequest(): DataRequest | undefined {
404-
return this.getDataRequest(SOURCE_DATA_ID_ORIGIN);
399+
return this.getDataRequest(SOURCE_DATA_REQUEST_ID);
405400
}
406401

407402
getDataRequest(id: string): DataRequest | undefined {
@@ -455,13 +450,8 @@ export class AbstractLayer implements ILayer {
455450
return sourceDataRequest ? sourceDataRequest.hasData() : false;
456451
}
457452

458-
async getBounds(mapFilters: MapFilters): Promise<MapExtent> {
459-
return {
460-
minLon: -180,
461-
maxLon: 180,
462-
minLat: -89,
463-
maxLat: 89,
464-
};
453+
async getBounds(dataRequestContext: DataRequestContext): Promise<MapExtent | null> {
454+
return null;
465455
}
466456

467457
renderStyleEditor({

0 commit comments

Comments
 (0)