Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions web/client/plugins/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions web/client/reducers/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion web/client/reducers/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down
Loading