From 42b326ca9aae765b27b83205b89cd1a8371b071c Mon Sep 17 00:00:00 2001 From: David Quartey <42542676+DavidQuartz@users.noreply.github.com> Date: Tue, 12 Jul 2022 12:39:41 +0000 Subject: [PATCH] [Fixes #1069] Use new config setting for supported dataset file types (#1070) (#1081) --- .../client/js/routes/UploadDataset.jsx | 74 +++---------------- 1 file changed, 12 insertions(+), 62 deletions(-) diff --git a/geonode_mapstore_client/client/js/routes/UploadDataset.jsx b/geonode_mapstore_client/client/js/routes/UploadDataset.jsx index 898b6342eb..dfcf036960 100644 --- a/geonode_mapstore_client/client/js/routes/UploadDataset.jsx +++ b/geonode_mapstore_client/client/js/routes/UploadDataset.jsx @@ -24,63 +24,6 @@ import UploadContainer from '@js/routes/upload/UploadContainer'; import { getConfigProp } from '@mapstore/framework/utils/ConfigUtils'; import { parseUploadResponse, processUploadResponse, parseUploadFiles } from '@js/utils/ResourceUtils'; -const supportedDatasetTypes = [ - { - id: 'shp', - label: 'ESRI Shapefile', - format: 'vector', - ext: ['shp'], - requires: ['shp', 'prj', 'dbf', 'shx'], - optional: ['xml', 'sld'] - }, - { - id: 'tiff', - label: 'GeoTIFF', - format: 'raster', - ext: ['tiff', 'tif'], - mimeType: ['image/tiff'], - optional: ['xml', 'sld'] - }, - { - id: 'csv', - label: 'Comma Separated Value (CSV)', - format: 'vector', - ext: ['csv'], - mimeType: ['text/csv'], - optional: ['xml', 'sld'] - }, - { - id: 'zip', - label: 'Zip Archive', - format: 'archive', - ext: ['zip'], - mimeType: ['application/zip'], - optional: ['xml', 'sld'] - }, - { - id: 'xml', - label: 'XML Metadata File', - format: 'metadata', - ext: ['xml'], - mimeType: ['application/json'], - needsFiles: ['shp', 'prj', 'dbf', 'shx', 'csv', 'tiff', 'zip', 'sld'] - }, - { - id: 'sld', - label: 'Styled Layer Descriptor (SLD)', - format: 'metadata', - ext: ['sld'], - mimeType: ['application/json'], - needsFiles: ['shp', 'prj', 'dbf', 'shx', 'csv', 'tiff', 'zip', 'xml'] - } -]; - -const supportedExtensions = supportedDatasetTypes.map(({ ext }) => ext || []).flat(); -const supportedMimeTypes = supportedDatasetTypes.map(({ mimeType }) => mimeType || []).flat(); -const supportedRequiresExtensions = supportedDatasetTypes.map(({ requires }) => requires || []).flat(); -const supportedLabels = supportedDatasetTypes.map(({ label }) => label).join(', '); -const supportedOptionalExtensions = supportedDatasetTypes.map(({ optional }) => optional || []).flat(); - function getFileNameParts(file) { const { name } = file; const nameParts = name.split('.'); @@ -89,10 +32,10 @@ function getFileNameParts(file) { return { ext, baseName }; } -function getDatasetFileType(file) { +function getDatasetFileType(file, supportedTypes) { const { type } = file; const { ext } = getFileNameParts(file); - const datasetFileType = supportedDatasetTypes.find((fileType) => + const datasetFileType = supportedTypes.find((fileType) => (fileType.ext || []).includes(ext) || (fileType.mimeType || []).includes(type) || (fileType.requires || []).includes(ext) @@ -107,6 +50,15 @@ function UploadList({ children, onSuccess }) { + const { maxParallelUploads, upload: uploadSettings = {} } = getConfigProp('geoNodeSettings') || {}; + + const { supportedDatasetFileTypes: supportedDatasetTypes } = uploadSettings; + + const supportedExtensions = supportedDatasetTypes.map(({ ext }) => ext || []).flat(); + const supportedMimeTypes = supportedDatasetTypes.map(({ mimeType }) => mimeType || []).flat(); + const supportedRequiresExtensions = supportedDatasetTypes.map(({ requires }) => requires || []).flat(); + const supportedLabels = supportedDatasetTypes.map(({ label }) => label).join(', '); + const supportedOptionalExtensions = supportedDatasetTypes.map(({ optional }) => optional || []).flat(); const [waitingUploads, setWaitingUploads] = useState({}); const [readyUploads, setReadyUploads] = useState({}); @@ -146,7 +98,7 @@ function UploadList({ .filter(({ supported }) => supported) .reduce((acc, { file }) => { const { ext, baseName } = getFileNameParts(file); - let type = getDatasetFileType(file); + let type = getDatasetFileType(file, supportedDatasetTypes); if (!type && supportedOptionalExtensions.includes(ext)) { type = checkedFiles.length > 1 ? acc[baseName]?.type : ext; } @@ -250,8 +202,6 @@ function UploadList({ return files.forEach((file) => sources[file].cancel()); }, []); - const { maxParallelUploads } = getConfigProp('geoNodeSettings'); - return (