Skip to content

Commit

Permalink
fix #2807 back interaction from widget to feature grid (#2821)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 authored and offtherailz committed Apr 20, 2018
1 parent a923763 commit 593692f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion web/client/epics/widgetsbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
32 changes: 29 additions & 3 deletions web/client/plugins/widgetbuilder/enhancers/withMapExitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
31 changes: 28 additions & 3 deletions web/client/selectors/__tests__/controls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
const expect = require('expect');
const {
queryPanelSelector,
wfsDownloadAvailable
wfsDownloadAvailable,
wfsDownloadSelector,
widgetBuilderAvailable,
widgetBuilderSelector
} = require("../controls");

const state = {
Expand All @@ -18,7 +21,15 @@ const state = {
enabled: true
},
wfsdownload: {
available: true
available: true,
enabled: true
},
widgetBuilder: {
available: true,
enabled: true
},
featuregrid: {
enabled: true
}
}
};
Expand All @@ -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);
});
});
8 changes: 7 additions & 1 deletion web/client/selectors/__tests__/widgets-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const {
getEditorSettings,
getWidgetLayer,
dependenciesSelector,
availableDependenciesSelector
availableDependenciesSelector,
returnToFeatureGridSelector
} = require('../widgets');
const {set} = require('../../utils/ImmutableUtils');
describe('widgets selectors', () => {
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions web/client/selectors/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 593692f

Please sign in to comment.