diff --git a/web/client/epics/widgetsbuilder.js b/web/client/epics/widgetsbuilder.js index 2999a488e3..a2aae98e25 100644 --- a/web/client/epics/widgetsbuilder.js +++ b/web/client/epics/widgetsbuilder.js @@ -60,7 +60,7 @@ module.exports = { ...w, // override action's type type: undefined - }, {step: 0}))), + }, {step: 0}), onEditorChange("returnToFeatureGrid", true))), /** * Manages interaction with QueryPanel and widgetBuilder */ diff --git a/web/client/plugins/widgetbuilder/enhancers/withMapExitButton.js b/web/client/plugins/widgetbuilder/enhancers/withMapExitButton.js index dcf3949630..deab6e6076 100644 --- a/web/client/plugins/widgetbuilder/enhancers/withMapExitButton.js +++ b/web/client/plugins/widgetbuilder/enhancers/withMapExitButton.js @@ -5,16 +5,42 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -const { compose, withProps } = require('recompose'); +const { compose, withProps, withHandlers} = require('recompose'); const { connect } = require('react-redux'); +const {setControlProperty} = require('../../../actions/controls'); +const {openFeatureGrid} = require('../../../actions/featuregrid'); const { onEditorChange } = require('../../../actions/widgets'); +const {returnToFeatureGridSelector} = require('../../../selectors/widgets'); /** * Reset widgets */ module.exports = compose( - connect(() => ({}), { - backFromWizard: () => onEditorChange('widgetType', undefined) + connect(() => ({ + returnToFeatureGrid: state => returnToFeatureGridSelector(state)}), + { + backToWidgetList: () => onEditorChange('widgetType', undefined), + closeWidgetBuilder: () => setControlProperty("widgetBuilder", "enabled", false, false), + openFeatureGridTable: () => openFeatureGrid() + }), + /** + * it allows to return to the feature grid if the chart wizard has been opened from there. + * otherwise it goes back to the widget list + */ + withHandlers({ + backFromWizard: ({ + backToWidgetList = () => {}, + closeWidgetBuilder = () => {}, + openFeatureGridTable = () => {}, + returnToFeatureGrid + }) => () => { + if (returnToFeatureGrid) { + closeWidgetBuilder(); + openFeatureGridTable(); + } else { + backToWidgetList(); + } + } }), withProps(({ backFromWizard = () => {} }) => ({ exitButton: { diff --git a/web/client/selectors/__tests__/controls-test.js b/web/client/selectors/__tests__/controls-test.js index 2e7d02ab28..41c86054ff 100644 --- a/web/client/selectors/__tests__/controls-test.js +++ b/web/client/selectors/__tests__/controls-test.js @@ -9,7 +9,10 @@ const expect = require('expect'); const { queryPanelSelector, - wfsDownloadAvailable + wfsDownloadAvailable, + wfsDownloadSelector, + widgetBuilderAvailable, + widgetBuilderSelector } = require("../controls"); const state = { @@ -18,7 +21,15 @@ const state = { enabled: true }, wfsdownload: { - available: true + available: true, + enabled: true + }, + widgetBuilder: { + available: true, + enabled: true + }, + featuregrid: { + enabled: true } } }; @@ -34,5 +45,19 @@ describe('Test controls selectors', () => { expect(retVal).toExist(); expect(retVal).toBe(true); }); - + it('test wfsDownloadSelector', () => { + const retVal = wfsDownloadSelector(state); + expect(retVal).toExist(); + expect(retVal).toBe(true); + }); + it('test widgetBuilderAvailable', () => { + const retVal = widgetBuilderAvailable(state); + expect(retVal).toExist(); + expect(retVal).toBe(true); + }); + it('test widgetBuilderSelector', () => { + const retVal = widgetBuilderSelector(state); + expect(retVal).toExist(); + expect(retVal).toBe(true); + }); }); diff --git a/web/client/selectors/__tests__/widgets-test.js b/web/client/selectors/__tests__/widgets-test.js index 724a2bcab6..91cc57a6a8 100644 --- a/web/client/selectors/__tests__/widgets-test.js +++ b/web/client/selectors/__tests__/widgets-test.js @@ -18,7 +18,8 @@ const { getEditorSettings, getWidgetLayer, dependenciesSelector, - availableDependenciesSelector + availableDependenciesSelector, + returnToFeatureGridSelector } = require('../widgets'); const {set} = require('../../utils/ImmutableUtils'); describe('widgets selectors', () => { @@ -65,6 +66,11 @@ describe('widgets selectors', () => { expect(getEditorSettings(state)).toExist(); expect(getEditorSettings(state).flag).toBe(true); }); + it('returnToFeatureGridSelector', () => { + const state = set(`widgets.builder.editor`, { returnToFeatureGrid: true }, {}); + expect(returnToFeatureGridSelector(state)).toExist(); + expect(returnToFeatureGridSelector(state)).toBe(true); + }); it('getWidgetLayer', () => { const tocLayerState = {'layers': { selected: ["TEST1"], flat: [{id: "TEST1", name: "TEST1"}] }}; expect(getWidgetLayer(tocLayerState)).toExist(); diff --git a/web/client/selectors/widgets.js b/web/client/selectors/widgets.js index 08591124d3..6764638b24 100644 --- a/web/client/selectors/widgets.js +++ b/web/client/selectors/widgets.js @@ -67,6 +67,7 @@ module.exports = { getDashboardWidgetsLayout: state => get(state, `widgets.containers[${DEFAULT_TARGET}].layouts`), getEditingWidget, getEditingWidgetLayer: state => get(getEditingWidget(state), "layer"), + returnToFeatureGridSelector: (state) => get(state, "widgets.builder.editor.returnToFeatureGrid", false), getEditingWidgetFilter: state => get(getEditingWidget(state), "filter"), getEditorSettings, getWidgetLayer,