Skip to content

Commit

Permalink
Merge upstream (#1681)
Browse files Browse the repository at this point in the history
* Fix - Duplicated API requests on viewer resource load (#1676)

* Enhance link system between map and mapviewers (#1677)

* Configuration update for the plugins available inside the context creator (#1675)

---------

Co-authored-by: Suren <dsuren1@gmail.com>
  • Loading branch information
giohappy and dsuren1 authored Feb 29, 2024
1 parent b4f9906 commit 49c2b35
Show file tree
Hide file tree
Showing 29 changed files with 910 additions and 46 deletions.
22 changes: 22 additions & 0 deletions geonode_mapstore_client/client/js/actions/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const DOWNLOAD_COMPLETE = 'GEONODE_DOWNLOAD_COMPLETE';
export const UPDATE_SINGLE_RESOURCE = 'GEONODE_UPDATE_SINGLE_RESOURCE';
export const SET_RESOURCE_EXTENT = 'GEONODE_SET_RESOURCE_EXTENT';
export const SET_RESOURCE_PATH_PARAMETERS = 'GEONODE:SET_RESOURCE_PATH_PARAMETERS';
export const SET_MAP_VIEWER_LINKED_RESOURCE = 'GEONODE:SET_MAP_VIEWER_LINKED_RESOURCE';
export const MANAGE_LINKED_RESOURCE = 'GEONODE:MANAGE_LINKED_RESOURCE';

/**
* Actions for GeoNode resource
Expand Down Expand Up @@ -327,3 +329,23 @@ export function setResourcePathParameters(params) {
params
};
}

/**
* Manage linked resource by process type
*/
export function manageLinkedResource(payload) {
return {
type: MANAGE_LINKED_RESOURCE,
payload
};
}

/**
* Set map viewer linked resource
*/
export function setMapViewerLinkedResource(resource) {
return {
type: SET_MAP_VIEWER_LINKED_RESOURCE,
resource
};
}
20 changes: 20 additions & 0 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ export const getLinkedResourcesByPk = (pk) => {
.then(({ data }) => data ?? {});
};

export const setLinkedResourcesByPk = (sourcePk, targetPks) => {
return axios.post(parseDevHostname(`${endpoints[RESOURCES]}/${sourcePk}/linked_resources`),
{
target: castArray(targetPks)
}
)
.then(({ data }) => data ?? {});
};

export const removeLinkedResourcesByPk = (sourcePk, targetPks) => {
return axios.delete(parseDevHostname(`${endpoints[RESOURCES]}/${sourcePk}/linked_resources`), {
data: {
target: castArray(targetPks)
}
})
.then(({ data }) => data ?? {});
};

export const getResourceByUuid = (uuid) => {
return axios.get(parseDevHostname(`${endpoints[RESOURCES]}`), {
params: {
Expand Down Expand Up @@ -877,6 +895,8 @@ export default {
getResources,
getResourceByPk,
getLinkedResourcesByPk,
setLinkedResourcesByPk,
removeLinkedResourcesByPk,
getResourceByUuid,
createGeoApp,
getGeoAppByPk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React, { useRef, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import isNil from 'lodash/isNil';
import { FormControl as FormControlRB, Glyphicon } from 'react-bootstrap';
import Message from '@mapstore/framework/components/I18N/Message';
import Button from '@js/components/Button';
Expand Down Expand Up @@ -35,7 +36,8 @@ function ResourcesCompactCatalog({
onSelect,
onClose,
titleId,
noResultId
noResultId,
loading: resourceLoading
}) {

const scrollContainer = useRef();
Expand All @@ -46,6 +48,10 @@ function ResourcesCompactCatalog({
const [q, setQ] = useState('');
const isMounted = useRef();

useEffect(()=>{
!isNil(resourceLoading) && setLoading(resourceLoading);
}, [resourceLoading]);

useInfiniteScroll({
scrollContainer: scrollContainer.current,
shouldScroll: () => !loading && isNextPageAvailable,
Expand Down Expand Up @@ -151,7 +157,7 @@ function ResourcesCompactCatalog({
</ul>

</div>
{(loading && entries.length === 0) && <div
{loading && <div
style={{
position: 'absolute',
top: 0,
Expand Down
73 changes: 68 additions & 5 deletions geonode_mapstore_client/client/js/epics/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Observable } from 'rxjs';
import axios from '@mapstore/framework/libs/ajax';
import uuid from "uuid";
import url from "url";
import omit from 'lodash/omit';
import {
getNewMapConfiguration,
getNewGeoStoryConfig,
Expand All @@ -22,7 +23,9 @@ import {
getMapByPk,
getCompactPermissionsByPk,
setResourceThumbnail,
getLinkedResourcesByPk
getLinkedResourcesByPk,
setLinkedResourcesByPk,
removeLinkedResourcesByPk
} from '@js/api/geonode/v2';
import { configureMap } from '@mapstore/framework/actions/config';
import { mapSelector } from '@mapstore/framework/selectors/map';
Expand Down Expand Up @@ -51,7 +54,9 @@ import {
updateResourceProperties,
SET_RESOURCE_THUMBNAIL,
updateResource,
setResourcePathParameters
setResourcePathParameters,
MANAGE_LINKED_RESOURCE,
setMapViewerLinkedResource
} from '@js/actions/gnresource';

import {
Expand Down Expand Up @@ -104,6 +109,9 @@ import {
setCreationStep
} from '@mapstore/framework/actions/contextcreator';
import { setContext } from '@mapstore/framework/actions/context';
import { wrapStartStop } from '@mapstore/framework/observables/epics';
import { parseDevHostname } from '@js/utils/APIUtils';
import { ProcessTypes } from '@js/utils/ResourceServiceUtils';

const resourceTypes = {
[ResourceTypes.DATASET]: {
Expand Down Expand Up @@ -200,12 +208,13 @@ const resourceTypes = {
.then(({ linked_to: linkedTo = [] } = {}) => {
const mapViewers = linkedTo.find(({ resource_type: resourceType }) => resourceType === ResourceTypes.VIEWER);
return mapViewers?.pk
? getGeoAppByPk(mapViewers?.pk)
? axios.all([getGeoAppByPk(mapViewers?.pk), getLinkedResourcesByPk(mapViewers?.pk)])
: null;
})
.catch(() => null)
]))
.switchMap(([baseConfig, resource, mapViewerResource]) => {
.switchMap(([baseConfig, resource, mapViewerResources]) => {
const [mapViewerResource, viewerLinkedResource] = mapViewerResources ?? [];
const mapConfig = options.data
? options.data
: toMapStoreMapConfig(resource, baseConfig);
Expand All @@ -215,6 +224,7 @@ const resourceTypes = {
setContext(mapViewerResource ? mapViewerResource.data : null),
setResource(resource),
setResourceId(pk),
setMapViewerLinkedResource({resource: omit(mapViewerResource, ['data']), linkedResource: viewerLinkedResource}),
setResourcePathParameters({
...options?.params,
appPk: mapViewerResource?.pk,
Expand Down Expand Up @@ -369,7 +379,27 @@ const resourceTypes = {
setCreationStep('configure-plugins')
);
});
},
linkedResourceObservable: (payload) => {
const {response, source} = payload;
const { success, error: [error] } = response;
if (success) {
// redirect to map resource
const redirectUrl = window.location.href.replace(/(#).*/, '$1' + `/map/${source}`);
window.location.replace(parseDevHostname(redirectUrl));
window.location.reload();
return Observable.empty();
}
return Observable.throw(new Error(error));
},
removeLinkedResourceObservable: (payload) => {
const { resource, response } = payload;
const { success, error: [error] } = response;
return success
? Observable.of(setResourcePathParameters({...resource?.params, appPk: null}))
: Observable.throw(new Error(error));
}
// }
}
};

Expand Down Expand Up @@ -559,10 +589,43 @@ export const closeOpenPanels = (action$, store) => action$.ofType(SET_CONTROL_PR
return actions.length > 0 ? Observable.of(...actions) : Observable.empty();
});

export const gnManageLinkedResource = (action$, store) =>
action$.ofType(MANAGE_LINKED_RESOURCE)
.switchMap((action) => {
const state = store.getState();
const resource = state.gnresource ?? {};
const { source, target, resourceType, processType } = action.payload;
const resourceObservable = resourceTypes[resourceType];
let observable$ = resourceObservable?.linkedResourceObservable;
let linkedResourceFn = setLinkedResourcesByPk;
if (processType === ProcessTypes.REMOVE_LINKED_RESOURCE) {
observable$ = resourceObservable?.removeLinkedResourceObservable;
linkedResourceFn = removeLinkedResourcesByPk;
}
if (!observable$) Observable.empty();
return Observable.defer(() => linkedResourceFn(source, target))
.switchMap((response) =>
Observable.concat(
observable$({response, source, resource}),
Observable.of(
successNotification({
title: "gnviewer.linkedResource.title",
message: `gnviewer.linkedResource.message.success.${processType}`}
))
).catch(() => Observable.of(errorNotification({
title: "gnviewer.linkedResource.title",
message: `gnviewer.linkedResource.message.failure.${processType}`
}))))
.let(wrapStartStop(
setControlProperty(processType, 'loading', true),
setControlProperty(processType, 'loading', false)
));
});
export default {
gnViewerRequestNewResourceConfig,
gnViewerRequestResourceConfig,
gnViewerSetNewResourceThumbnail,
closeInfoPanelOnMapClick,
closeOpenPanels
closeOpenPanels,
gnManageLinkedResource
};
8 changes: 7 additions & 1 deletion geonode_mapstore_client/client/js/epics/gnsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import axios from '@mapstore/framework/libs/ajax';
import { Observable } from 'rxjs';
import get from 'lodash/get';
import { mapInfoSelector } from '@mapstore/framework/selectors/map';
import { userSelector } from '@mapstore/framework/selectors/security';
import {
Expand All @@ -32,7 +33,8 @@ import {
updateResourceProperties,
loadingResourceConfig,
enableMapThumbnailViewer,
updateResource
updateResource,
manageLinkedResource
} from '@js/actions/gnresource';
import {
getResourceByPk,
Expand Down Expand Up @@ -150,6 +152,10 @@ export const gnSaveContent = (action$, store) =>
return Observable.defer(() => SaveAPI[contentType](state, action.id, body, action.reload))
.switchMap((resource) => {
if (action.reload) {
if (contentType === ResourceTypes.VIEWER) {
const sourcepk = get(state, 'router.location.pathname', '').split('/').pop();
return Observable.of(manageLinkedResource({resourceType: contentType, source: sourcepk, target: resource.pk, processType: ProcessTypes.LINK_RESOURCE}));
}
window.location.href = parseDevHostname(resource?.detail_url);
window.location.reload();
return Observable.empty();
Expand Down
3 changes: 2 additions & 1 deletion geonode_mapstore_client/client/js/epics/resourceservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export const gnMonitorAsyncProcesses = (action$, store) => {

const processAPI = {
[ProcessTypes.DELETE_RESOURCE]: deleteResource,
[ProcessTypes.COPY_RESOURCE]: copyResource
[ProcessTypes.COPY_RESOURCE]: copyResource,
[ProcessTypes.REMOVE_LINKED_RESOURCE]: deleteResource
};

export const gnProcessResources = (action$) =>
Expand Down
Loading

0 comments on commit 49c2b35

Please sign in to comment.