Skip to content

Commit

Permalink
geosolutions-it#10242: Fix - Viewer widgets state not aligned (geosol…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuren1 authored Apr 29, 2024
1 parent 422a7b6 commit ffa0351
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 6 deletions.
90 changes: 89 additions & 1 deletion web/client/epics/__tests__/widgets-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions web/client/epics/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit ffa0351

Please sign in to comment.