From 11e2697fbfa8efaea6ba1568314ef47f23a5bee8 Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Mon, 20 Nov 2023 16:24:41 +0545 Subject: [PATCH 1/2] fix (projectDetails): generateMbTilesModal - modal content UI enhancements --- .../src/components/GenerateBasemap.jsx | 246 +++++++++--------- 1 file changed, 129 insertions(+), 117 deletions(-) diff --git a/src/frontend/src/components/GenerateBasemap.jsx b/src/frontend/src/components/GenerateBasemap.jsx index a576d331c7..a569d38239 100644 --- a/src/frontend/src/components/GenerateBasemap.jsx +++ b/src/frontend/src/components/GenerateBasemap.jsx @@ -69,137 +69,149 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI - {/* Output Format Dropdown */} - - - - Select Output Format - - { - setSelectedOutputFormat(e.target.value); - }} - > - {environment.tileOutputFormats?.map((form) => ( - - {form.label} - - ))} - - - + + {/* Output Format Dropdown */} + + + + Select Output Format + + { + setSelectedOutputFormat(e.target.value); + }} + > + {environment.tileOutputFormats?.map((form) => ( + + {form.label} + + ))} + + + - {/* Tile Source Dropdown or TMS URL Input */} - - - - Select Tile Source - - - {environment.baseMapProviders?.map((form) => ( - - {form.label} - - ))} - - {selectedTileSource === 'tms' && ( - + {/* Tile Source Dropdown or TMS URL Input */} + + + + Select Tile Source + + + {environment.baseMapProviders?.map((form) => ( + + {form.label} + + ))} + + + + {selectedTileSource === 'tms' && ( + + - )} - - - - {/* Generate Button */} - - { - // Check if 'tms' is selected and tmsUrl is not empty - if (selectedTileSource === 'tms' && !tmsUrl) { - // Handle error, TMS URL is required - console.log('TMS URL is required'); - return; - } + + )} + +
+ {/* Generate Button */} +
+ { + // Check if 'tms' is selected and tmsUrl is not empty + if (selectedTileSource === 'tms' && !tmsUrl) { + // Handle error, TMS URL is required + console.log('TMS URL is required'); + return; + } - dispatch( - GenerateProjectTiles( - `${ - import.meta.env.VITE_API_URL - }/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`, - decodedId, - ), - ); - }} - > - Generate - - + dispatch( + GenerateProjectTiles( + `${ + import.meta.env.VITE_API_URL + }/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`, + decodedId, + ), + ); + }} + > + Generate + +
- {/* Refresh Button */} - - { - getTilesList(); - }} - > - Refresh - + {/* Refresh Button */} +
+ { + getTilesList(); + }} + > + Refresh + +
+
+
{/* Table Content */} From 1663e79bc8cbe47cad4300c474b32d76644eabfd Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Mon, 20 Nov 2023 16:55:08 +0545 Subject: [PATCH 2/2] feat (projectDetails): generateProjectTiles - validations added when generating projectTiles --- .../src/components/GenerateBasemap.jsx | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/frontend/src/components/GenerateBasemap.jsx b/src/frontend/src/components/GenerateBasemap.jsx index a569d38239..d1091de09b 100644 --- a/src/frontend/src/components/GenerateBasemap.jsx +++ b/src/frontend/src/components/GenerateBasemap.jsx @@ -15,6 +15,7 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI const [selectedTileSource, setSelectedTileSource] = useState(null); const [selectedOutputFormat, setSelectedOutputFormat] = useState(null); const [tmsUrl, setTmsUrl] = useState(''); + const [error, setError] = useState([]); const modalStyle = (theme) => ({ width: '90vw', // Responsive modal width using vw @@ -51,6 +52,35 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI setTmsUrl(e.target.value); }; + const generateProjectTilesValidation = () => { + const currentError = []; + if (!selectedTileSource) { + currentError.push('selectedTileSource'); + } + if (!selectedOutputFormat) { + currentError.push('selectedOutputFormat'); + } + if (!tmsUrl && selectedTileSource === 'tms') { + currentError.push('tmsUrl'); + } + setError(currentError); + return currentError; + }; + + const generateProjectTiles = () => { + const currentErrors = generateProjectTilesValidation(); + if (currentErrors.length === 0) { + dispatch( + GenerateProjectTiles( + `${ + import.meta.env.VITE_API_URL + }/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`, + decodedId, + ), + ); + } + }; + return ( + {error.includes('selectedOutputFormat') && ( +

Output Format is Required.

+ )} {/* Tile Source Dropdown or TMS URL Input */} @@ -140,6 +173,9 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI ))} + {error.includes('selectedTileSource') && ( +

Tile Source is Required.

+ )} {selectedTileSource === 'tms' && ( @@ -165,6 +201,7 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI onChange={handleTmsUrlChange} /> + {error.includes('tmsUrl') &&

Tile Source is Required.

}
)} @@ -175,23 +212,7 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI variant="contained" loading={generateProjectTilesLoading} color="error" - onClick={() => { - // Check if 'tms' is selected and tmsUrl is not empty - if (selectedTileSource === 'tms' && !tmsUrl) { - // Handle error, TMS URL is required - console.log('TMS URL is required'); - return; - } - - dispatch( - GenerateProjectTiles( - `${ - import.meta.env.VITE_API_URL - }/projects/tiles/${decodedId}?source=${selectedTileSource}&format=${selectedOutputFormat}&tms=${tmsUrl}`, - decodedId, - ), - ); - }} + onClick={() => generateProjectTiles()} > Generate