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

[Fixes 1038] Reload catalogue after saving a reaource #1062

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 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
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down