Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10626 adding possibilities for better updating store #10627

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
updateAllLayers,
UPDATE_ALL_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('updateAllLayers', () => {
const layers = [{}];
const action = updateAllLayers(layers);
expect(action).toExist();
expect(action.type).toBe(UPDATE_ALL_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 UPDATE_ALL_LAYERS = 'LAYERS:UPDATE_ALL_LAYERS';

/**
* full replacement of layers in layers state
* @param {object[]} layers the new layers to replace in the state
* @returns
*/
export function updateAllLayers(layers) {
return {
type: UPDATE_ALL_LAYERS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based also on the jsdoc this operation represent a replacement so I would call this REPLACE_LAYERS/replaceLayers

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,
UPDATE_ALL_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 UPDATE_ALL_LAYERS: {
return {
...state,
layers: action.layers
};
}
case UPDATE_NODE: {
const updatedNode = changeNodeConfiguration({
layers: state.flat,
Expand Down
Loading