Skip to content

Commit 8e2d443

Browse files
authored
Fix geosolutions-it#10626 adding possibilities for better updating store (geosolutions-it#10627)
1 parent 3794608 commit 8e2d443

File tree

6 files changed

+59
-2
lines changed

6 files changed

+59
-2
lines changed

web/client/actions/__tests__/catalog-test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ import {
7272
SET_FORMAT_OPTIONS,
7373
setSupportedFormats, addLayerAndDescribe, ADD_LAYER_AND_DESCRIBE,
7474
INIT_PLUGIN,
75-
initPlugin
75+
initPlugin,
76+
updateCatalogServices,
77+
UPDATE_CATALOG_SERVICES
7678
} from '../catalog';
7779

7880
import { SHOW_NOTIFICATION } from '../notifications';
@@ -254,6 +256,14 @@ describe('Test correctness of the catalog actions', () => {
254256
expect(retval.type).toBe(ADD_CATALOG_SERVICE);
255257
expect(retval.service).toBe(service);
256258
});
259+
it('updateCatalogServices', () => {
260+
const services = [{}];
261+
var retval = updateCatalogServices(services);
262+
263+
expect(retval).toExist();
264+
expect(retval.type).toBe(UPDATE_CATALOG_SERVICES);
265+
expect(retval.services).toEqual(services);
266+
});
257267
it('resetCatalog', () => {
258268
var retval = resetCatalog();
259269
expect(retval).toExist();

web/client/actions/__tests__/layers-test.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
ADD_LAYER,
2121
REMOVE_LAYER,
2222
SHOW_SETTINGS,
23+
replaceLayers,
24+
REPLACE_LAYERS,
2325
HIDE_SETTINGS,
2426
UPDATE_SETTINGS,
2527
REFRESH_LAYERS,
@@ -240,6 +242,14 @@ describe('Test correctness of the layers actions', () => {
240242
expect(action.options).toEqual({opacity: 0.5});
241243
});
242244

245+
it('replaceLayers', () => {
246+
const layers = [{}];
247+
const action = replaceLayers(layers);
248+
expect(action).toExist();
249+
expect(action.type).toBe(REPLACE_LAYERS);
250+
expect(action.layers).toEqual(layers);
251+
});
252+
243253
it('hide settings', () => {
244254
const action = hideSettings();
245255
expect(action).toExist();

web/client/actions/catalog.js

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const CHANGE_SERVICE_FORMAT = 'CATALOG:CHANGE_SERVICE_FORMAT';
3838
export const FOCUS_SERVICES_LIST = 'CATALOG:FOCUS_SERVICES_LIST';
3939
export const CHANGE_URL = 'CATALOG:CHANGE_URL';
4040
export const ADD_CATALOG_SERVICE = 'CATALOG:ADD_CATALOG_SERVICE';
41+
export const UPDATE_CATALOG_SERVICES = 'CATALOG:UPDATE_CATALOG_SERVICES';
4142
export const DELETE_CATALOG_SERVICE = 'CATALOG:DELETE_CATALOG_SERVICE';
4243
export const ADD_SERVICE = 'CATALOG:ADD_SERVICE';
4344
export const DELETE_SERVICE = 'CATALOG:DELETE_SERVICE';
@@ -184,6 +185,17 @@ export function addCatalogService(service) {
184185
service
185186
};
186187
}
188+
/**
189+
*
190+
* @param {object[]} services list of services to full replace catalog ones
191+
* @returns
192+
*/
193+
export function updateCatalogServices(services) {
194+
return {
195+
type: UPDATE_CATALOG_SERVICES,
196+
services
197+
};
198+
}
187199
export function deleteCatalogService(service) {
188200
return {
189201
type: DELETE_CATALOG_SERVICE,

web/client/actions/layers.js

+12
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,19 @@ export const FILTER_LAYERS = 'LAYERS:FILTER_LAYERS';
3636
export const SHOW_LAYER_METADATA = 'LAYERS:SHOW_LAYER_METADATA';
3737
export const HIDE_LAYER_METADATA = 'LAYERS:HIDE_LAYER_METADATA';
3838
export const UPDATE_SETTINGS_PARAMS = 'LAYERS:UPDATE_SETTINGS_PARAMS';
39+
export const REPLACE_LAYERS = 'LAYERS:REPLACE_LAYERS';
3940

41+
/**
42+
* full replacement of layers in layers state
43+
* @param {object[]} layers the new layers to replace in the state
44+
* @returns
45+
*/
46+
export function replaceLayers(layers) {
47+
return {
48+
type: REPLACE_LAYERS,
49+
layers
50+
};
51+
}
4052
export function showSettings(node, nodeType, options) {
4153
return {
4254
type: SHOW_SETTINGS,

web/client/reducers/catalog.js

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
CHANGE_SERVICE_FORMAT,
2323
FOCUS_SERVICES_LIST,
2424
ADD_CATALOG_SERVICE,
25+
UPDATE_CATALOG_SERVICES,
2526
DELETE_CATALOG_SERVICE,
2627
SAVING_SERVICE,
2728
CHANGE_METADATA_TEMPLATE,
@@ -171,6 +172,11 @@ function catalog(state = {
171172
layerError: null
172173
});
173174
}
175+
case UPDATE_CATALOG_SERVICES: {
176+
return {...state,
177+
services: action.services
178+
};
179+
}
174180
case CHANGE_SELECTED_SERVICE: {
175181
if (action.service !== state.selectedService) {
176182
return assign({}, state, {

web/client/reducers/layers.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import {
3131
SELECT_NODE,
3232
FILTER_LAYERS,
3333
SHOW_LAYER_METADATA,
34-
HIDE_LAYER_METADATA
34+
HIDE_LAYER_METADATA,
35+
REPLACE_LAYERS
3536
} from '../actions/layers';
3637

3738
import { TOGGLE_CONTROL } from '../actions/controls';
@@ -174,6 +175,12 @@ function layers(state = { flat: [] }, action) {
174175
}
175176
return state;
176177
}
178+
case REPLACE_LAYERS: {
179+
return {
180+
...state,
181+
layers: action.layers
182+
};
183+
}
177184
case UPDATE_NODE: {
178185
const updatedNode = changeNodeConfiguration({
179186
layers: state.flat,

0 commit comments

Comments
 (0)