Skip to content

Commit

Permalink
Fix #10626 adding possibilities for better updating store (#10627)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 authored Oct 25, 2024
1 parent 3794608 commit 8e2d443
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
12 changes: 11 additions & 1 deletion web/client/actions/__tests__/catalog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ import {
SET_FORMAT_OPTIONS,
setSupportedFormats, addLayerAndDescribe, ADD_LAYER_AND_DESCRIBE,
INIT_PLUGIN,
initPlugin
initPlugin,
updateCatalogServices,
UPDATE_CATALOG_SERVICES
} from '../catalog';

import { SHOW_NOTIFICATION } from '../notifications';
Expand Down Expand Up @@ -254,6 +256,14 @@ describe('Test correctness of the catalog actions', () => {
expect(retval.type).toBe(ADD_CATALOG_SERVICE);
expect(retval.service).toBe(service);
});
it('updateCatalogServices', () => {
const services = [{}];
var retval = updateCatalogServices(services);

expect(retval).toExist();
expect(retval.type).toBe(UPDATE_CATALOG_SERVICES);
expect(retval.services).toEqual(services);
});
it('resetCatalog', () => {
var retval = resetCatalog();
expect(retval).toExist();
Expand Down
10 changes: 10 additions & 0 deletions web/client/actions/__tests__/layers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
ADD_LAYER,
REMOVE_LAYER,
SHOW_SETTINGS,
replaceLayers,
REPLACE_LAYERS,
HIDE_SETTINGS,
UPDATE_SETTINGS,
REFRESH_LAYERS,
Expand Down Expand Up @@ -240,6 +242,14 @@ describe('Test correctness of the layers actions', () => {
expect(action.options).toEqual({opacity: 0.5});
});

it('replaceLayers', () => {
const layers = [{}];
const action = replaceLayers(layers);
expect(action).toExist();
expect(action.type).toBe(REPLACE_LAYERS);
expect(action.layers).toEqual(layers);
});

it('hide settings', () => {
const action = hideSettings();
expect(action).toExist();
Expand Down
12 changes: 12 additions & 0 deletions web/client/actions/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const CHANGE_SERVICE_FORMAT = 'CATALOG:CHANGE_SERVICE_FORMAT';
export const FOCUS_SERVICES_LIST = 'CATALOG:FOCUS_SERVICES_LIST';
export const CHANGE_URL = 'CATALOG:CHANGE_URL';
export const ADD_CATALOG_SERVICE = 'CATALOG:ADD_CATALOG_SERVICE';
export const UPDATE_CATALOG_SERVICES = 'CATALOG:UPDATE_CATALOG_SERVICES';
export const DELETE_CATALOG_SERVICE = 'CATALOG:DELETE_CATALOG_SERVICE';
export const ADD_SERVICE = 'CATALOG:ADD_SERVICE';
export const DELETE_SERVICE = 'CATALOG:DELETE_SERVICE';
Expand Down Expand Up @@ -184,6 +185,17 @@ export function addCatalogService(service) {
service
};
}
/**
*
* @param {object[]} services list of services to full replace catalog ones
* @returns
*/
export function updateCatalogServices(services) {
return {
type: UPDATE_CATALOG_SERVICES,
services
};
}
export function deleteCatalogService(service) {
return {
type: DELETE_CATALOG_SERVICE,
Expand Down
12 changes: 12 additions & 0 deletions web/client/actions/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ export const FILTER_LAYERS = 'LAYERS:FILTER_LAYERS';
export const SHOW_LAYER_METADATA = 'LAYERS:SHOW_LAYER_METADATA';
export const HIDE_LAYER_METADATA = 'LAYERS:HIDE_LAYER_METADATA';
export const UPDATE_SETTINGS_PARAMS = 'LAYERS:UPDATE_SETTINGS_PARAMS';
export const REPLACE_LAYERS = 'LAYERS:REPLACE_LAYERS';

/**
* full replacement of layers in layers state
* @param {object[]} layers the new layers to replace in the state
* @returns
*/
export function replaceLayers(layers) {
return {
type: REPLACE_LAYERS,
layers
};
}
export function showSettings(node, nodeType, options) {
return {
type: SHOW_SETTINGS,
Expand Down
6 changes: 6 additions & 0 deletions web/client/reducers/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
CHANGE_SERVICE_FORMAT,
FOCUS_SERVICES_LIST,
ADD_CATALOG_SERVICE,
UPDATE_CATALOG_SERVICES,
DELETE_CATALOG_SERVICE,
SAVING_SERVICE,
CHANGE_METADATA_TEMPLATE,
Expand Down Expand Up @@ -171,6 +172,11 @@ function catalog(state = {
layerError: null
});
}
case UPDATE_CATALOG_SERVICES: {
return {...state,
services: action.services
};
}
case CHANGE_SELECTED_SERVICE: {
if (action.service !== state.selectedService) {
return assign({}, state, {
Expand Down
9 changes: 8 additions & 1 deletion web/client/reducers/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
SELECT_NODE,
FILTER_LAYERS,
SHOW_LAYER_METADATA,
HIDE_LAYER_METADATA
HIDE_LAYER_METADATA,
REPLACE_LAYERS
} from '../actions/layers';

import { TOGGLE_CONTROL } from '../actions/controls';
Expand Down Expand Up @@ -174,6 +175,12 @@ function layers(state = { flat: [] }, action) {
}
return state;
}
case REPLACE_LAYERS: {
return {
...state,
layers: action.layers
};
}
case UPDATE_NODE: {
const updatedNode = changeNodeConfiguration({
layers: state.flat,
Expand Down

0 comments on commit 8e2d443

Please sign in to comment.