Skip to content

Commit 3c9675b

Browse files
committed
merge conflicts
1 parent 095c1ce commit 3c9675b

File tree

6 files changed

+58
-56
lines changed

6 files changed

+58
-56
lines changed

x-pack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
"@kbn/interpreter": "1.0.0",
211211
"@kbn/ui-framework": "1.0.0",
212212
"@mapbox/geojson-rewind": "^0.4.1",
213-
"@mapbox/mapbox-gl-draw": "^1.1.2",
213+
"@mapbox/mapbox-gl-draw": "^1.2.0",
214214
"@mapbox/mapbox-gl-rtl-text": "^0.2.3",
215215
"@scant/router": "^0.1.0",
216216
"@slack/webhook": "^5.0.0",

x-pack/plugins/maps/public/connected_components/map/mb/draw_control/draw_control.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import {
1818
} from '../../../../elasticsearch_geo_utils';
1919
import { DrawTooltip } from './draw_tooltip';
2020

21+
const DRAW_RECTANGLE = 'draw_rectangle';
22+
const DRAW_CIRCLE = 'draw_circle';
23+
2124
const mbDrawModes = MapboxDraw.modes;
22-
mbDrawModes.draw_rectangle = DrawRectangle;
23-
mbDrawModes.draw_circle = DrawCircle;
25+
mbDrawModes[DRAW_RECTANGLE] = DrawRectangle;
26+
mbDrawModes[DRAW_CIRCLE] = DrawCircle;
2427

