Skip to content

Commit de8109f

Browse files
authored
review operations configurations (#1890)
1 parent 2e0e563 commit de8109f

File tree

5 files changed

+41
-153
lines changed

5 files changed

+41
-153
lines changed

geonode_mapstore_client/client/js/plugins/Operation/components/UploadPanel.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import FaIcon from '@js/components/FaIcon';
1414
import Message from '@mapstore/framework/components/I18N/Message';
1515
import ViewerLayout from '@js/components/ViewerLayout';
1616
import uuidv1 from 'uuid/v1';
17+
import uniq from 'lodash/uniq';
1718
import { getFileNameParts } from '@js/utils/FileUtils';
1819
import tooltip from '@mapstore/framework/components/misc/enhancers/tooltip';
1920
import PendingUploadCard from './PendingUploadCard';
@@ -109,7 +110,7 @@ function UploadPanel({
109110
return handleAdd([getDefaultRemoteResource({ id: uuidv1(), type: 'remote', url: '' })]);
110111
};
111112

112-
const supportedLabels = supportedFiles.map(supportedFile => supportedFile.label).join(', ');
113+
const supportedLabels = uniq(supportedFiles.map(supportedFile => supportedFile.label)).join(', ');
113114
const uploadsList = uploads.filter(upload => upload.type === 'file' ? upload.supported : true);
114115
const supportedUploads = uploads.filter(upload => upload.supported);
115116
const readyUploads = uploads.filter(upload => upload.ready);

geonode_mapstore_client/client/js/plugins/Operation/index.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Message from '@mapstore/framework/components/I18N/Message';
3131
* @prop {string} iconName a font awesome icon name for the central section
3232
* @prop {string} titleMsgId title for the central section
3333
* @prop {string} descriptionMsgId description for the central section
34-
* @prop {string} source the operation source used in the upload process
34+
* @prop {string} action the operation action used in the upload process
3535
* @prop {boolean} pageReload if true the page is reloaded after clicking on reload
3636
* @prop {object} api an object with the api configuration for upload and execution request
3737
* @prop {object} api.upload configuration for the upload process
@@ -57,25 +57,25 @@ import Message from '@mapstore/framework/components/I18N/Message';
5757
* "iconName": "file",
5858
* "titleMsgId": "gnviewer.operationTitle",
5959
* "descriptionMsgId": "gnviewer.operationDescription",
60-
* "source": "upload",
60+
* "action": "upload",
6161
* "api": {
6262
* "upload": {
6363
* "url": "{context.getEndpointUrl('uploads', '/upload')}",
6464
* "maxParallelUploads": 1,
6565
* "enableRemoteUploads": false,
66-
* "supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { source: ['upload'] })}",
66+
* "supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { actions: ['upload'] })}",
6767
* "body": {
6868
* "file": {
6969
* "base_file": "{context.getUploadMainFile}",
70-
* "resource_pk": "{context.get(state('gnResourceData'), 'pk')}"
70+
* "resource_pk": "{context.get(state('gnResourceData'), 'pk')}",
71+
* "action": "upload"
7172
* }
7273
* }
7374
* },
7475
* "executionRequest": {
7576
* "url": "{context.getEndpointUrl('executionrequest')}",
7677
* "params": {
77-
* "filter{source}": "resource_file_upload",
78-
* "filter{name.endswith}": ".xml",
78+
* "filter{action}": "upload",
7979
* "sort[]": "-created",
8080
* "filter{geonode_resource}": "{context.get(state('gnResourceData'), 'pk')}"
8181
* }
@@ -100,22 +100,22 @@ function Operation({
100100
iconName,
101101
titleMsgId,
102102
descriptionMsgId,
103-
source,
103+
action,
104104
pageReload
105105
}) {
106106

107107
// open the import ui if a blocking execution is still running
108108
const executions = resource?.executions;
109109
useEffect(() => {
110-
if (executions && source && blocking) {
110+
if (executions && action && blocking) {
111111
const runningExecution = executions
112112
.find((execution) => execution.status === 'running'
113-
&& execution?.input_params?.source === source);
113+
&& execution?.input_params?.action === action);
114114
if (runningExecution) {
115115
onSelect(id);
116116
}
117117
}
118-
}, [id, blocking, source, executions]);
118+
}, [id, blocking, action, executions]);
119119

120120
if (selected !== id) {
121121
return null;

geonode_mapstore_client/client/js/routes/UploadDataset.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,21 @@ function UploadDataset({
3737
body: {
3838
file: {
3939
'base_file': getUploadMainFile,
40-
'store_spatial_files': true
40+
'store_spatial_files': true,
41+
'action': 'upload'
4142
},
4243
remote: {
4344
'url': getUploadProperty('url'),
4445
'title': getUploadProperty('url'),
45-
'type': getUploadProperty('remoteType')
46+
'type': getUploadProperty('remoteType'),
47+
'action': 'upload'
4648
}
4749
}
4850
},
4951
executionRequest: {
5052
url: getEndpointUrl(EXECUTION_REQUEST),
5153
params: {
52-
'filter{action}': 'import',
53-
'filter{source}': 'upload',
54+
'filter{action}': 'upload',
5455
'sort[]': '-created'
5556
}
5657
}
@@ -83,11 +84,10 @@ function UploadDataset({
8384
setForceRequests(prevForceRequests => prevForceRequests + 1);
8485
}
8586
});
86-
8787
return (
8888
<UploadPanel
8989
enableRemoteUploads
90-
supportedFiles={getSupportedFilesByResourceType('dataset', { source: ['upload'] })}
90+
supportedFiles={getSupportedFilesByResourceType('dataset', { actions: ['upload'] })}
9191
maxParallelUploads={getMaxParallelUploads()}
9292
maxAllowedSize={getMaxAllowedSizeByResourceType('dataset')}
9393
progress={progress}

geonode_mapstore_client/client/js/utils/UploadUtils.js

Lines changed: 7 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const getMaxAllowedSizeByResourceType = (resourceType) => {
194194
return maxAllowedSize;
195195
};
196196

197-
export const getSupportedFilesByResourceType = (resourceType, { source } = {}) => {
197+
export const getSupportedFilesByResourceType = (resourceType, { actions } = {}) => {
198198
if (resourceType === 'document') {
199199
const { allowedDocumentTypes } = getConfigProp('geoNodeSettings') || [];
200200
return allowedDocumentTypes.map((ext) => {
@@ -205,122 +205,10 @@ export const getSupportedFilesByResourceType = (resourceType, { source } = {}) =
205205
};
206206
});
207207
}
208-
// const { upload: uploadSettings = {} } = getConfigProp('geoNodeSettings') || {};
209-
// const { supportedDatasetFileTypes: supportedDatasetTypes } = uploadSettings;
210-
return [
211-
{
212-
"id": "shp",
213-
"label": "ESRI Shapefile",
214-
"required_ext": ["shp", "prj", "dbf", "shx"],
215-
"optional_ext": ["xml", "sld", "cpg", "cst"],
216-
"source": ["upload"],
217-
"format": "vector"
218-
},
219-
{
220-
"id": "csv",
221-
"label": "CSV",
222-
"required_ext": ["csv"],
223-
"optional_ext": ["sld", "xml"],
224-
"source": ["upload"],
225-
"format": "vector"
226-
},
227-
{
228-
"id": "gpkg",
229-
"label": "GeoPackage",
230-
"required_ext": ["gpkg"],
231-
"source": ["upload"],
232-
"format": "vector"
233-
},
234-
{
235-
"id": "json",
236-
"label": "GeoJSON",
237-
"required_ext": ["json"],
238-
"optional_ext": ["sld", "xml"],
239-
"source": ["upload"],
240-
"format": "vector"
241-
},
242-
{
243-
"id": "geojson",
244-
"label": "GeoJSON",
245-
"required_ext": ["geojson"],
246-
"optional_ext": ["sld", "xml"],
247-
"source": ["upload"],
248-
"format": "vector"
249-
},
250-
{
251-
"id": "kml",
252-
"label": "KML",
253-
"required_ext": ["kml"],
254-
"source": ["upload"],
255-
"format": "vector"
256-
},
257-
{
258-
"id": "kmz",
259-
"label": "KMZ",
260-
"required_ext": ["kmz"],
261-
"source": ["upload"],
262-
"format": "vector"
263-
},
264-
{
265-
"id": "3dtiles",
266-
"label": "3D Tiles",
267-
"required_ext": ["zip"],
268-
"source": ["upload"],
269-
"format": "vector"
270-
},
271-
{
272-
"id": "tiff",
273-
"label": "TIFF",
274-
"required_ext": ["tiff"],
275-
"optional_ext": ["xml", "sld"],
276-
"source": ["upload"],
277-
"format": "raster"
278-
},
279-
{
280-
"id": "tif",
281-
"label": "TIF",
282-
"required_ext": ["tif"],
283-
"optional_ext": ["xml", "sld"],
284-
"source": ["upload"],
285-
"format": "raster"
286-
},
287-
{
288-
"id": "geotiff",
289-
"label": "GeoTIFF",
290-
"required_ext": ["geotiff"],
291-
"optional_ext": ["xml", "sld"],
292-
"source": ["upload"],
293-
"format": "raster"
294-
},
295-
{
296-
"id": "geotif",
297-
"label": "GeoTIF",
298-
"required_ext": ["geotif"],
299-
"optional_ext": ["xml", "sld"],
300-
"source": ["upload"],
301-
"format": "raster"
302-
},
303-
{
304-
"id": "zip",
305-
"label": "Zip Archive",
306-
"required_ext": ["zip"],
307-
"optional_ext": ["xml", "sld"],
308-
"source": ["upload"],
309-
"format": "archive"
310-
},
311-
{
312-
"id": "sld",
313-
"label": "Styled Layer Descriptor 1.0, 1.1 (SLD)",
314-
"required_ext": ["sld"],
315-
"source": ["resource_style_upload"],
316-
"format": "metadata"
317-
},
318-
{
319-
"id": "xml",
320-
"label": "XML Metadata File (XML - ISO, FGDC, ebRIM, Dublin Core)",
321-
"required_ext": ["xml"],
322-
"source": ["resource_metadata_upload"],
323-
"format": "metadata"
324-
}
325-
].filter(supportedType => source ? supportedType.source.some(value => source.includes(value)) : true);
208+
const { upload: uploadSettings = {} } = getConfigProp('geoNodeSettings') || {};
209+
const { supportedDatasetFileTypes: supportedDatasetTypes } = uploadSettings;
210+
return (supportedDatasetTypes || [])
211+
.map((supportedType) => supportedType.formats.map(format => ({ ...supportedType, ...format })))
212+
.flat()
213+
.filter(supportedType => actions ? supportedType.actions.some(value => actions.includes(value)) : true);
326214
};

geonode_mapstore_client/static/mapstore/configs/localConfig.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,25 +1227,24 @@
12271227
"blocking": true,
12281228
"iconName": "paint-brush",
12291229
"titleMsgId": "gnviewer.uploadDatasetStyle",
1230-
"source": "resource_file_upload",
1230+
"action": "resource_style_upload",
12311231
"api": {
12321232
"upload": {
12331233
"url": "{context.getEndpointUrl('uploads', '/upload')}",
12341234
"maxParallelUploads": 1,
12351235
"body": {
12361236
"file": {
12371237
"resource_pk": "{context.get(state('gnResourceData'), 'pk')}",
1238-
"base_file": "{context.getUploadMainFile}"
1238+
"base_file": "{context.getUploadMainFile}",
1239+
"action": "resource_style_upload"
12391240
}
12401241
},
1241-
"supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { source: ['resource_style_upload'] })}"
1242+
"supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { actions: ['resource_style_upload'] })}"
12421243
},
12431244
"executionRequest": {
12441245
"url": "{context.getEndpointUrl('executionrequest')}",
12451246
"params": {
1246-
"filter{source}": "resource_file_upload",
1247-
"filter{name.endswith}": ".sld",
1248-
"filter{action}": "import",
1247+
"filter{action}": "resource_style_upload",
12491248
"sort[]": "-created",
12501249
"filter{geonode_resource}": "{context.get(state('gnResourceData'), 'pk')}"
12511250
}
@@ -1267,25 +1266,25 @@
12671266
"iconName": "file-code-o",
12681267
"titleMsgId": "gnviewer.uploadDatasetMetadata",
12691268
"blocking": true,
1270-
"source": "resource_file_upload",
1269+
"action": "resource_metadata_upload",
1270+
"pageReload": true,
12711271
"api": {
12721272
"upload": {
12731273
"url": "{context.getEndpointUrl('uploads', '/upload')}",
12741274
"maxParallelUploads": 1,
12751275
"body": {
12761276
"file": {
12771277
"resource_pk": "{context.get(state('gnResourceData'), 'pk')}",
1278-
"base_file": "{context.getUploadMainFile}"
1278+
"base_file": "{context.getUploadMainFile}",
1279+
"action": "resource_metadata_upload"
12791280
}
12801281
},
1281-
"supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { source: ['resource_metadata_upload'] })}"
1282+
"supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { actions: ['resource_metadata_upload'] })}"
12821283
},
12831284
"executionRequest": {
12841285
"url": "{context.getEndpointUrl('executionrequest')}",
12851286
"params": {
1286-
"filter{source}": "resource_file_upload",
1287-
"filter{name.endswith}": ".xml",
1288-
"filter{action}": "import",
1287+
"filter{action}": "resource_metadata_upload",
12891288
"sort[]": "-created",
12901289
"filter{geonode_resource}": "{context.get(state('gnResourceData'), 'pk')}"
12911290
}
@@ -1307,7 +1306,7 @@
13071306
"iconName": "refresh",
13081307
"titleMsgId": "gnviewer.replaceDatasetTitle",
13091308
"blocking": true,
1310-
"source": "upload",
1309+
"action": "replace",
13111310
"pageReload": true,
13121311
"api": {
13131312
"upload": {
@@ -1318,16 +1317,16 @@
13181317
"resource_pk": "{context.get(state('gnResourceData'), 'pk')}",
13191318
"base_file": "{context.getUploadMainFile}",
13201319
"store_spatial_files": true,
1321-
"overwrite_existing_layer": true
1320+
"overwrite_existing_layer": true,
1321+
"action": "replace"
13221322
}
13231323
},
1324-
"supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { source: ['upload'] })}"
1324+
"supportedFiles": "{context.getSupportedFilesByResourceType('dataset', { actions: ['replace'] })}"
13251325
},
13261326
"executionRequest": {
13271327
"url": "{context.getEndpointUrl('executionrequest')}",
13281328
"params": {
1329-
"filter{source}": "upload",
1330-
"filter{action}": "import",
1329+
"filter{action}": "replace",
13311330
"sort[]": "-created",
13321331
"filter{geonode_resource}": "{context.get(state('gnResourceData'), 'pk')}"
13331332
}

0 commit comments

Comments
 (0)