From a8f901e2c77c391058d852dfc938452c22cf0e4d Mon Sep 17 00:00:00 2001 From: DavidQuartz Date: Fri, 1 Jul 2022 15:59:14 +0000 Subject: [PATCH] Updating catalogu after save --- .../client/js/actions/gnresource.js | 12 ++++++++++++ .../client/js/epics/__tests__/gnresource-test.js | 5 +++-- .../client/js/epics/gnresource.js | 5 +++-- .../client/js/epics/gnsave.js | 9 ++++++--- .../client/js/reducers/gnsearch.js | 16 ++++++++++++++++ geonode_mapstore_client/client/package.json | 2 +- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/geonode_mapstore_client/client/js/actions/gnresource.js b/geonode_mapstore_client/client/js/actions/gnresource.js index b81e351d72..0fa34353c2 100644 --- a/geonode_mapstore_client/client/js/actions/gnresource.js +++ b/geonode_mapstore_client/client/js/actions/gnresource.js @@ -33,6 +33,7 @@ export const SET_RESOURCE_THUMBNAIL = 'GEONODE_SET_RESOURCE_THUMBNAIL'; export const ENABLE_MAP_THUMBNAIL_VIEWER = 'GEONODE_ENABLE_MAP_THUMBNAIL_VIEWER'; export const DOWNLOAD_RESOURCE = 'GEONODE_DOWNLOAD_RESOURCE'; export const DOWNLOAD_COMPLETE = 'GEONODE_DOWNLOAD_COMPLETE'; +export const UPDATE_SINGLE_RESOURCE = 'GEONODE_UPDATE_SINGLE_RESOURCE'; /** @@ -61,6 +62,17 @@ export function setResource(data) { }; } +/** +* Set the resource in the state +* @param {object} data resource data object +*/ +export function updateResource(resource) { + return { + type: UPDATE_SINGLE_RESOURCE, + data: resource + }; +} + /** * edit the title resource in the state * @param {string} title resource diff --git a/geonode_mapstore_client/client/js/epics/__tests__/gnresource-test.js b/geonode_mapstore_client/client/js/epics/__tests__/gnresource-test.js index 79cbc4b46b..b905faba4f 100644 --- a/geonode_mapstore_client/client/js/epics/__tests__/gnresource-test.js +++ b/geonode_mapstore_client/client/js/epics/__tests__/gnresource-test.js @@ -11,7 +11,7 @@ import MockAdapter from 'axios-mock-adapter'; import axios from '@mapstore/framework/libs/ajax'; import { testEpic } from '@mapstore/framework/epics/__tests__/epicTestUtils'; import { gnViewerSetNewResourceThumbnail, closeInfoPanelOnMapClick } from '@js/epics/gnresource'; -import { setResourceThumbnail, UPDATE_RESOURCE_PROPERTIES } from '@js/actions/gnresource'; +import { setResourceThumbnail, UPDATE_RESOURCE_PROPERTIES, UPDATE_SINGLE_RESOURCE } from '@js/actions/gnresource'; import { clickOnMap } from '@mapstore/framework/actions/map'; import { SET_CONTROL_PROPERTY } from '@mapstore/framework/actions/controls'; import { @@ -33,7 +33,7 @@ describe('gnsave epics', () => { }); it('should apply new resource thumbnail', (done) => { - const NUM_ACTIONS = 2; + const NUM_ACTIONS = 3; const pk = 1; const testState = { gnresource: { @@ -56,6 +56,7 @@ describe('gnsave epics', () => { expect(actions.map(({ type }) => type)) .toEqual([ UPDATE_RESOURCE_PROPERTIES, + UPDATE_SINGLE_RESOURCE, SHOW_NOTIFICATION ]); } catch (e) { diff --git a/geonode_mapstore_client/client/js/epics/gnresource.js b/geonode_mapstore_client/client/js/epics/gnresource.js index 923a86055a..fbc96d645a 100644 --- a/geonode_mapstore_client/client/js/epics/gnresource.js +++ b/geonode_mapstore_client/client/js/epics/gnresource.js @@ -42,7 +42,8 @@ import { resourceConfigError, setResourceCompactPermissions, updateResourceProperties, - SET_RESOURCE_THUMBNAIL + SET_RESOURCE_THUMBNAIL, + updateResource } from '@js/actions/gnresource'; import { @@ -441,7 +442,7 @@ export const gnViewerSetNewResourceThumbnail = (action$, store) => return Observable.defer(() => setResourceThumbnail(resourceIDThumbnail, body)) .switchMap((res) => { - return Observable.of(updateResourceProperties({ ...currentResource, thumbnail_url: res.thumbnail_url, thumbnailChanged: false, updatingThumbnail: false }), + return Observable.of(updateResourceProperties({ ...currentResource, thumbnail_url: res.thumbnail_url, thumbnailChanged: false, updatingThumbnail: false }), updateResource({ ...currentResource, thumbnail_url: res.thumbnail_url }), successNotification({ title: "gnviewer.thumbnailsaved", message: "gnviewer.thumbnailsaved" })); }).catch((error) => { return Observable.of( diff --git a/geonode_mapstore_client/client/js/epics/gnsave.js b/geonode_mapstore_client/client/js/epics/gnsave.js index 6aca423daa..66007e350b 100644 --- a/geonode_mapstore_client/client/js/epics/gnsave.js +++ b/geonode_mapstore_client/client/js/epics/gnsave.js @@ -31,7 +31,8 @@ import { setResourceCompactPermissions, updateResourceProperties, loadingResourceConfig, - enableMapThumbnailViewer + enableMapThumbnailViewer, + updateResource } from '@js/actions/gnresource'; import { getResourceByPk, @@ -148,6 +149,7 @@ export const gnSaveContent = (action$, store) => ...currentResource, ...body }), + updateResource(resource), ...(action.showNotifications ? [ action.showNotifications === true @@ -188,9 +190,10 @@ export const gnSetMapThumbnail = (action$, store) => return Observable.defer(() => setMapThumbnail(resourceIDThumbnail, body, contentType)) .switchMap((res) => { + const randomNumber = Math.random(); return Observable.of( - updateResourceProperties({ ...currentResource, thumbnail_url: `${res.thumbnail_url}?${Math.random()}` }), - enableMapThumbnailViewer(false), + updateResourceProperties({ ...currentResource, thumbnail_url: `${res.thumbnail_url}?${randomNumber}` }), + enableMapThumbnailViewer(false), updateResource({ ...currentResource, thumbnail_url: `${res.thumbnail_url}?${randomNumber}` }), clearSave(), ...([successNotification({ title: "gnviewer.thumbnailsaved", message: "gnviewer.thumbnailsaved" })]) diff --git a/geonode_mapstore_client/client/js/reducers/gnsearch.js b/geonode_mapstore_client/client/js/reducers/gnsearch.js index 2c726ba5a5..711e0969b7 100644 --- a/geonode_mapstore_client/client/js/reducers/gnsearch.js +++ b/geonode_mapstore_client/client/js/reducers/gnsearch.js @@ -16,6 +16,8 @@ import { SET_FEATURED_RESOURCES } from '@js/actions/gnsearch'; +import { UPDATE_SINGLE_RESOURCE } from '@js/actions/gnresource'; + const defaultState = { resources: [], params: {}, @@ -46,6 +48,20 @@ function gnsearch(state = defaultState, action) { ] }; } + case UPDATE_SINGLE_RESOURCE: { + const updatedState = state.resources.map(resource => { + if (resource.pk === action?.data?.pk) { + return action?.data; + } return resource; + }); + return { + ...state, + isFirstRequest: false, + resources: [ + ...updatedState + ] + }; + } case UPDATE_RESOURCES_METADATA: { return { ...state, diff --git a/geonode_mapstore_client/client/package.json b/geonode_mapstore_client/client/package.json index 63b0cad0a2..65926532e4 100644 --- a/geonode_mapstore_client/client/package.json +++ b/geonode_mapstore_client/client/package.json @@ -26,7 +26,7 @@ "author": "GeoSolutions", "license": "BSD-2-Clause", "devDependencies": { - "@mapstore/project": "1.0.23", + "@mapstore/project": "1.0.24", "dotenv": "10.0.0", "jsdoc-to-markdown": "7.1.0" },