Skip to content

Commit c2e2c87

Browse files
authored
[Maps] replace singleton inspectorAdapters with per map inspector adapter instance (#31009) (#31281)
* [Maps] replace singleton inspectorAdapters with per map inspector adapter instance * pass inspectorAdapters to all source constructors in renderEditor * rename non_serializable_kibana_instances to non_serializable_instances, fix test jest test broken by import
1 parent 988fc0f commit c2e2c87

File tree

26 files changed

+120
-118
lines changed

26 files changed

+120
-118
lines changed

x-pack/plugins/maps/public/angular/map_controller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ import {
2727
FLYOUT_STATE
2828
} from '../store/ui';
2929
import { getUniqueIndexPatternIds } from '../selectors/map_selectors';
30+
import { getInspectorAdapters } from '../store/non_serializable_instances';
3031
import { Inspector } from 'ui/inspector';
3132
import { DocTitleProvider } from 'ui/doc_title';
32-
import { inspectorAdapters, indexPatternService } from '../kibana_services';
33+
import { indexPatternService } from '../kibana_services';
3334
import { SavedObjectSaveModal } from 'ui/saved_objects/components/saved_object_save_modal';
3435
import { showSaveModal } from 'ui/saved_objects/show_saved_object_save_modal';
3536
import { toastNotifications } from 'ui/notify';
@@ -49,7 +50,6 @@ app.controller('GisMapController', ($scope, $route, config, kbnUrl, localStorage
4950
let unsubscribe;
5051

5152
const store = createMapStore();
52-
inspectorAdapters.requests.reset();
5353

5454
$scope.$listen(globalState, 'fetch_with_changes', (diff) => {
5555
if (diff.includes('time')) {
@@ -252,6 +252,7 @@ app.controller('GisMapController', ($scope, $route, config, kbnUrl, localStorage
252252
description: 'Open Inspector',
253253
testId: 'openInspectorButton',
254254
run() {
255+
const inspectorAdapters = getInspectorAdapters(store.getState());
255256
Inspector.open(inspectorAdapters, {});
256257
}
257258
}, {

x-pack/plugins/maps/public/components/layer_addpanel/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { connect } from 'react-redux';
88
import { AddLayerPanel } from './view';
99
import { getFlyoutDisplay, updateFlyout, FLYOUT_STATE } from '../../store/ui';
1010
import { getTemporaryLayers, getMapColors } from '../../selectors/map_selectors';
11+
import { getInspectorAdapters } from '../../store/non_serializable_instances';
1112
import {
1213
addLayer,
1314
removeLayer,
@@ -23,6 +24,7 @@ function mapStateToProps(state = {}) {
2324
return tmp.some((layer) => layer.isLayerLoading());
2425
}
2526
return {
27+
inspectorAdapters: getInspectorAdapters(state),
2628
flyoutVisible: getFlyoutDisplay(state) !== FLYOUT_STATE.NONE,
2729
layerLoading: isLoading(),
2830
temporaryLayers: !_.isEmpty(getTemporaryLayers(state)),

x-pack/plugins/maps/public/components/layer_addpanel/view.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ import {
2323

2424
export class AddLayerPanel extends Component {
2525

26-
constructor() {
27-
super();
28-
29-
this.state = {
30-
sourceType: null,
31-
};
26+
state = {
27+
sourceType: null,
3228
}
3329

3430
_previewLayer = (source) => {
@@ -107,7 +103,8 @@ export class AddLayerPanel extends Component {
107103

108104
_renderSourceEditor() {
109105
const editorProperties = {
110-
onPreviewSource: this._previewLayer
106+
onPreviewSource: this._previewLayer,
107+
inspectorAdapters: this.props.inspectorAdapters,
111108
};
112109

113110
const Source = ALL_SOURCES.find((Source) => {

x-pack/plugins/maps/public/components/map/mb/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import {
1616
setLayerErrorStatus,
1717
} from '../../../actions/store_actions';
1818
import { getLayerList, getMapReady, getGoto } from '../../../selectors/map_selectors';
19+
import { getInspectorAdapters } from '../../../store/non_serializable_instances';
1920

2021
function mapStateToProps(state = {}) {
2122
return {
2223
isMapReady: getMapReady(state),
2324
layerList: getLayerList(state),
24-
goto: getGoto(state)
25+
goto: getGoto(state),
26+
inspectorAdapters: getInspectorAdapters(state),
2527
};
2628
}
2729

x-pack/plugins/maps/public/components/map/mb/view.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import _ from 'lodash';
88
import React from 'react';
99
import { ResizeChecker } from 'ui/resize_checker';
1010
import { syncLayerOrder, removeOrphanedSourcesAndLayers, createMbMapInstance } from './utils';
11-
import { inspectorAdapters } from '../../../kibana_services';
1211
import { DECIMAL_DEGREES_PRECISION, ZOOM_PRECISION } from '../../../../common/constants';
1312
import mapboxgl from 'mapbox-gl';
1413

@@ -217,7 +216,7 @@ export class MBMapContainer extends React.Component {
217216
};
218217

219218
_syncMbMapWithInspector = () => {
220-
if (!this.props.isMapReady || !inspectorAdapters.map) {
219+
if (!this.props.isMapReady || !this.props.inspectorAdapters.map) {
221220
return;
222221
}
223222

@@ -226,7 +225,7 @@ export class MBMapContainer extends React.Component {
226225
zoom: this._mbMap.getZoom(),
227226

228227
};
229-
inspectorAdapters.map.setMapState({
228+
this.props.inspectorAdapters.map.setMapState({
230229
stats,
231230
style: this._mbMap.getStyle(),
232231
});

x-pack/plugins/maps/public/components/widget_overlay/attribution_control/view.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ import {
1515

1616
export class AttributionControl extends React.Component {
1717

18-
constructor() {
19-
super();
20-
this.state = {
21-
uniqueAttributions: []
22-
};
18+
state = {
19+
uniqueAttributions: []
2320
}
2421

2522
componentDidMount() {

x-pack/plugins/maps/public/kibana_services.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import chrome from 'ui/chrome';
87
import { uiModules } from 'ui/modules';
98
import { SearchSourceProvider } from 'ui/courier';
10-
import { RequestAdapter } from 'ui/inspector/adapters';
11-
import { MapAdapter } from './inspector/adapters/map_adapter';
129
import { timefilter } from 'ui/timefilter/timefilter';
1310
import { getRequestInspectorStats, getResponseInspectorStats } from 'ui/courier/utils/courier_inspector_utils';
1411

@@ -17,14 +14,7 @@ export let indexPatternService;
1714
export let SearchSource;
1815
export let emsServiceSettings;
1916

20-
export const inspectorAdapters = {
21-
requests: new RequestAdapter(),
22-
};
23-
if (chrome.getInjected('showMapsInspectorAdapter', false)) {
24-
inspectorAdapters.map = new MapAdapter();
25-
}
26-
27-
export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, requestName, requestDesc }) {
17+
export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, requestName, requestDesc, inspectorAdapters }) {
2818
const inspectorRequest = inspectorAdapters.requests.start(
2919
requestName,
3020
{ id: requestId, description: requestDesc });

x-pack/plugins/maps/public/selectors/map_selectors.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import { VectorStyle } from '../shared/layers/styles/vector_style';
1414
import { HeatmapStyle } from '../shared/layers/styles/heatmap_style';
1515
import { TileStyle } from '../shared/layers/styles/tile_style';
1616
import { timefilter } from 'ui/timefilter';
17-
17+
import { getInspectorAdapters } from '../store/non_serializable_instances';
1818
import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../store/util';
1919

20-
function createLayerInstance(layerDescriptor) {
21-
const source = createSourceInstance(layerDescriptor.sourceDescriptor);
20+
function createLayerInstance(layerDescriptor, inspectorAdapters) {
21+
const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters);
2222
const style = createStyleInstance(layerDescriptor.style);
2323
switch (layerDescriptor.type) {
2424
case TileLayer.type:
@@ -32,14 +32,14 @@ function createLayerInstance(layerDescriptor) {
3232
}
3333
}
3434

35-
function createSourceInstance(sourceDescriptor) {
35+
function createSourceInstance(sourceDescriptor, inspectorAdapters) {
3636
const Source = ALL_SOURCES.find(Source => {
3737
return Source.type === sourceDescriptor.type;
3838
});
3939
if (!Source) {
4040
throw new Error(`Unrecognized sourceType ${sourceDescriptor.type}`);
4141
}
42-
return new Source(sourceDescriptor);
42+
return new Source(sourceDescriptor, inspectorAdapters);
4343
}
4444

4545

@@ -131,9 +131,10 @@ export const getDataFilters = createSelector(
131131

132132
export const getLayerList = createSelector(
133133
getLayerListRaw,
134-
(layerDescriptorList) => {
134+
getInspectorAdapters,
135+
(layerDescriptorList, inspectorAdapters) => {
135136
return layerDescriptorList.map(layerDescriptor =>
136-
createLayerInstance(layerDescriptor));
137+
createLayerInstance(layerDescriptor, inspectorAdapters));
137138
});
138139

139140
export const getSelectedLayer = createSelector(

x-pack/plugins/maps/public/selectors/map_selectors.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
jest.mock('../shared/layers/vector_layer', () => {});
88
jest.mock('../shared/layers/sources/all_sources', () => {});
9+
jest.mock('../store/non_serializable_instances', () => ({
10+
getInspectorAdapters: () => {
11+
return {};
12+
}
13+
}));
914
jest.mock('ui/timefilter', () => ({
1015
timefilter: {
1116
getTime: () => {

x-pack/plugins/maps/public/shared/components/map_listing.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,16 @@ export const EMPTY_FILTER = '';
2929

3030
export class MapListing extends React.Component {
3131

32-
constructor(props) {
33-
super(props);
34-
35-
this.state = {
36-
hasInitialFetchReturned: false,
37-
isFetchingItems: false,
38-
showDeleteModal: false,
39-
showLimitError: false,
40-
filter: EMPTY_FILTER,
41-
items: [],
42-
selectedIds: [],
43-
page: 0,
44-
perPage: 20,
45-
};
32+
state = {
33+
hasInitialFetchReturned: false,
34+
isFetchingItems: false,
35+
showDeleteModal: false,
36+
showLimitError: false,
37+
filter: EMPTY_FILTER,
38+
items: [],
39+
selectedIds: [],
40+
page: 0,
41+
perPage: 20,
4642
}
4743

4844
componentWillMount() {

0 commit comments

Comments
 (0)