Skip to content

Commit

Permalink
[Fixes #1038] Reload catalogue after saving a resource (#1062) (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidQuartz authored Jul 18, 2022
1 parent 7d8df35 commit 36d661e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
12 changes: 12 additions & 0 deletions geonode_mapstore_client/client/js/actions/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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: {
Expand All @@ -56,6 +56,7 @@ describe('gnsave epics', () => {
expect(actions.map(({ type }) => type))
.toEqual([
UPDATE_RESOURCE_PROPERTIES,
UPDATE_SINGLE_RESOURCE,
SHOW_NOTIFICATION
]);
} catch (e) {
Expand Down
5 changes: 3 additions & 2 deletions geonode_mapstore_client/client/js/epics/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {
resourceConfigError,
setResourceCompactPermissions,
updateResourceProperties,
SET_RESOURCE_THUMBNAIL
SET_RESOURCE_THUMBNAIL,
updateResource
} from '@js/actions/gnresource';

import {
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 6 additions & 3 deletions geonode_mapstore_client/client/js/epics/gnsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
setResourceCompactPermissions,
updateResourceProperties,
loadingResourceConfig,
enableMapThumbnailViewer
enableMapThumbnailViewer,
updateResource
} from '@js/actions/gnresource';
import {
getResourceByPk,
Expand Down Expand Up @@ -148,6 +149,7 @@ export const gnSaveContent = (action$, store) =>
...currentResource,
...body
}),
updateResource(resource),
...(action.showNotifications
? [
action.showNotifications === true
Expand Down Expand Up @@ -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" })])

Expand Down
16 changes: 16 additions & 0 deletions geonode_mapstore_client/client/js/reducers/gnsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
SET_FEATURED_RESOURCES
} from '@js/actions/gnsearch';

import { UPDATE_SINGLE_RESOURCE } from '@js/actions/gnresource';

const defaultState = {
resources: [],
params: {},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 36d661e

Please sign in to comment.