Skip to content

Commit

Permalink
geosolutions-it#9825: Add option to enable mapInfo highlight by default
Browse files Browse the repository at this point in the history
* Description:
- resolve review comments by using INIT_PLUGIN action instead of the new created one
- Remove the new created action ' INIT_IDENTIFY_HIGHLIGHT' and its dependent code
- Remove the added config from localConfig file
  • Loading branch information
mahmoudadel54 committed Dec 21, 2023
1 parent 480fabf commit 2fe3010
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 45 deletions.
10 changes: 1 addition & 9 deletions web/client/actions/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ import {
checkIdentifyIsMounted,
IDENTIFY_IS_MOUNTED,
onInitPlugin,
INIT_PLUGIN,
INIT_IDENTIFY_HIGHLIGHT,
initiateOrResetHighlight
INIT_PLUGIN
} from '../mapInfo';

describe('Test correctness of the map actions', () => {
Expand Down Expand Up @@ -168,10 +166,4 @@ describe('Test correctness of the map actions', () => {
it('onInitPlugin', () => {
expect(onInitPlugin({cfg1: false})).toEqual({type: INIT_PLUGIN, cfg: {cfg1: false} });
});
it('initiateOrResetHighlight if highlight default value equal true', () => {
expect(initiateOrResetHighlight(true)).toEqual({type: INIT_IDENTIFY_HIGHLIGHT, identifyHighlight: true });
});
it('initiateOrResetHighlight if highlight default value equal false', () => {
expect(initiateOrResetHighlight(false)).toEqual({type: INIT_IDENTIFY_HIGHLIGHT, identifyHighlight: false });
});
});
7 changes: 0 additions & 7 deletions web/client/actions/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const TOGGLE_EMPTY_MESSAGE_GFI = "IDENTIFY:TOGGLE_EMPTY_MESSAGE_GFI";
export const SET_SHOW_IN_MAP_POPUP = "IDENTIFY:SET_SHOW_IN_MAP_POPUP";
export const IDENTIFY_IS_MOUNTED = "IDENTIFY:IDENTIFY_IS_MOUNTED";
export const INIT_PLUGIN = 'IDENTIFY:INIT_PLUGIN';
export const INIT_IDENTIFY_HIGHLIGHT = 'IDENTIFY:INIT_IDENTIFY_HIGHLIGHT';

export const toggleEmptyMessageGFI = () => ({type: TOGGLE_EMPTY_MESSAGE_GFI});

Expand Down Expand Up @@ -289,9 +288,3 @@ export const checkIdentifyIsMounted = (isMounted)=> ({
});

export const onInitPlugin = (cfg) => ({type: INIT_PLUGIN, cfg});
/**
* Action performed when the identify component opened to initiate the default value of highight
* @param {boolean} highlight
* @returns {{type: string, identifyHighlight: boolean}}
*/
export const initiateOrResetHighlight = (highlight) => ({type: INIT_IDENTIFY_HIGHLIGHT, identifyHighlight: highlight});
6 changes: 4 additions & 2 deletions web/client/components/data/identify/IdentifyContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default props => {
validator = () => null,
disableCoordinatesRow,
disableInfoAlert,
initiateOrResetHighlight,
onInitPlugin = () => {},
pluginCfg
} = props;
const latlng = point && point.latlng || null;
Expand Down Expand Up @@ -123,7 +123,9 @@ export default props => {
draggable={draggable}
onClose={() => {
onClose();
initiateOrResetHighlight(pluginCfg?.identifyHighlight || false);
onInitPlugin({
highlight: pluginCfg?.highlightEnabledFromTheStart || false
});
}}
dock={dock}
style={dockStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ describe("test IdentifyContainer", () => {
expect(glyphIcons.forEach(glyph => glyph.className) !== 'zoom-to').toBeTruthy();
});

it('test call initiateOrResetHighlight on Close', () => {
it('test call onInitPlugin on Close', () => {
const requests = [{reqId: 1}, {reqId: 2}];
const callbacks = {
initiateOrResetHighlight: () => {}
onInitPlugin: () => {}
};
const initiateOrResetHighlightSpy = expect.spyOn(callbacks, 'initiateOrResetHighlight');
const onInitPluginSpy = expect.spyOn(callbacks, 'onInitPlugin');
const responses = [{layerMetadata: {title: "Layer 1"}}, {layerMetadata: {title: "Layer 2"}}];
const CMP = (<IdentifyContainer
enabled
Expand All @@ -272,7 +272,7 @@ describe("test IdentifyContainer", () => {
getFeatureButtons={getFeatureButtons}
point={{latlng: {lat: 1, lng: 1}}}
showCoordinateEditor={false}
initiateOrResetHighlight={callbacks.initiateOrResetHighlight}
onInitPlugin={callbacks.onInitPlugin}
/>);
ReactDOM.render(CMP, document.getElementById("container"));
const container = document.getElementById('container');
Expand All @@ -281,7 +281,7 @@ describe("test IdentifyContainer", () => {
TestUtils.act(() => {
ReactDOM.render(CMP, document.getElementById("container"));
});
expect(initiateOrResetHighlightSpy).toHaveBeenCalled();
expect(onInitPluginSpy).toHaveBeenCalled();
// Test since when the highlight feature is disabled the zoom Icon is not shown
const zoomIcon = document.querySelector('.glyphicon-zoom-to');
expect(zoomIcon).toNotExist();
Expand Down
6 changes: 3 additions & 3 deletions web/client/components/data/identify/enhancers/identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const identifyLifecycle = compose(
setShowInMapPopup = () => {},
checkIdentifyIsMounted = () => {},
onInitPlugin = () => {},
initiateOrResetHighlight = () => {}
pluginCfg = {}
} = this.props;

// Initialize plugin configuration
Expand All @@ -88,9 +88,9 @@ export const identifyLifecycle = compose(
configuration: {
maxItems
},
showAllResponses
showAllResponses,
highlight: pluginCfg?.highlightEnabledFromTheStart || false
});
initiateOrResetHighlight(this.props?.pluginCfg?.identifyHighlight || false);
if (enabled || showInMapPopup) {
changeMousePointer('pointer');
checkIdentifyIsMounted(true);
Expand Down
1 change: 0 additions & 1 deletion web/client/configs/localConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@
"name": "Identify",
"cfg": {
"showHighlightFeatureButton": true,
"identifyHighlight":false,
"viewerOptions": {
"container": "{context.ReactSwipe}"
},
Expand Down
6 changes: 2 additions & 4 deletions web/client/plugins/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import {
updateCenterToMarker,
updateFeatureInfoClickPoint,
checkIdentifyIsMounted,
onInitPlugin,
initiateOrResetHighlight
onInitPlugin
} from '../actions/mapInfo';
import DefaultViewerComp from '../components/data/identify/DefaultViewer';
import { defaultViewerDefaultProps, defaultViewerHandlers } from '../components/data/identify/enhancers/defaultViewer';
Expand Down Expand Up @@ -197,7 +196,7 @@ const identifyDefaultProps = defaultProps({
* @prop cfg.dock {bool} true shows dock panel, false shows modal
* @prop cfg.draggable {boolean} draggable info window, when modal
* @prop cfg.showHighlightFeatureButton {boolean} show the highlight feature button if the interrogation returned valid features (openlayers only)
* @prop cfg.identifyHighlight {boolean} the highlight feature button will be activated by default if true
* @prop cfg.highlightEnabledFromTheStart {boolean} the highlight feature button will be activated by default if true
* @prop cfg.viewerOptions.container {expression} the container of the viewer, expression from the context
* @prop cfg.viewerOptions.header {expression} the header of the viewer, expression from the context{expression}
* @prop cfg.disableCenterToMarker {bool} disable zoom to marker action
Expand Down Expand Up @@ -227,7 +226,6 @@ const identifyDefaultProps = defaultProps({
const IdentifyPlugin = compose(
connect(selector, {
onInitPlugin,
initiateOrResetHighlight,
purgeResults: purgeMapInfoResults,
closeIdentify,
onSubmitClickPoint: updateFeatureInfoClickPoint,
Expand Down
11 changes: 5 additions & 6 deletions web/client/reducers/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
toggleHighlightFeature,
setMapTrigger,
setShowInMapPopup,
onInitPlugin,
initiateOrResetHighlight
onInitPlugin
} from '../../actions/mapInfo';
import {changeVisualizationMode} from '../../actions/maptype';
import { MAP_CONFIG_LOADED } from '../../actions/config';
Expand Down Expand Up @@ -450,14 +449,14 @@ describe('Test the mapInfo reducer', () => {
expect(state.cfg1).toEqual("test");
expect(state.configuration).toEqual({maxItems: 3});
});
it('initiateOrResetHighlight if highlight default value equal true', () => {
it('initiateOrResetHighlight via onInitPlugin if highlight default value equal true', () => {
const initialState = { configuration: {} };
const state = mapInfo(initialState, initiateOrResetHighlight(true));
const state = mapInfo(initialState, onInitPlugin({highlight: true}));
expect(state.highlight).toEqual(true);
});
it('initiateOrResetHighlight if highlight default value equal false', () => {
it('initiateOrResetHighlight via onInitPlugin if highlight default value equal false', () => {
const initialState = { configuration: {} };
const state = mapInfo(initialState, initiateOrResetHighlight(false));
const state = mapInfo(initialState, onInitPlugin({highlight: false}));
expect(state.highlight).toEqual(false);
});
});
9 changes: 1 addition & 8 deletions web/client/reducers/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import {
SET_CURRENT_EDIT_FEATURE_QUERY,
SET_MAP_TRIGGER,
SET_SHOW_IN_MAP_POPUP,
INIT_PLUGIN,
INIT_IDENTIFY_HIGHLIGHT
INIT_PLUGIN
} from '../actions/mapInfo';
import { VISUALIZATION_MODE_CHANGED } from '../actions/maptype';

Expand Down Expand Up @@ -411,12 +410,6 @@ function mapInfo(state = initState, action) {
}
};
}
case INIT_IDENTIFY_HIGHLIGHT: {
return {
...state,
highlight: action.identifyHighlight
};
}
default:
return state;
}
Expand Down

0 comments on commit 2fe3010

Please sign in to comment.