From 9b9c1edf5c4e461a29323918059e5d4e6777f3c5 Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Tue, 19 Dec 2023 08:12:37 +0200 Subject: [PATCH 1/3] #9825: Add option to enable mapInfo highlight by default * Description: - Adding an option called "identifyHighlight" to enable/disable mapInfo highlight by default in localConfig file - implement intiate highlight value based on the added option and the default is false - write unit tests based on change --- web/client/actions/__tests__/mapInfo-test.js | 10 +++++++++- web/client/actions/mapInfo.js | 7 +++++++ .../components/data/identify/IdentifyContainer.jsx | 7 ++++--- .../components/data/identify/enhancers/identify.js | 5 +++-- web/client/configs/localConfig.json | 1 + web/client/plugins/Identify.jsx | 5 ++++- web/client/reducers/__tests__/mapInfo-test.js | 13 ++++++++++++- web/client/reducers/mapInfo.js | 9 ++++++++- 8 files changed, 48 insertions(+), 9 deletions(-) diff --git a/web/client/actions/__tests__/mapInfo-test.js b/web/client/actions/__tests__/mapInfo-test.js index 344fd303ab..9b5c2ef971 100644 --- a/web/client/actions/__tests__/mapInfo-test.js +++ b/web/client/actions/__tests__/mapInfo-test.js @@ -42,7 +42,9 @@ import { checkIdentifyIsMounted, IDENTIFY_IS_MOUNTED, onInitPlugin, - INIT_PLUGIN + INIT_PLUGIN, + INIT_IDENTIFY_HIGHLIGHT, + initiateOrResetHighlight } from '../mapInfo'; describe('Test correctness of the map actions', () => { @@ -166,4 +168,10 @@ 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 }); + }); }); diff --git a/web/client/actions/mapInfo.js b/web/client/actions/mapInfo.js index fdbdc37bce..a1973d27df 100644 --- a/web/client/actions/mapInfo.js +++ b/web/client/actions/mapInfo.js @@ -38,6 +38,7 @@ 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}); @@ -288,3 +289,9 @@ 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}); diff --git a/web/client/components/data/identify/IdentifyContainer.jsx b/web/client/components/data/identify/IdentifyContainer.jsx index 93ade34308..94216748a8 100644 --- a/web/client/components/data/identify/IdentifyContainer.jsx +++ b/web/client/components/data/identify/IdentifyContainer.jsx @@ -71,9 +71,10 @@ export default props => { formatCoord, loaded, validator = () => null, - toggleHighlightFeature = () => {}, disableCoordinatesRow, - disableInfoAlert + disableInfoAlert, + initiateOrResetHighlight, + pluginCfg } = props; const latlng = point && point.latlng || null; @@ -122,7 +123,7 @@ export default props => { draggable={draggable} onClose={() => { onClose(); - toggleHighlightFeature(false); + initiateOrResetHighlight(pluginCfg?.identifyHighlight || false); }} dock={dock} style={dockStyle} diff --git a/web/client/components/data/identify/enhancers/identify.js b/web/client/components/data/identify/enhancers/identify.js index 283c686a56..d6c1d174bb 100644 --- a/web/client/components/data/identify/enhancers/identify.js +++ b/web/client/components/data/identify/enhancers/identify.js @@ -78,7 +78,8 @@ export const identifyLifecycle = compose( onEnableCenterToMarker = () => {}, setShowInMapPopup = () => {}, checkIdentifyIsMounted = () => {}, - onInitPlugin = () => {} + onInitPlugin = () => {}, + initiateOrResetHighlight = () => {} } = this.props; // Initialize plugin configuration @@ -89,7 +90,7 @@ export const identifyLifecycle = compose( }, showAllResponses }); - + initiateOrResetHighlight(this.props?.pluginCfg?.identifyHighlight || false); if (enabled || showInMapPopup) { changeMousePointer('pointer'); checkIdentifyIsMounted(true); diff --git a/web/client/configs/localConfig.json b/web/client/configs/localConfig.json index dadcf5f379..054d89c3d1 100644 --- a/web/client/configs/localConfig.json +++ b/web/client/configs/localConfig.json @@ -408,6 +408,7 @@ "name": "Identify", "cfg": { "showHighlightFeatureButton": true, + "identifyHighlight":false, "viewerOptions": { "container": "{context.ReactSwipe}" }, diff --git a/web/client/plugins/Identify.jsx b/web/client/plugins/Identify.jsx index 52f8a4669b..2eac3103fd 100644 --- a/web/client/plugins/Identify.jsx +++ b/web/client/plugins/Identify.jsx @@ -36,7 +36,8 @@ import { updateCenterToMarker, updateFeatureInfoClickPoint, checkIdentifyIsMounted, - onInitPlugin + onInitPlugin, + initiateOrResetHighlight } from '../actions/mapInfo'; import DefaultViewerComp from '../components/data/identify/DefaultViewer'; import { defaultViewerDefaultProps, defaultViewerHandlers } from '../components/data/identify/enhancers/defaultViewer'; @@ -196,6 +197,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.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 @@ -225,6 +227,7 @@ const identifyDefaultProps = defaultProps({ const IdentifyPlugin = compose( connect(selector, { onInitPlugin, + initiateOrResetHighlight, purgeResults: purgeMapInfoResults, closeIdentify, onSubmitClickPoint: updateFeatureInfoClickPoint, diff --git a/web/client/reducers/__tests__/mapInfo-test.js b/web/client/reducers/__tests__/mapInfo-test.js index 5951d2cacb..99f4d160ac 100644 --- a/web/client/reducers/__tests__/mapInfo-test.js +++ b/web/client/reducers/__tests__/mapInfo-test.js @@ -20,7 +20,8 @@ import { toggleHighlightFeature, setMapTrigger, setShowInMapPopup, - onInitPlugin + onInitPlugin, + initiateOrResetHighlight } from '../../actions/mapInfo'; import {changeVisualizationMode} from '../../actions/maptype'; import { MAP_CONFIG_LOADED } from '../../actions/config'; @@ -449,4 +450,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', () => { + const initialState = { configuration: {} }; + const state = mapInfo(initialState, initiateOrResetHighlight(true)); + expect(state.highlight).toEqual(true); + }); + it('initiateOrResetHighlight if highlight default value equal false', () => { + const initialState = { configuration: {} }; + const state = mapInfo(initialState, initiateOrResetHighlight(false)); + expect(state.highlight).toEqual(false); + }); }); diff --git a/web/client/reducers/mapInfo.js b/web/client/reducers/mapInfo.js index 7c0260bedf..d7faf9a831 100644 --- a/web/client/reducers/mapInfo.js +++ b/web/client/reducers/mapInfo.js @@ -35,7 +35,8 @@ import { SET_CURRENT_EDIT_FEATURE_QUERY, SET_MAP_TRIGGER, SET_SHOW_IN_MAP_POPUP, - INIT_PLUGIN + INIT_PLUGIN, + INIT_IDENTIFY_HIGHLIGHT } from '../actions/mapInfo'; import { VISUALIZATION_MODE_CHANGED } from '../actions/maptype'; @@ -410,6 +411,12 @@ function mapInfo(state = initState, action) { } }; } + case INIT_IDENTIFY_HIGHLIGHT: { + return { + ...state, + highlight: action.identifyHighlight + }; + } default: return state; } From 480fabf71dcdb79a2b0fd72ebdfad508a26957a6 Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Tue, 19 Dec 2023 08:44:02 +0200 Subject: [PATCH 2/3] #9825: Add option to enable mapInfo highlight by default * Description: - fix FE test failure by editing a unit test in identifyContainer that test calling initiateOrResetHighlight on close identify --- .../data/identify/__tests__/IdentifyContainer-test.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx b/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx index 00a17ba303..2a2dfc9716 100644 --- a/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx +++ b/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx @@ -257,12 +257,12 @@ describe("test IdentifyContainer", () => { expect(glyphIcons.forEach(glyph => glyph.className) !== 'zoom-to').toBeTruthy(); }); - it('test call toggleHighlightFeature on Close', () => { + it('test call initiateOrResetHighlight on Close', () => { const requests = [{reqId: 1}, {reqId: 2}]; const callbacks = { - toggleHighlightFeature: () => {} + initiateOrResetHighlight: () => {} }; - const toggleHighlightFeatureSpy = expect.spyOn(callbacks, 'toggleHighlightFeature'); + const initiateOrResetHighlightSpy = expect.spyOn(callbacks, 'initiateOrResetHighlight'); const responses = [{layerMetadata: {title: "Layer 1"}}, {layerMetadata: {title: "Layer 2"}}]; const CMP = ( { getFeatureButtons={getFeatureButtons} point={{latlng: {lat: 1, lng: 1}}} showCoordinateEditor={false} - toggleHighlightFeature={callbacks.toggleHighlightFeature} + initiateOrResetHighlight={callbacks.initiateOrResetHighlight} />); ReactDOM.render(CMP, document.getElementById("container")); const container = document.getElementById('container'); @@ -281,7 +281,7 @@ describe("test IdentifyContainer", () => { TestUtils.act(() => { ReactDOM.render(CMP, document.getElementById("container")); }); - expect(toggleHighlightFeatureSpy).toHaveBeenCalled(); + expect(initiateOrResetHighlightSpy).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(); From 2fe3010aaeabefa2c12305079bdbdf6c7e48112d Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Thu, 21 Dec 2023 14:18:45 +0200 Subject: [PATCH 3/3] #9825: Add option to enable mapInfo highlight by default * 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 --- web/client/actions/__tests__/mapInfo-test.js | 10 +--------- web/client/actions/mapInfo.js | 7 ------- .../components/data/identify/IdentifyContainer.jsx | 6 ++++-- .../identify/__tests__/IdentifyContainer-test.jsx | 10 +++++----- .../components/data/identify/enhancers/identify.js | 6 +++--- web/client/configs/localConfig.json | 1 - web/client/plugins/Identify.jsx | 6 ++---- web/client/reducers/__tests__/mapInfo-test.js | 11 +++++------ web/client/reducers/mapInfo.js | 9 +-------- 9 files changed, 21 insertions(+), 45 deletions(-) diff --git a/web/client/actions/__tests__/mapInfo-test.js b/web/client/actions/__tests__/mapInfo-test.js index 9b5c2ef971..344fd303ab 100644 --- a/web/client/actions/__tests__/mapInfo-test.js +++ b/web/client/actions/__tests__/mapInfo-test.js @@ -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', () => { @@ -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 }); - }); }); diff --git a/web/client/actions/mapInfo.js b/web/client/actions/mapInfo.js index a1973d27df..fdbdc37bce 100644 --- a/web/client/actions/mapInfo.js +++ b/web/client/actions/mapInfo.js @@ -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}); @@ -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}); diff --git a/web/client/components/data/identify/IdentifyContainer.jsx b/web/client/components/data/identify/IdentifyContainer.jsx index 94216748a8..6bd5f18bfa 100644 --- a/web/client/components/data/identify/IdentifyContainer.jsx +++ b/web/client/components/data/identify/IdentifyContainer.jsx @@ -73,7 +73,7 @@ export default props => { validator = () => null, disableCoordinatesRow, disableInfoAlert, - initiateOrResetHighlight, + onInitPlugin = () => {}, pluginCfg } = props; const latlng = point && point.latlng || null; @@ -123,7 +123,9 @@ export default props => { draggable={draggable} onClose={() => { onClose(); - initiateOrResetHighlight(pluginCfg?.identifyHighlight || false); + onInitPlugin({ + highlight: pluginCfg?.highlightEnabledFromTheStart || false + }); }} dock={dock} style={dockStyle} diff --git a/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx b/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx index 2a2dfc9716..ad9c39f433 100644 --- a/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx +++ b/web/client/components/data/identify/__tests__/IdentifyContainer-test.jsx @@ -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 = ( { 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'); @@ -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(); diff --git a/web/client/components/data/identify/enhancers/identify.js b/web/client/components/data/identify/enhancers/identify.js index d6c1d174bb..03724ec45e 100644 --- a/web/client/components/data/identify/enhancers/identify.js +++ b/web/client/components/data/identify/enhancers/identify.js @@ -79,7 +79,7 @@ export const identifyLifecycle = compose( setShowInMapPopup = () => {}, checkIdentifyIsMounted = () => {}, onInitPlugin = () => {}, - initiateOrResetHighlight = () => {} + pluginCfg = {} } = this.props; // Initialize plugin configuration @@ -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); diff --git a/web/client/configs/localConfig.json b/web/client/configs/localConfig.json index 054d89c3d1..dadcf5f379 100644 --- a/web/client/configs/localConfig.json +++ b/web/client/configs/localConfig.json @@ -408,7 +408,6 @@ "name": "Identify", "cfg": { "showHighlightFeatureButton": true, - "identifyHighlight":false, "viewerOptions": { "container": "{context.ReactSwipe}" }, diff --git a/web/client/plugins/Identify.jsx b/web/client/plugins/Identify.jsx index 2eac3103fd..30479ae208 100644 --- a/web/client/plugins/Identify.jsx +++ b/web/client/plugins/Identify.jsx @@ -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'; @@ -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 @@ -227,7 +226,6 @@ const identifyDefaultProps = defaultProps({ const IdentifyPlugin = compose( connect(selector, { onInitPlugin, - initiateOrResetHighlight, purgeResults: purgeMapInfoResults, closeIdentify, onSubmitClickPoint: updateFeatureInfoClickPoint, diff --git a/web/client/reducers/__tests__/mapInfo-test.js b/web/client/reducers/__tests__/mapInfo-test.js index 99f4d160ac..837ae71da2 100644 --- a/web/client/reducers/__tests__/mapInfo-test.js +++ b/web/client/reducers/__tests__/mapInfo-test.js @@ -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'; @@ -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); }); }); diff --git a/web/client/reducers/mapInfo.js b/web/client/reducers/mapInfo.js index d7faf9a831..7c0260bedf 100644 --- a/web/client/reducers/mapInfo.js +++ b/web/client/reducers/mapInfo.js @@ -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'; @@ -411,12 +410,6 @@ function mapInfo(state = initState, action) { } }; } - case INIT_IDENTIFY_HIGHLIGHT: { - return { - ...state, - highlight: action.identifyHighlight - }; - } default: return state; }