diff --git a/web/client/plugins/Identify.jsx b/web/client/plugins/Identify.jsx index d97af38eba..5c9acb5c58 100644 --- a/web/client/plugins/Identify.jsx +++ b/web/client/plugins/Identify.jsx @@ -177,17 +177,39 @@ const identifyDefaultProps = defaultProps({ /** * This plugin allows get information about clicked point. It can be configured to have a mobile or a desktop flavor. * - * You can configure some of the features of this plugin by setting up the initial mapInfo state, then you need to update the "initialState.defaultState", or by the plugin configuration + * You can configure app-wide defaults for new maps by setting the initial mapInfo + * state in localConfig.json, or by the plugin configuration: + * ```json + * "initialState": { + * "defaultState": { + * "mapInfo": { + * "enabled": true, + * "disabledAlwaysOn": false, + * "configuration": { + * "showEmptyMessageGFI": false, + * "infoFormat": "text/plain" + * } + * } + * } + * } * ``` - * "mapInfo": { - * "enabled": true, // enabled by default - * "disabledAlwaysOn": false, // if true, disable always on setup - * "configuration": { - * "showEmptyMessageGFI": false // allow or deny the visibility of message when you have no results from identify request - * "infoFormat": "text/plain" // default infoformat value, other values are "text/html" for text only or "application/json" for properties + * + * Saved map-specific Identify settings are stored in the map configuration as a + * top-level "mapInfoConfiguration" property, sibling of "map". Use the same + * top-level property in a map template such as new.json when the template needs + * its own Identify settings: + * ```json + * { + * "version": 2, + * "map": {}, + * "mapInfoConfiguration": { + * "showEmptyMessageGFI": false, + * "infoFormat": "text/html" * } * } * ``` + * When both configurations are present, "mapInfoConfiguration" takes precedence + * for the loaded map; otherwise the app-wide default is used. * * @class Identify * @memberof plugins diff --git a/web/client/reducers/__tests__/mapInfo-test.js b/web/client/reducers/__tests__/mapInfo-test.js index 501f9040a6..39d6e83265 100644 --- a/web/client/reducers/__tests__/mapInfo-test.js +++ b/web/client/reducers/__tests__/mapInfo-test.js @@ -397,6 +397,54 @@ describe('Test the mapInfo reducer', () => { expect(state.configuration.infoFormat).toBe(newInfoFormat); }); + it('MAP_CONFIG_LOADED should restore default mapInfo configuration when loading a map without mapInfoConfiguration', () => { + const defaultConfiguration = { + infoFormat: "application/json", + showEmptyMessageGFI: false + }; + let state = mapInfo({ + configuration: defaultConfiguration + }, { + type: MAP_CONFIG_LOADED, + config: { + mapInfoConfiguration: { + infoFormat: "text/html", + showEmptyMessageGFI: true + } + } + }); + + expect(state.configuration.infoFormat).toBe("text/html"); + expect(state.configuration.showEmptyMessageGFI).toBe(true); + + state = mapInfo(state, { + type: MAP_CONFIG_LOADED, + config: {} + }); + + expect(state.configuration).toEqual(defaultConfiguration); + }); + + it('MAP_CONFIG_LOADED should reset mapInfo configuration when no default is configured', () => { + let state = mapInfo(undefined, { + type: MAP_CONFIG_LOADED, + config: { + mapInfoConfiguration: { + infoFormat: "text/html" + } + } + }); + + expect(state.configuration.infoFormat).toBe("text/html"); + + state = mapInfo(state, { + type: MAP_CONFIG_LOADED, + config: {} + }); + + expect(state.configuration).toEqual({}); + }); + it('toggleShowCoordinateEditor', () => { let state = mapInfo({}, toggleShowCoordinateEditor(true)); expect(state).toExist(); diff --git a/web/client/reducers/mapInfo.js b/web/client/reducers/mapInfo.js index 2bcd31f9a7..0c0c2e0379 100644 --- a/web/client/reducers/mapInfo.js +++ b/web/client/reducers/mapInfo.js @@ -144,6 +144,8 @@ const initState = { configuration: {} }; +const getDefaultConfiguration = (state) => state.defaultConfiguration || state.configuration || {}; + /** * Manages the map info tool state. Contains configurations and responses. * @prop {boolean} [enabled=true] if true, the info tool is enabled by default @@ -365,9 +367,11 @@ function mapInfo(state = initState, action) { }; } case MAP_CONFIG_LOADED: { + const defaultConfiguration = getDefaultConfiguration(state); return { ...state, - configuration: action.config.mapInfoConfiguration || state.configuration || {} + defaultConfiguration, + configuration: action.config?.mapInfoConfiguration || defaultConfiguration }; } case CHANGE_FORMAT: {