2528
export class DrawControl extends React.Component {
2629
constructor() {
@@ -45,8 +48,10 @@ export class DrawControl extends React.Component {
4548
this._removeDrawControl();
4649
}
4750

51+
// debounce with zero timeout needed to allow mapbox-draw finish logic to complete
52+
// before _removeDrawControl is called
4853
_syncDrawControl = _.debounce(() => {
49-
if (!this.props.mbMap) {
54+
if (!this._isMounted) {
5055
return;
5156
}
5257

@@ -55,7 +60,7 @@ export class DrawControl extends React.Component {
5560
} else {
5661
this._removeDrawControl();
5762
}
58-
}, 256);
63+
}, 0);
5964

6065
_onDraw = (e) => {
6166
if (!e.features.length) {
@@ -118,7 +123,7 @@ export class DrawControl extends React.Component {
118123
};
119124

120125
_removeDrawControl() {
121-
if (!this._mbDrawControlAdded) {
126+
if (!this.props.mbMap || !this._mbDrawControlAdded) {
122127
return;
123128
}
124129

@@ -129,18 +134,26 @@ export class DrawControl extends React.Component {
129134
}
130135

131136
_updateDrawControl() {
137+
if (!this.props.mbMap) {
138+
return;
139+
}
140+
132141
if (!this._mbDrawControlAdded) {
133142
this.props.mbMap.addControl(this._mbDrawControl);
134143
this._mbDrawControlAdded = true;
135144
this.props.mbMap.getCanvas().style.cursor = 'crosshair';
136145
this.props.mbMap.on('draw.create', this._onDraw);
137146
}
138147

139-
if (this.props.drawState.drawType === DRAW_TYPE.BOUNDS) {
140-
this._mbDrawControl.changeMode('draw_rectangle');
141-
} else if (this.props.drawState.drawType === DRAW_TYPE.DISTANCE) {
142-
this._mbDrawControl.changeMode('draw_circle');
143-
} else if (this.props.drawState.drawType === DRAW_TYPE.POLYGON) {
148+
const drawMode = this._mbDrawControl.getMode();
149+
if (drawMode !== DRAW_RECTANGLE && this.props.drawState.drawType === DRAW_TYPE.BOUNDS) {
150+
this._mbDrawControl.changeMode(DRAW_RECTANGLE);
151+
} else if (drawMode !== DRAW_CIRCLE && this.props.drawState.drawType === DRAW_TYPE.DISTANCE) {
152+
this._mbDrawControl.changeMode(DRAW_CIRCLE);
153+
} else if (
154+
drawMode !== this._mbDrawControl.modes.DRAW_POLYGON &&
155+
this.props.drawState.drawType === DRAW_TYPE.POLYGON
156+
) {
144157
this._mbDrawControl.changeMode(this._mbDrawControl.modes.DRAW_POLYGON);
145158
}
146159
}

x-pack/plugins/maps/public/routing/routes/maps_app/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
getFilters,
1212
getQueryableUniqueIndexPatternIds,
1313
getRefreshConfig,
14-
hasUnsavedChanges,
14+
getLayerListConfigOnly,
1515
} from '../../../selectors/map_selectors';
1616
import {
1717
replaceLayerList,
@@ -35,9 +35,7 @@ function mapStateToProps(state = {}) {
3535
flyoutDisplay: getFlyoutDisplay(state),
3636
refreshConfig: getRefreshConfig(state),
3737
filters: getFilters(state),
38-
hasUnsavedChanges: (savedMap, initialLayerListConfig) => {
39-
return hasUnsavedChanges(state, savedMap, initialLayerListConfig);
40-
},
38+
layerListConfigOnly: getLayerListConfigOnly(state),
4139
};
4240
}
4341

x-pack/plugins/maps/public/routing/routes/maps_app/maps_app_view.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ export class MapsAppView extends React.Component {
106106
}
107107

108108
_hasUnsavedChanges() {
109-
return this.props.hasUnsavedChanges(this.props.savedMap, this.state.initialLayerListConfig);
109+
const savedLayerList = this.props.savedMap.getLayerList();
110+
return !savedLayerList
111+
? !_.isEqual(this.props.layerListConfigOnly, this.state.initialLayerListConfig)
112+
: // savedMap stores layerList as a JSON string using JSON.stringify.
113+
// JSON.stringify removes undefined properties from objects.
114+
// savedMap.getLayerList converts the JSON string back into Javascript array of objects.
115+
// Need to perform the same process for layerListConfigOnly to compare apples to apples
116+
// and avoid undefined properties in layerListConfigOnly triggering unsaved changes.
117+
!_.isEqual(JSON.parse(JSON.stringify(this.props.layerListConfigOnly)), savedLayerList);
110118
}
111119

112120
_setBreadcrumbs = () => {
@@ -447,22 +455,20 @@ export class MapsAppView extends React.Component {
447455
) : null;
448456
}
449457

450-
render() {
451-
const { filters, isFullScreen } = this.props;
458+
_addFilter = (newFilters) => {
459+
newFilters.forEach((filter) => {
460+
filter.$state = { store: esFilters.FilterStateStore.APP_STATE };
461+
});
462+
this._onFiltersChange([...this.props.filters, ...newFilters]);
463+
};
452464

465+
render() {
453466
return this.state.initialized ? (
454-
<div id="maps-plugin" className={isFullScreen ? 'mapFullScreen' : ''}>
467+
<div id="maps-plugin" className={this.props.isFullScreen ? 'mapFullScreen' : ''}>
455468
{this._renderTopNav()}
456469
<h1 className="euiScreenReaderOnly">{`screenTitle placeholder`}</h1>
457470
<div id="react-maps-root">
458-
<GisMap
459-
addFilters={(newFilters) => {
460-
newFilters.forEach((filter) => {
461-
filter.$state = { store: esFilters.FilterStateStore.APP_STATE };
462-
});
463-
this._updateFiltersAndDispatch([...filters, ...newFilters]);
464-
}}
465-
/>
471+
<GisMap addFilters={this._addFilter} />
466472
</div>
467473
</div>
468474
) : null;

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ export const getLayerList = createSelector(
297297
}
298298
);
299299

300+
export const getLayerListConfigOnly = createSelector(getLayerListRaw, (layerDescriptorList) => {
301+
return copyPersistentState(layerDescriptorList);
302+
});
303+
300304
export function getLayerById(layerId: string | null, state: MapStoreState): ILayer | undefined {
301305
return getLayerList(state).find((layer) => {
302306
return layerId === layer.getId();
@@ -416,23 +420,3 @@ export const areLayersLoaded = createSelector(
416420
return true;
417421
}
418422
);
419-
420-
export function hasUnsavedChanges(
421-
state: MapStoreState,
422-
savedMap: unknown,
423-
initialLayerListConfig: LayerDescriptor[]
424-
) {
425-
const layerListConfigOnly = copyPersistentState(getLayerListRaw(state));
426-
427-
// @ts-expect-error
428-
const savedLayerList = savedMap.getLayerList();
429-
430-
return !savedLayerList
431-
? !_.isEqual(layerListConfigOnly, initialLayerListConfig)
432-
: // savedMap stores layerList as a JSON string using JSON.stringify.
433-
// JSON.stringify removes undefined properties from objects.
434-
// savedMap.getLayerList converts the JSON string back into Javascript array of objects.
435-
// Need to perform the same process for layerListConfigOnly to compare apples to apples
436-
// and avoid undefined properties in layerListConfigOnly triggering unsaved changes.
437-
!_.isEqual(JSON.parse(JSON.stringify(layerListConfigOnly)), savedLayerList);
438-
}

yarn.lock

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,10 +3198,10 @@
31983198
resolved "https://registry.yarnpkg.com/@mapbox/geojson-types/-/geojson-types-1.0.2.tgz#9aecf642cb00eab1080a57c4f949a65b4a5846d6"
31993199
integrity sha512-e9EBqHHv3EORHrSfbR9DqecPNn+AmuAoQxV6aL8Xu30bJMJR1o8PZLZzpk1Wq7/NfCbuhmakHTPYRhoqLsXRnw==
32003200

3201-
"@mapbox/geojsonhint@^2.0.0":
3202-
version "2.2.0"
3203-
resolved "https://registry.yarnpkg.com/@mapbox/geojsonhint/-/geojsonhint-2.2.0.tgz#75ca94706e9a56e6debf4e1c78fabdc67978b883"
3204-
integrity sha512-8qQYRB+/2z2JsN5s6D0WAnpo69+3V3nvJsSFLwMB1dsaWz1V4oZeuoje9srbYAxxL8PXCwIywfhYa3GxOkBv5Q==
3201+
"@mapbox/geojsonhint@3.0.0":
3202+
version "3.0.0"
3203+
resolved "https://registry.yarnpkg.com/@mapbox/geojsonhint/-/geojsonhint-3.0.0.tgz#42448232ce4236cb89c1b69c36b0cadeac99e02e"
3204+
integrity sha512-zHcyh1rDHYnEBd6NvOWoeHLuvazlDkIjvz9MJx4cKwcKTlfrqgxVnTv1QLnVJnsSU5neJnhQJcgscR/Zl4uYgw==
32053205
dependencies:
32063206
concat-stream "^1.6.1"
32073207
jsonlint-lines "1.7.1"
@@ -3214,16 +3214,17 @@
32143214
resolved "https://registry.yarnpkg.com/@mapbox/jsonlint-lines-primitives/-/jsonlint-lines-primitives-2.0.2.tgz#ce56e539f83552b58d10d672ea4d6fc9adc7b234"
32153215
integrity sha1-zlblOfg1UrWNENZy6k1vya3HsjQ=
32163216

3217-
"@mapbox/mapbox-gl-draw@^1.1.2":
3218-
version "1.1.2"
3219-
resolved "https://registry.yarnpkg.com/@mapbox/mapbox-gl-draw/-/mapbox-gl-draw-1.1.2.tgz#247b3f0727db34c2641ab718df5eebeee69a2585"
3220-
integrity sha512-DWtATUAnJaGZYoH/y2O+QTRybxrp5y3w3eV5FXHFNVcKsCAojKEMB8ALKUG2IsiCKqV/JCAguK9AlPWR7Bjafw==
3217+
"@mapbox/mapbox-gl-draw@^1.2.0":
3218+
version "1.2.0"
3219+
resolved "https://registry.yarnpkg.com/@mapbox/mapbox-gl-draw/-/mapbox-gl-draw-1.2.0.tgz#b6e5278afef65bd5d7d92366034997768e478ad9"
3220+
integrity sha512-gMrP2zn8PzDtrs72FMJTPytCumX5vUn9R7IK38qBOVy9UfqbdWr56KYuNA/2X+jKn4FIOpmWf8CWkKpOaQkv7w==
32213221
dependencies:
32223222
"@mapbox/geojson-area" "^0.2.1"
32233223
"@mapbox/geojson-extent" "^0.3.2"
32243224
"@mapbox/geojson-normalize" "0.0.1"
3225-
"@mapbox/geojsonhint" "^2.0.0"
3225+
"@mapbox/geojsonhint" "3.0.0"
32263226
"@mapbox/point-geometry" "0.1.0"
3227+
eslint-plugin-import "^2.19.1"
32273228
hat "0.0.3"
32283229
lodash.isequal "^4.2.0"
32293230
xtend "^4.0.1"

0 commit comments

Comments
 (0)