Skip to content

Commit

Permalink
geosolutions-it#8588: Fix - Effective handle of widget conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuren1 committed Oct 21, 2022
1 parent d5ad101 commit cba6e82
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion web/client/reducers/__tests__/widgets-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,18 @@ describe('Test the widgets reducer', () => {
const state = widgets(undefined, configureMap({widgetsConfig: {widgets: [{id: "1"}]}}));
expect(state.containers[DEFAULT_TARGET].widgets.length).toBe(1);
});
it('configureMap with no widget', () => {
it('configureMap with no widgetsConfig', () => {
const state = widgets(undefined, configureMap({}));
expect(state.containers[DEFAULT_TARGET].widgets).toBeFalsy();
});
it('configureMap with empty object widgetsConfig', () => {
const state = widgets(undefined, configureMap({widgetsConfig: {}}));
expect(state.containers[DEFAULT_TARGET].widgets).toBeFalsy({});
});
it('configureMap with empty widgets in widgetsConfig', () => {
const state = widgets(undefined, configureMap({widgetsConfig: { widgets: []}}));
expect(state.containers[DEFAULT_TARGET].widgets).toEqual([]);
});
it('changeLayout', () => {
const L = {lg: []};
const AL = {md: []};
Expand Down
4 changes: 2 additions & 2 deletions web/client/reducers/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { MAP_CONFIG_LOADED } from '../actions/config';
import { DASHBOARD_LOADED, DASHBOARD_RESET } from '../actions/dashboard';
import assign from 'object-assign';
import set from 'lodash/fp/set';
import { get, find, omit, mapValues, castArray } from 'lodash';
import { get, find, omit, mapValues, castArray, isEmpty } from 'lodash';
import { arrayUpsert, compose, arrayDelete } from '../utils/ImmutableUtils';
import {
convertDependenciesMappingForCompatibility as convertToCompatibleWidgets,
Expand Down Expand Up @@ -170,7 +170,7 @@ function widgetsReducer(state = emptyState, action) {
}, state);
case MAP_CONFIG_LOADED:
let { widgetsConfig } = (action.config || {});
if (widgetsConfig) {
if (!isEmpty(widgetsConfig)) {
widgetsConfig = convertToCompatibleWidgets(widgetsConfig);
}
return set(`containers[${DEFAULT_TARGET}]`, {
Expand Down
2 changes: 1 addition & 1 deletion web/client/utils/WidgetsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const CHART_PROPS = ["selectedChartId", "id", "mapSync", "widgetType", "c
export const convertDependenciesMappingForCompatibility = (data) => {
const mapDependencies = ["layers", "viewport", "zoom", "center"];
const _data = cloneDeep(data);
const widgets = _data.widgets || {};
const widgets = _data?.widgets || [];
const tempWidgetMapDependency = [];
return {
..._data,
Expand Down

0 comments on commit cba6e82

Please sign in to comment.