From 8e2d4433427ce5b7cf7628c8d51f724f29d2bf18 Mon Sep 17 00:00:00 2001 From: "Matteo V." Date: Fri, 25 Oct 2024 09:30:51 +0200 Subject: [PATCH] Fix #10626 adding possibilities for better updating store (#10627) --- web/client/actions/__tests__/catalog-test.js | 12 +++++++++++- web/client/actions/__tests__/layers-test.js | 10 ++++++++++ web/client/actions/catalog.js | 12 ++++++++++++ web/client/actions/layers.js | 12 ++++++++++++ web/client/reducers/catalog.js | 6 ++++++ web/client/reducers/layers.js | 9 ++++++++- 6 files changed, 59 insertions(+), 2 deletions(-) diff --git a/web/client/actions/__tests__/catalog-test.js b/web/client/actions/__tests__/catalog-test.js index 029e2aa4bc..95623410da 100644 --- a/web/client/actions/__tests__/catalog-test.js +++ b/web/client/actions/__tests__/catalog-test.js @@ -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'; @@ -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(); diff --git a/web/client/actions/__tests__/layers-test.js b/web/client/actions/__tests__/layers-test.js index f4648abb32..47bba2ac0c 100644 --- a/web/client/actions/__tests__/layers-test.js +++ b/web/client/actions/__tests__/layers-test.js @@ -20,6 +20,8 @@ import { ADD_LAYER, REMOVE_LAYER, SHOW_SETTINGS, + replaceLayers, + REPLACE_LAYERS, HIDE_SETTINGS, UPDATE_SETTINGS, REFRESH_LAYERS, @@ -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(); diff --git a/web/client/actions/catalog.js b/web/client/actions/catalog.js index fb5c5e26bb..3994422e1e 100644 --- a/web/client/actions/catalog.js +++ b/web/client/actions/catalog.js @@ -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'; @@ -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, diff --git a/web/client/actions/layers.js b/web/client/actions/layers.js index 0d56ab5ca8..ac1b2764c0 100644 --- a/web/client/actions/layers.js +++ b/web/client/actions/layers.js @@ -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, diff --git a/web/client/reducers/catalog.js b/web/client/reducers/catalog.js index 6b358854ab..4803c3a433 100644 --- a/web/client/reducers/catalog.js +++ b/web/client/reducers/catalog.js @@ -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, @@ -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, { diff --git a/web/client/reducers/layers.js b/web/client/reducers/layers.js index e841ba7d13..459c00bc32 100644 --- a/web/client/reducers/layers.js +++ b/web/client/reducers/layers.js @@ -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'; @@ -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,