Skip to content

Commit f61c402

Browse files
#11777: fix issue of coordinate in the GFI and Share-tool depend on each other instead of the config in localConfig.json (#11778)
Descrption: - create local state for format coordinate in Share plugin instead of using mapInfo one - add unit test
1 parent c45dfe5 commit f61c402

2 files changed

Lines changed: 90 additions & 7 deletions

File tree

web/client/plugins/Share.jsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
import React from 'react';
9+
import React, {useState} from 'react';
1010
import {connect, createPlugin} from '../utils/PluginsUtils';
1111
import { Glyphicon } from 'react-bootstrap';
1212
import Message from '../components/I18N/Message';
@@ -22,7 +22,6 @@ import { mapIdSelector, mapSelector } from '../selectors/map';
2222
import { currentContextSelector } from '../selectors/context';
2323
import { get } from 'lodash';
2424
import controls from '../reducers/controls';
25-
import { changeFormat } from '../actions/mapInfo';
2625
import { addMarker, hideMarker } from '../actions/search';
2726
import { updateMapView } from '../actions/map';
2827
import { resourceSelector as geostoryResourceSelector, updateUrlOnScrollSelector } from '../selectors/geostory';
@@ -69,7 +68,6 @@ const Share = connect(createSelector([
6968
mapTypeSelector,
7069
currentContextSelector,
7170
state => get(state, 'controls.share.settings', {}),
72-
(state) => state.mapInfo && state.mapInfo.formatCoord || ConfigUtils.getConfigProp("defaultCoordinateFormat"),
7371
state => state.search && state.search.markerPosition || {},
7472
updateUrlOnScrollSelector,
7573
state => get(state, 'map.present.viewerOptions'),
@@ -84,7 +82,7 @@ const Share = connect(createSelector([
8482
},
8583
state => get(state, 'controls.share.resource.shareUrl') || location.href,
8684
state => get(state, 'controls.share.resource.categoryName')
87-
], (isVisible, version, map, mapType, context, settings, formatCoords, point, isScrollPosition, viewerOptions, center, shareUrl, categoryName) => ({
85+
], (isVisible, version, map, mapType, context, settings, point, isScrollPosition, viewerOptions, center, shareUrl, categoryName) => ({
8886
isVisible,
8987
shareUrl,
9088
shareApiUrl: getApiUrl(shareUrl),
@@ -104,20 +102,19 @@ const Share = connect(createSelector([
104102
bbox: true,
105103
centerAndZoom: true
106104
},
107-
formatCoords: formatCoords,
108105
point,
109106
isScrollPosition,
110107
categoryName})), {
111108
onClose: toggleControl.bind(null, 'share', null),
112109
hideMarker,
113110
updateMapView,
114111
onUpdateSettings: setControlProperty.bind(null, 'share', 'settings'),
115-
onChangeFormat: changeFormat,
116112
addMarker: addMarker,
117113
onClearShareResource: setControlProperty.bind(null, 'share', 'resource', undefined)
118114
})(({ categoryName, ...props }) => {
115+
const [formatCoord, setFormatCoords] = useState(ConfigUtils.getConfigProp("defaultCoordinateFormat") || 'decimal');
119116
const categoryCfg = props[categoryName];
120-
return <SharePanel {...props} {...categoryCfg} />;
117+
return <SharePanel {...props} {...categoryCfg} onChangeFormat={setFormatCoords} formatCoords={formatCoord} />;
121118
});
122119

123120
const ActionCardShareButton = connect(

web/client/plugins/__tests__/Share-test.jsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { TOGGLE_CONTROL } from '../../actions/controls';
1717
import { PURGE_MAPINFO_RESULTS, HIDE_MAPINFO_MARKER } from '../../actions/mapInfo';
1818
import mapInfo from '../../reducers/mapInfo';
1919
import search from '../../reducers/search';
20+
import ConfigUtils from '../../utils/ConfigUtils';
2021

2122
describe('Share Plugin', () => {
2223
beforeEach(() => {
@@ -485,4 +486,89 @@ describe('Share Plugin', () => {
485486
expect(toNumber(lon.value)).toBe(-80);
486487
expect(toNumber(zoom.value)).toBe(5);
487488
});
489+
it('test Share plugin with coordinate editor with default decimal formatCoord', () => {
490+
let storeState = {
491+
map: {
492+
center: {
493+
crs: "EPSG:4326",
494+
x: -86.25,
495+
y: 38.07
496+
},
497+
zoom: 5
498+
},
499+
controls: {
500+
share: {
501+
enabled: true,
502+
settings: {
503+
centerAndZoomEnabled: true
504+
}
505+
}
506+
},
507+
search: {
508+
markerPosition: {latlng: {lat: 40, lng: -80}}
509+
}
510+
};
511+
const props = {
512+
advancedSettings: {
513+
centerAndZoom: true,
514+
defaultEnabled: "markerAndZoom"
515+
}
516+
};
517+
const {Plugin} = getPluginForTest({...SharePlugin, reducers: {
518+
mapInfo,
519+
search
520+
}}, storeState);
521+
ReactDOM.render(<Plugin {...props}/>, document.getElementById("container"));
522+
const sharePanelElem = document.getElementsByClassName('share-panel-modal-body')[0];
523+
expect(sharePanelElem).toExist();
524+
let coordinateLngLatElems = sharePanelElem.querySelectorAll(".coordinate .input-group-container .input-group .form-group");
525+
526+
expect(coordinateLngLatElems.length).toEqual(2);
527+
});
528+
it('test Share plugin with coordinate editor with auronautical formatCoord', () => {
529+
let storeState = {
530+
map: {
531+
center: {
532+
crs: "EPSG:4326",
533+
x: -86.25,
534+
y: 38.07
535+
},
536+
zoom: 5
537+
},
538+
controls: {
539+
share: {
540+
enabled: true,
541+
settings: {
542+
centerAndZoomEnabled: true
543+
}
544+
}
545+
},
546+
search: {
547+
markerPosition: {latlng: {lat: 40, lng: -80}}
548+
}
549+
};
550+
const props = {
551+
advancedSettings: {
552+
centerAndZoom: true,
553+
defaultEnabled: "markerAndZoom"
554+
}
555+
};
556+
ConfigUtils.setConfigProp('defaultCoordinateFormat', "aeronautical");
557+
const {Plugin} = getPluginForTest({...SharePlugin, reducers: {
558+
mapInfo,
559+
search
560+
}}, storeState);
561+
ReactDOM.render(<Plugin {...props} />, document.getElementById("container"));
562+
const sharePanelElem = document.getElementsByClassName('share-panel-modal-body')[0];
563+
expect(sharePanelElem).toExist();
564+
let coordinateLngLatElems = sharePanelElem.querySelectorAll(".coordinate .input-group-container .input-group .form-group");
565+
566+
expect(coordinateLngLatElems.length).toEqual(2);
567+
expect(coordinateLngLatElems[0].childNodes.length).toEqual(4);
568+
expect(coordinateLngLatElems[0].querySelector('.degrees')).toExist();
569+
expect(coordinateLngLatElems[0].querySelector('.minutes')).toExist();
570+
expect(coordinateLngLatElems[0].querySelector('.seconds')).toExist();
571+
expect(coordinateLngLatElems[0].querySelector('.direction-select')).toExist();
572+
ConfigUtils.removeConfigProp('defaultCoordinateFormat');
573+
});
488574
});

0 commit comments

Comments
 (0)