Skip to content

Commit

Permalink
Fix geosolutions-it#9172 add flag to always select first layer in toc…
Browse files Browse the repository at this point in the history
… in identify results (geosolutions-it#9174)

* Fix geosolutions-it#9172 add flag to always select first layer in toc in identify results

* rename flag
  • Loading branch information
MV88 authored Jun 19, 2023
1 parent 3af3f96 commit 0e5a381
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 18 deletions.
2 changes: 2 additions & 0 deletions web/client/components/data/identify/IdentifyContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default props => {
onClose = () => {},
responses = [],
index,
showAllResponses,
viewerOptions = {},
format,
dock = true,
Expand Down Expand Up @@ -134,6 +135,7 @@ export default props => {
<LayerSelector
responses={responses}
index={index}
showAllResponses={showAllResponses}
loaded={loaded}
setIndex={setIndex}
missingResponses={missingResponses}
Expand Down
13 changes: 10 additions & 3 deletions web/client/components/data/identify/LayerSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {isEmpty} from 'lodash';
import localizedProps from '../../misc/enhancers/localizedProps';
const SelectLocalized = localizedProps(['placeholder', 'clearValueText', 'noResultsText'])(Select);

const LayerSelector = ({ responses, index, loaded, setIndex, missingResponses, emptyResponses, validator, format}) => {
const LayerSelector = ({ responses, index, loaded, setIndex, missingResponses, emptyResponses, validator, format, showAllResponses = false}) => {
const selectProps = {clearable: false, isSearchable: true};
const [options, setOptions] = useState([]);
const [title, setTitle] = useState("");
Expand All @@ -22,9 +22,16 @@ const LayerSelector = ({ responses, index, loaded, setIndex, missingResponses, e
if (!isEmpty(responses)) {
setOptions(responses.map((opt, idx)=> {
const value = opt?.layerMetadata?.title;
// Display only valid responses in the drop down
// Display only valid responses in the drop down if showAllResponses is false,
// otherwise all response are visible and the first layer in toc is present in here
const valid = !!validator(format)?.getValidResponses([opt]).length;
return {label: value, value, idx, style: {display: valid ? 'block' : 'none'}};
return {
label: value,
value,
idx,
style: {
display: showAllResponses ? 'block' : (valid ? 'block' : 'none')
}};
}));
}
}, [responses]);
Expand Down
4 changes: 3 additions & 1 deletion web/client/components/data/identify/enhancers/identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const identifyLifecycle = compose(
enabled,
showInMapPopup,
maxItems,
showAllResponses,
changeMousePointer = () => {},
disableCenterToMarker,
enableInfoForSelectedLayers = true,
Expand All @@ -85,7 +86,8 @@ export const identifyLifecycle = compose(
enableInfoForSelectedLayers,
configuration: {
maxItems
}
},
showAllResponses
});

if (enabled || showInMapPopup) {
Expand Down
5 changes: 3 additions & 2 deletions web/client/plugins/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ const identifyDefaultProps = defaultProps({
});

/**
* This plugin allows get informations about clicked point. It can be configured to have a mobile or a desktop flavor.
* 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
* ```
* "mapInfo": {
* "enabled": true, // enabled by default
* "disabledAlwaysOn": false, // if true, disable always on setup
* "configuration": {
* "showEmptyMessageGFI": false // allow or deny the visiibility of message when you have no results from identify request
* "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
* }
* }
Expand All @@ -199,6 +199,7 @@ const identifyDefaultProps = defaultProps({
* @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
* @prop cfg.showAllResponses {bool} if true it will include invalid/empty responses and it will always select the first request/layer
* @prop cfg.zIndex {number} component z index order
* @prop cfg.showInMapPopup {boolean} if true show the identify as popup
* @prop cfg.maxItems {number} the number of features returned by this tool
Expand Down
76 changes: 70 additions & 6 deletions web/client/reducers/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
*/

import expect from 'expect';
import assign from 'object-assign';
import 'babel-polyfill';

import mapInfo from '../mapInfo';

import {
featureInfoClick,
toggleEmptyMessageGFI,
Expand All @@ -22,19 +23,20 @@ import {
onInitPlugin
} from '../../actions/mapInfo';
import {changeVisualizationMode} from '../../actions/maptype';

import { MAP_CONFIG_LOADED } from '../../actions/config';
import { VisualizationModes } from '../../utils/MapTypeUtils';
import assign from 'object-assign';
import 'babel-polyfill';

describe('Test the mapInfo reducer', () => {
const appState = {
configuration: {
infoFormat: 'text/plain'
},
responses: [],
requests: [{reqId: 10, request: "test"}, {reqId: 11, request: "test1"}]};
requests: [
{reqId: 10, request: "test"},
{reqId: 11, request: "test1"},
{reqId: 3, request: "test3"}
]};

it('returns original state on unrecognized action', () => {
let state = mapInfo(1, {type: 'UNKNOWN'});
Expand Down Expand Up @@ -123,6 +125,59 @@ describe('Test the mapInfo reducer', () => {
expect(state.responses[1].layerMetadata).toBe("meta");
expect(state.index).toBe(1);
});
it('creates a feature info data from successful request, with showAllResponses true', () => {
let testAction = {
type: 'LOAD_FEATURE_INFO',
data: "data",
requestParams: "params",
layerMetadata: "meta",
reqId: 11
};

let state = mapInfo({
configuration: {
infoFormat: 'text/plain'
},
responses: [],
requests: [
{reqId: 10, request: "test"},
{reqId: 11, request: "test1"},
{reqId: 3, request: "test3"}
],
showAllResponses: true
}, testAction);
expect(state.responses).toExist();
expect(state.responses.length).toBe(2);
expect(state.loaded).toBe(true);
expect(state.responses[1].response).toBe("data");
expect(state.responses[1].queryParams).toBe("params");
expect(state.responses[1].layerMetadata).toBe("meta");
expect(state.index).toBe(0);

state = mapInfo({
configuration: {
infoFormat: 'text/plain'
},
responses: [{response: "test"}, {response: "test1"}],
requests: [
{reqId: 10, request: "test"},
{reqId: 11, request: "test1"},
{reqId: 3, request: "test3"}
],
showAllResponses: true
}, {...testAction, reqId: 3, layerMetadata: "meta3"});
expect(state.responses).toExist();
expect(state.responses.length).toBe(3);
expect(state.responses[0].response).toBe("test");
expect(state.responses[0]).toBeTruthy();
expect(state.responses[1].response).toBe("test1");
expect(state.responses[1]).toBeTruthy();
expect(state.responses[2]).toBeTruthy();
expect(state.responses[2].queryParams).toBe("params");
expect(state.responses[2].layerMetadata).toBe("meta3");
expect(state.loaded).toBe(true);
expect(state.index).toBe(0);
});
it('creates a feature info data from successful request on showInMapPopup', () => {
let testAction = {
type: 'LOAD_FEATURE_INFO',
Expand Down Expand Up @@ -176,6 +231,15 @@ describe('Test the mapInfo reducer', () => {
expect(state.responses[1].response).toBe("");
expect(state.responses[1].queryParams).toBe("params");
expect(state.responses[1].layerMetadata).toBe("meta");

state = mapInfo(assign({}, appState, {responses: [{response: "test"}, {response: "test"}]}), {...testAction, layerMetadata: "meta3", reqId: 3});
expect(state.responses).toExist();
expect(state.responses.length).toBe(3);
expect(state.responses[0]).toBeTruthy();
expect(state.responses[0].response).toBe("test");
expect(state.responses[1].response).toBe("test");
expect(state.responses[2].queryParams).toBe("params");
expect(state.responses[2].layerMetadata).toBe("meta3");
expect(state.index).toBe(undefined);
expect(state.loaded).toBe(true);
});
Expand Down Expand Up @@ -241,7 +305,7 @@ describe('Test the mapInfo reducer', () => {

state = mapInfo( appState, {type: 'NEW_MAPINFO_REQUEST', reqId: 1, request: "request"});
expect(state.requests).toExist();
expect(state.requests.length).toBe(3);
expect(state.requests.length).toBe(4);
expect(state.requests.filter((req) => req.reqId === 10)[0].request).toBe("test");
expect(state.requests.filter((req) => req.reqId === 1)[0].request).toBe("request");
});
Expand Down
10 changes: 4 additions & 6 deletions web/client/reducers/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import assign from 'object-assign';
import { findIndex, isUndefined, isEmpty } from 'lodash';
import buffer from 'turf-buffer';
import intersect from 'turf-intersect';
import { findIndex, isUndefined, isEmpty } from 'lodash';

import { MAP_CONFIG_LOADED } from '../actions/config';
import { RESET_CONTROLS } from '../actions/controls';
import {
ERROR_FEATURE_INFO,
EXCEPTIONS_FEATURE_INFO,
Expand Down Expand Up @@ -39,9 +40,6 @@ import {
SET_SHOW_IN_MAP_POPUP,
INIT_PLUGIN
} from '../actions/mapInfo';

import { MAP_CONFIG_LOADED } from '../actions/config';
import { RESET_CONTROLS } from '../actions/controls';
import { VISUALIZATION_MODE_CHANGED } from '../actions/maptype';

import { getValidator } from '../utils/MapInfoUtils';
Expand Down Expand Up @@ -111,7 +109,7 @@ function receiveResponse(state, action, type) {
}

let indexObj;
if (isHover) {
if (isHover || state.showAllResponses) {
indexObj = {loaded: true, index: 0};
} else if (!isHover && isIndexValid(state, responses, requestIndex, isVector)) {
indexObj = {loaded: true, index: requestIndex};
Expand Down

0 comments on commit 0e5a381

Please sign in to comment.