Skip to content

Commit 0393a4c

Browse files
committed
Merge commit 'ccef351258dddab5178d29c7780cc4d47b738b0a' into #2153_settings
2 parents 0a335fe + ccef351 commit 0393a4c

File tree

523 files changed

+97
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

523 files changed

+97
-65
lines changed

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

Lines changed: 7 additions & 1 deletion
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);
@@ -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/gnresource.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import {
9797
import {
9898
canAddResource,
9999
getInitialDatasetLayer,
100+
getInitialDatasetLayerStyle,
100101
getResourceData,
101102
getResourceId,
102103
getResourceThumbnail
@@ -538,7 +539,7 @@ export const gnViewerRequestResourceConfig = (action$, store) =>
538539
...action.options,
539540
isSamePreviousResource,
540541
resourceData,
541-
selectedLayer: isSamePreviousResource && getInitialDatasetLayer(state),
542+
selectedLayer: isSamePreviousResource && {...getInitialDatasetLayer(state), style: getInitialDatasetLayerStyle(state)},
542543
params: {...action?.options?.params, query}
543544
}),
544545
Observable.of(

geonode_mapstore_client/client/js/epics/gnsave.js

Lines changed: 31 additions & 21 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';
@@ -63,7 +65,8 @@ import {
6365
getResourceId,
6466
getDataPayload,
6567
getCompactPermissions,
66-
getExtentPayload
68+
getExtentPayload,
69+
getInitialDatasetLayerStyle
6770
} from '@js/selectors/resource';
6871

6972
import {
@@ -80,13 +83,13 @@ import {
8083
toGeoNodeMapConfig,
8184
RESOURCE_PUBLISHING_PROPERTIES,
8285
RESOURCE_OPTIONS_PROPERTIES,
83-
getDimensions
86+
getDimensions,
87+
isDefaultDatasetSubtype
8488
} from '@js/utils/ResourceUtils';
8589
import {
8690
ProcessTypes,
8791
ProcessStatus
8892
} from '@js/utils/ResourceServiceUtils';
89-
import { updateDatasetTimeSeries } from '@js/api/geonode/v2/index';
9093
import { updateNode, updateSettingsParams } from '@mapstore/framework/actions/layers';
9194
import { layersSelector, getSelectedLayer as getSelectedNode } from '@mapstore/framework/selectors/layers';
9295
import { styleServiceSelector, getUpdatedLayer, selectedStyleSelector } from '@mapstore/framework/selectors/styleeditor';
@@ -112,9 +115,9 @@ const setDefaultStyle = (state, id) => {
112115
availableStyles = [...defaultStyle, ...filteredStyles];
113116
}
114117
const {style: currentStyleName} = getSelectedNode(state) ?? {};
115-
const initalStyleName = layer?.availableStyles?.[0]?.name;
118+
const initialStyleName = getInitialDatasetLayerStyle(state);
116119

117-
if (id && initalStyleName && currentStyleName !== initalStyleName) {
120+
if (id && initialStyleName && currentStyleName !== initialStyleName) {
118121
const { baseUrl = '' } = styleServiceSelector(state);
119122
return {
120123
request: () => LayersAPI.updateDefaultStyle({
@@ -171,21 +174,23 @@ const SaveAPI = {
171174
...(timeseries && { has_time: timeseries?.has_time })
172175
};
173176
const { request, actions } = setDefaultStyle(state, id); // set default style, if modified
174-
175-
return request().then(() => (id
177+
return request().then(() => {
178+
const patchResource = !isDefaultDatasetSubtype(currentResource?.subtype) ? updateResourceAPI : updateDataset;
179+
return (id
176180
// perform dataset and timeseries updates sequentially to avoid race conditions
177-
? updateDataset(id, updatedBody).then((resource) =>
178-
updateDatasetTimeSeries(id, timeseries).then(() => resource)
179-
) : Promise.resolve())
180-
.then((_resource) => {
181-
let resource = omit(_resource, 'default_style');
182-
if (timeseries) {
183-
const layerId = layersSelector(state)?.find((l) => l.pk === resource?.pk)?.id;
184-
// actions to be dispacted are added to response array
185-
return [resource, updateNode(layerId, 'layers', { dimensions: get(resource, 'data.dimensions', []) }), ...actions];
186-
}
187-
return [resource, ...actions];
188-
}));
181+
? patchResource(id, updatedBody).then((resource) =>
182+
timeseries ? updateDatasetTimeSeries(id, timeseries).then(() => resource) : Promise.resolve(resource)
183+
) : Promise.resolve())
184+
.then((_resource) => {
185+
let resource = omit(_resource, 'default_style');
186+
if (timeseries) {
187+
const layerId = layersSelector(state)?.find((l) => l.pk === resource?.pk)?.id;
188+
// actions to be dispacted are added to response array
189+
return [resource, updateNode(layerId, 'layers', { dimensions: get(resource, 'data.dimensions', []) }), ...actions];
190+
}
191+
return [resource, ...actions];
192+
});
193+
});
189194
},
190195
[ResourceTypes.VIEWER]: (state, id, body) => {
191196
const user = userSelector(state);
@@ -225,7 +230,7 @@ export const gnSaveContent = (action$, store) =>
225230
const { compactPermissions } = getPermissionsPayload(state);
226231
return Observable.defer(() => SaveAPI[contentType](state, action.id, body, action.reload))
227232
.switchMap((response) => {
228-
const [resource, ...actions] = castArray(response);
233+
let [resource, ...actions] = castArray(response);
229234
if (action.reload) {
230235
if (contentType === ResourceTypes.VIEWER) {
231236
const sourcepk = get(state, 'router.location.pathname', '').split('/').pop();
@@ -235,6 +240,11 @@ export const gnSaveContent = (action$, store) =>
235240
window.location.reload();
236241
return Observable.empty();
237242
}
243+
const selectedLayer = getSelectedNode(state);
244+
const currentStyle = selectedLayer?.availableStyles?.find(({ name }) => selectedLayer?.style?.includes(name));
245+
// adding default style upon saving resource for correct style comparison
246+
const defaultStyle = currentStyle ? { sld_title: currentStyle.title, name: selectedLayer?.style } : null;
247+
resource = {...resource, default_style: defaultStyle};
238248
return Observable.merge(
239249
Observable.of(
240250
saveSuccess(resource),

geonode_mapstore_client/client/js/selectors/resource.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,20 @@ function isMapCenterEqual(initialCenter = {}, currentCenter = {}) {
232232
return initialCenter.crs === currentCenter.crs && Math.abs(initialCenter.x - currentCenter.x) < CENTER_EPS && Math.abs(initialCenter.y - currentCenter.y) < CENTER_EPS;
233233
}
234234

235-
export function getInitialDatasetLayer(state) {
235+
export const getInitialDatasetResource = (state) => {
236236
const initialResource = state?.gnresource?.initialResource;
237-
return initialResource && initialResource.resource_type === ResourceTypes.DATASET && resourceToLayerConfig(omit(initialResource, ['default_style']));
238-
}
237+
return initialResource && initialResource.resource_type === ResourceTypes.DATASET ? initialResource : null;
238+
};
239+
240+
export const getInitialDatasetLayer = (state) => {
241+
const initialResource = getInitialDatasetResource(state);
242+
return initialResource && resourceToLayerConfig(omit(initialResource, ['default_style']));
243+
};
244+
245+
export const getInitialDatasetLayerStyle = (state) => {
246+
const initialResource = getInitialDatasetResource(state);
247+
return initialResource ? resourceToLayerConfig(initialResource)?.style : null;
248+
};
239249

240250
function isResourceDataEqual(state, initialData = {}, currentData = {}) {
241251
const resourceType = state?.gnresource?.type;
@@ -308,12 +318,17 @@ function isResourceDataEqual(state, initialData = {}, currentData = {}) {
308318
const selectedLayer = getSelectedNode(state);
309319
const selectedLayerInitial = getSelectedLayer(state);
310320
const initialLayerData = {...selectedLayerInitial, ...initialData};
321+
const initialStyle = getInitialDatasetLayerStyle(state);
311322

312323
const isSettingsEqual = compareObjects(omit(currentData, ['style', 'fields']),
313324
omit(initialLayerData, ['style', 'fields', 'extendedParams', 'pk', '_v_', 'isDataset', 'perms']));
314-
const isStyleEqual = isEmpty(selectedLayer?.availableStyles) || isEmpty(selectedLayer?.style) ? true
315-
: selectedLayer?.style === selectedLayer?.availableStyles?.[0]?.name;
316-
const isAttributesEqual = isEmpty(selectedLayer) ? true : !isEmpty(initialLayerData) && isEqual(initialLayerData?.fields, selectedLayer.fields);
325+
const isStyleEqual = isEmpty(initialStyle) || isEmpty(selectedLayer?.style) ? true
326+
: selectedLayer?.style === initialStyle;
327+
const isAttributesEqual = isEmpty(selectedLayer) ? true
328+
: !isEmpty(initialLayerData) && isEqual(
329+
isEmpty(initialLayerData?.fields) ? {} : initialLayerData?.fields,
330+
isEmpty(selectedLayer?.fields) ? {} : selectedLayer?.fields
331+
);
317332

318333
return isSettingsEqual && isAttributesEqual && isStyleEqual;
319334
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
geonode-mapstore-client-v4.0.0-419786b06dee3a4bbc04b05d064eef1e0284bb84
1+
geonode-mapstore-client-v4.0.0-54c993e308fefb3edb52b11da971f733fc6ba0c6

geonode_mapstore_client/static/mapstore/dist/js/1030.1834a13c1e01b472.chunk.js renamed to geonode_mapstore_client/static/mapstore/dist/js/1030.d55f7bdafd7ef840.chunk.js

File renamed without changes.

geonode_mapstore_client/static/mapstore/dist/js/104.1834a13c1e01b472.chunk.js renamed to geonode_mapstore_client/static/mapstore/dist/js/104.d55f7bdafd7ef840.chunk.js

File renamed without changes.

geonode_mapstore_client/static/mapstore/dist/js/1092.1834a13c1e01b472.chunk.js renamed to geonode_mapstore_client/static/mapstore/dist/js/1092.d55f7bdafd7ef840.chunk.js

File renamed without changes.

geonode_mapstore_client/static/mapstore/dist/js/1111.1834a13c1e01b472.chunk.js renamed to geonode_mapstore_client/static/mapstore/dist/js/1111.d55f7bdafd7ef840.chunk.js

File renamed without changes.

geonode_mapstore_client/static/mapstore/dist/js/1141.1834a13c1e01b472.chunk.js renamed to geonode_mapstore_client/static/mapstore/dist/js/1141.d55f7bdafd7ef840.chunk.js

File renamed without changes.

0 commit comments

Comments
 (0)