Skip to content

Commit 0b65237

Browse files
authored
[Fixes #1893] Changing settings of a 3D Tiles resource throws an error (#2199)
1 parent 6e69667 commit 0b65237

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

geonode_mapstore_client/client/js/api/geonode/v2/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ export const updateDataset = (pk, body) => {
374374
.then(({ data }) => (data.dataset));
375375
};
376376

377+
export const updateResource = (pk, body) => {
378+
return axios.patch(getEndpointUrl(RESOURCES, `/${pk}`), body)
379+
.then(({ data }) => (data.resource));
380+
};
381+
377382
export const updateDocument = (pk, body) => {
378383
return axios.patch(getEndpointUrl(DOCUMENTS, `/${pk}`), body)
379384
.then(({ data }) => data.document);
@@ -731,7 +736,7 @@ export const createDataset = (body) => {
731736

732737
export const getMetadataDownloadLinkByPk = (pk) => {
733738
return getEndpointUrl(RESOURCES, `/${pk}/iso_metadata_xml`);
734-
}
739+
};
735740

736741
export default {
737742
getEndpoints,
@@ -771,5 +776,6 @@ export default {
771776
deleteExecutionRequest,
772777
getResourceByTypeAndByPk,
773778
createDataset,
774-
getMetadataDownloadLinkByPk
779+
getMetadataDownloadLinkByPk,
780+
updateResource
775781
};

geonode_mapstore_client/client/js/epics/gnsave.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ import {
5151
updateDocument,
5252
setMapThumbnail,
5353
updateCompactPermissionsByPk,
54-
getResourceByUuid
54+
getResourceByUuid,
55+
updateDatasetTimeSeries,
56+
updateResource as updateResourceAPI
5557
} from '@js/api/geonode/v2';
5658
import { parseDevHostname } from '@js/utils/APIUtils';
5759
import uuid from 'uuid';
@@ -79,13 +81,13 @@ import {
7981
cleanCompactPermissions,
8082
toGeoNodeMapConfig,
8183
RESOURCE_MANAGEMENT_PROPERTIES,
82-
getDimensions
84+
getDimensions,
85+
isDefaultDatasetSubtype
8386
} from '@js/utils/ResourceUtils';
8487
import {
8588
ProcessTypes,
8689
ProcessStatus
8790
} from '@js/utils/ResourceServiceUtils';
88-
import { updateDatasetTimeSeries } from '@js/api/geonode/v2/index';
8991
import { updateNode, updateSettingsParams } from '@mapstore/framework/actions/layers';
9092
import { layersSelector, getSelectedLayer as getSelectedNode } from '@mapstore/framework/selectors/layers';
9193
import { styleServiceSelector, getUpdatedLayer, selectedStyleSelector } from '@mapstore/framework/selectors/styleeditor';
@@ -170,21 +172,23 @@ const SaveAPI = {
170172
...(timeseries && { has_time: timeseries?.has_time })
171173
};
172174
const { request, actions } = setDefaultStyle(state, id); // set default style, if modified
173-
174-
return request().then(() => (id
175+
return request().then(() => {
176+
const patchResource = !isDefaultDatasetSubtype(currentResource?.subtype) ? updateResourceAPI : updateDataset;
177+
return (id
175178
// perform dataset and timeseries updates sequentially to avoid race conditions
176-
? updateDataset(id, updatedBody).then((resource) =>
177-
updateDatasetTimeSeries(id, timeseries).then(() => resource)
178-
) : Promise.resolve())
179-
.then((_resource) => {
180-
let resource = omit(_resource, 'default_style');
181-
if (timeseries) {
182-
const layerId = layersSelector(state)?.find((l) => l.pk === resource?.pk)?.id;
183-
// actions to be dispacted are added to response array
184-
return [resource, updateNode(layerId, 'layers', { dimensions: get(resource, 'data.dimensions', []) }), ...actions];
185-
}
186-
return [resource, ...actions];
187-
}));
179+
? patchResource(id, updatedBody).then((resource) =>
180+
timeseries ? updateDatasetTimeSeries(id, timeseries).then(() => resource) : Promise.resolve(resource)
181+
) : Promise.resolve())
182+
.then((_resource) => {
183+
let resource = omit(_resource, 'default_style');
184+
if (timeseries) {
185+
const layerId = layersSelector(state)?.find((l) => l.pk === resource?.pk)?.id;
186+
// actions to be dispacted are added to response array
187+
return [resource, updateNode(layerId, 'layers', { dimensions: get(resource, 'data.dimensions', []) }), ...actions];
188+
}
189+
return [resource, ...actions];
190+
});
191+
});
188192
},
189193
[ResourceTypes.VIEWER]: (state, id, body) => {
190194
const user = userSelector(state);

geonode_mapstore_client/client/js/selectors/resource.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,11 @@ function isResourceDataEqual(state, initialData = {}, currentData = {}) {
313313
omit(initialLayerData, ['style', 'fields', 'extendedParams', 'pk', '_v_', 'isDataset', 'perms']));
314314
const isStyleEqual = isEmpty(selectedLayer?.availableStyles) || isEmpty(selectedLayer?.style) ? true
315315
: selectedLayer?.style === selectedLayer?.availableStyles?.[0]?.name;
316-
const isAttributesEqual = isEmpty(selectedLayer) ? true : !isEmpty(initialLayerData) && isEqual(initialLayerData?.fields, selectedLayer.fields);
316+
const isAttributesEqual = isEmpty(selectedLayer) ? true
317+
: !isEmpty(initialLayerData) && isEqual(
318+
isEmpty(initialLayerData?.fields) ? {} : initialLayerData?.fields,
319+
isEmpty(selectedLayer?.fields) ? {} : selectedLayer?.fields
320+
);
317321

318322
return isSettingsEqual && isAttributesEqual && isStyleEqual;
319323
}

0 commit comments

Comments
 (0)