Skip to content
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
10 changes: 8 additions & 2 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ export const updateDataset = (pk, body) => {
.then(({ data }) => (data.dataset));
};

export const updateResource = (pk, body) => {
return axios.patch(getEndpointUrl(RESOURCES, `/${pk}`), body)
.then(({ data }) => (data.resource));
};

export const updateDocument = (pk, body) => {
return axios.patch(getEndpointUrl(DOCUMENTS, `/${pk}`), body)
.then(({ data }) => data.document);
Expand Down Expand Up @@ -731,7 +736,7 @@ export const createDataset = (body) => {

export const getMetadataDownloadLinkByPk = (pk) => {
return getEndpointUrl(RESOURCES, `/${pk}/iso_metadata_xml`);
}
};

export default {
getEndpoints,
Expand Down Expand Up @@ -771,5 +776,6 @@ export default {
deleteExecutionRequest,
getResourceByTypeAndByPk,
createDataset,
getMetadataDownloadLinkByPk
getMetadataDownloadLinkByPk,
updateResource
};
38 changes: 21 additions & 17 deletions geonode_mapstore_client/client/js/epics/gnsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ import {
updateDocument,
setMapThumbnail,
updateCompactPermissionsByPk,
getResourceByUuid
getResourceByUuid,
updateDatasetTimeSeries,
updateResource as updateResourceAPI
} from '@js/api/geonode/v2';
import { parseDevHostname } from '@js/utils/APIUtils';
import uuid from 'uuid';
Expand Down Expand Up @@ -79,13 +81,13 @@ import {
cleanCompactPermissions,
toGeoNodeMapConfig,
RESOURCE_MANAGEMENT_PROPERTIES,
getDimensions
getDimensions,
isDefaultDatasetSubtype
} from '@js/utils/ResourceUtils';
import {
ProcessTypes,
ProcessStatus
} from '@js/utils/ResourceServiceUtils';
import { updateDatasetTimeSeries } from '@js/api/geonode/v2/index';
import { updateNode, updateSettingsParams } from '@mapstore/framework/actions/layers';
import { layersSelector, getSelectedLayer as getSelectedNode } from '@mapstore/framework/selectors/layers';
import { styleServiceSelector, getUpdatedLayer, selectedStyleSelector } from '@mapstore/framework/selectors/styleeditor';
Expand Down Expand Up @@ -170,21 +172,23 @@ const SaveAPI = {
...(timeseries && { has_time: timeseries?.has_time })
};
const { request, actions } = setDefaultStyle(state, id); // set default style, if modified

return request().then(() => (id
return request().then(() => {
const patchResource = !isDefaultDatasetSubtype(currentResource?.subtype) ? updateResourceAPI : updateDataset;
return (id
// perform dataset and timeseries updates sequentially to avoid race conditions
? updateDataset(id, updatedBody).then((resource) =>
updateDatasetTimeSeries(id, timeseries).then(() => resource)
) : Promise.resolve())
.then((_resource) => {
let resource = omit(_resource, 'default_style');
if (timeseries) {
const layerId = layersSelector(state)?.find((l) => l.pk === resource?.pk)?.id;
// actions to be dispacted are added to response array
return [resource, updateNode(layerId, 'layers', { dimensions: get(resource, 'data.dimensions', []) }), ...actions];
}
return [resource, ...actions];
}));
? patchResource(id, updatedBody).then((resource) =>
timeseries ? updateDatasetTimeSeries(id, timeseries).then(() => resource) : Promise.resolve(resource)
) : Promise.resolve())
.then((_resource) => {
let resource = omit(_resource, 'default_style');
if (timeseries) {
const layerId = layersSelector(state)?.find((l) => l.pk === resource?.pk)?.id;
// actions to be dispacted are added to response array
return [resource, updateNode(layerId, 'layers', { dimensions: get(resource, 'data.dimensions', []) }), ...actions];
}
return [resource, ...actions];
});
});
},
[ResourceTypes.VIEWER]: (state, id, body) => {
const user = userSelector(state);
Expand Down
6 changes: 5 additions & 1 deletion geonode_mapstore_client/client/js/selectors/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ function isResourceDataEqual(state, initialData = {}, currentData = {}) {
omit(initialLayerData, ['style', 'fields', 'extendedParams', 'pk', '_v_', 'isDataset', 'perms']));
const isStyleEqual = isEmpty(selectedLayer?.availableStyles) || isEmpty(selectedLayer?.style) ? true
: selectedLayer?.style === selectedLayer?.availableStyles?.[0]?.name;
const isAttributesEqual = isEmpty(selectedLayer) ? true : !isEmpty(initialLayerData) && isEqual(initialLayerData?.fields, selectedLayer.fields);
const isAttributesEqual = isEmpty(selectedLayer) ? true
: !isEmpty(initialLayerData) && isEqual(
isEmpty(initialLayerData?.fields) ? {} : initialLayerData?.fields,
isEmpty(selectedLayer?.fields) ? {} : selectedLayer?.fields
);

return isSettingsEqual && isAttributesEqual && isStyleEqual;
}
Expand Down