diff --git a/web/client/epics/__tests__/widgets-test.js b/web/client/epics/__tests__/widgets-test.js index a676e303d5..045cc7358c 100644 --- a/web/client/epics/__tests__/widgets-test.js +++ b/web/client/epics/__tests__/widgets-test.js @@ -36,7 +36,7 @@ import { import { savingMap, mapCreated } from '../../actions/maps'; import { configureMap } from '../../actions/config'; -import { changeLayerProperties, layerLoad, layerError } from '../../actions/layers'; +import { changeLayerProperties, layerLoad, layerError, updateNode } from '../../actions/layers'; import { onLocationChanged } from 'connected-react-router'; import { ActionsObservable } from 'redux-observable'; import Rx from 'rxjs'; @@ -438,6 +438,94 @@ describe('widgets Epics', () => { .toArray() .subscribe(checkActions); }); + it('updateNode triggers updateWidgetLayer on filterLayer change', (done) => { + const checkActions = actions => { + expect(actions.length).toBe(1); + expect(actions[0].type).toBe(UPDATE_LAYER); + expect(actions[0].layer).toEqual({ + id: "1", + name: "layer" + }); + done(); + }; + testEpic(updateLayerOnLayerPropertiesChange, + 1, + [updateNode( + "1", + "layers", + {layerFilter: {rowId: 1567705038414}} + )], + checkActions, + { + layers: { + flat: [{ + id: "1", + name: "layer" + }, { + id: "2", + name: "layer2", + filterLayer: {rowId: 1567705038414} + }, { + id: "3", + name: "layer3" + }] + } + }); + }); + it('updateNode does not trigger updateWidgetLayer layer property change', (done) => { + const checkActions = actions => { + expect(actions.length).toBe(1); + expect(actions[0].type).toBe(TEST_TIMEOUT); + done(); + }; + testEpic(addTimeoutEpic(updateLayerOnLayerPropertiesChange, 0), + 1, + [updateNode( + "1", + "layers", + {filter: {rowId: 1567705038414}} + )], + checkActions, + { + layers: { + flat: [{ + id: "1", + name: "layer" + }, { + id: "2", + name: "layer2", + filterLayer: {rowId: 1567705038414} + }] + } + }); + }); + it('updateNode does not trigger updateWidgetLayer group property change', (done) => { + const checkActions = actions => { + expect(actions.length).toBe(1); + expect(actions[0].type).toBe(TEST_TIMEOUT); + done(); + }; + testEpic(addTimeoutEpic(updateLayerOnLayerPropertiesChange, 0), + 1, + [updateNode( + "1", + "groups", + {test: "some"} + )], + checkActions, + { + layers: { + flat: [{ + id: "1", + name: "layer" + }, { + id: "2", + name: "layer2", + filterLayer: {rowId: 1567705038414} + }] + } + }); + }); it('updateLayerOnLoadingErrorChange triggers updateWidgetLayer on LAYER_LOAD error', (done) => { const checkActions = actions => { expect(actions.length).toBe(1); diff --git a/web/client/epics/widgets.js b/web/client/epics/widgets.js index 6674556b54..d08053aa6a 100644 --- a/web/client/epics/widgets.js +++ b/web/client/epics/widgets.js @@ -43,7 +43,7 @@ import { getFloatingWidgets, getWidgetLayer } from '../selectors/widgets'; -import { CHANGE_LAYER_PROPERTIES, LAYER_LOAD, LAYER_ERROR } from '../actions/layers'; +import { CHANGE_LAYER_PROPERTIES, LAYER_LOAD, LAYER_ERROR, UPDATE_NODE } from '../actions/layers'; import { getLayerFromId } from '../selectors/layers'; import { pathnameSelector } from '../selectors/router'; @@ -261,11 +261,14 @@ export const exportWidgetImage = action$ => * @return {external:Observable} */ export const updateLayerOnLayerPropertiesChange = (action$, store) => - action$.ofType(CHANGE_LAYER_PROPERTIES) - .switchMap(({layer, newProperties}) => { + action$.ofType(CHANGE_LAYER_PROPERTIES, UPDATE_NODE) + .filter(({layer, newProperties, nodeType, options}) => { + return (layer && newProperties) || (nodeType === "layers" && has(options, "layerFilter")); + }) + .switchMap(({layer, newProperties, node, options}) => { const state = store.getState(); - const flatLayer = getLayerFromId(state, layer); - const shouldUpdate = flatLayer && (has(newProperties, "layerFilter") || has(newProperties, "fields")); + const flatLayer = getLayerFromId(state, layer ?? node); + const shouldUpdate = flatLayer && (has(newProperties ?? options, "layerFilter") || has(newProperties, "fields")); if (shouldUpdate) { return Rx.Observable.of(updateWidgetLayer(flatLayer)); }