From 45e89ceca91f16418a2e79f37e3a21706cf219cc Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Tue, 10 Sep 2024 16:12:56 +0545 Subject: [PATCH] Adds expand option to buttons --- .../Layout/TrainingDS/DatasetEditor/AOI.js | 229 ++++++++++-------- 1 file changed, 129 insertions(+), 100 deletions(-) diff --git a/frontend/src/components/Layout/TrainingDS/DatasetEditor/AOI.js b/frontend/src/components/Layout/TrainingDS/DatasetEditor/AOI.js index 5b715a8e..c025f405 100644 --- a/frontend/src/components/Layout/TrainingDS/DatasetEditor/AOI.js +++ b/frontend/src/components/Layout/TrainingDS/DatasetEditor/AOI.js @@ -1,4 +1,7 @@ import React, { useContext, useEffect, useState } from "react"; +import { Collapse, Box } from "@mui/material"; +import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; +import ExpandLessIcon from "@mui/icons-material/ExpandLess"; import { Alert, Avatar, @@ -71,7 +74,11 @@ const AOI = (props) => { const [fileError, setFileError] = useState(null); const [geoJsonFile, setGeoJsonFile] = useState(null); const [fetchError, setFetchError] = useState(null); + const [expandedAoi, setExpandedAoi] = useState(null); + const handleExpandClick = (aoiId) => { + setExpandedAoi(expandedAoi === aoiId ? null : aoiId); + }; let _DATA = usePagination( props.mapLayers.filter((e) => e.type === "aoi"), PER_PAGE @@ -414,53 +421,43 @@ const AOI = (props) => { } /> + {/* JOSM Editor Button */} { - try { - const Imgurl = new URL( - "http://127.0.0.1:8111/imagery" - ); - Imgurl.searchParams.set("type", "tms"); - Imgurl.searchParams.set( - "title", - props.oamImagery.name - ); - Imgurl.searchParams.set( - "url", - props.oamImagery.url - ); - const imgResponse = await fetch(Imgurl); - const loadurl = new URL( - "http://127.0.0.1:8111/load_and_zoom" - ); - loadurl.searchParams.set( - "bottom", - layer.latlngs[0].lat - ); - loadurl.searchParams.set( - "top", - layer.latlngs[1].lat - ); - loadurl.searchParams.set( - "left", - layer.latlngs[0].lng - ); - loadurl.searchParams.set( - "right", - layer.latlngs[2].lng - ); - const loadResponse = await fetch(loadurl); - - if (!imgResponse.ok) { - setOpenSnack(true); - } - } catch (error) { - setOpenSnack(true); - } + const Imgurl = new URL( + "http://127.0.0.1:8111/imagery" + ); + Imgurl.searchParams.set("type", "tms"); + Imgurl.searchParams.set( + "title", + props.oamImagery.name + ); + Imgurl.searchParams.set("url", props.oamImagery.url); + const imgResponse = await fetch(Imgurl); + + const loadurl = new URL( + "http://127.0.0.1:8111/load_and_zoom" + ); + loadurl.searchParams.set( + "bottom", + layer.latlngs[0].lat + ); + loadurl.searchParams.set("top", layer.latlngs[1].lat); + loadurl.searchParams.set( + "left", + layer.latlngs[0].lng + ); + loadurl.searchParams.set( + "right", + layer.latlngs[2].lng + ); + await fetch(loadurl); + + if (!imgResponse.ok) setOpenSnack(true); }} > { /> + + {/* ID Editor Button */} { /> + + {/* Fetch OSM Data */} { @@ -506,86 +507,114 @@ const AOI = (props) => { }} > - {/* */} - - - - { - mutateDownload(layer.aoiId); - console.log("Downloading AOI as Geojson"); - }} - > - - - - - - { - mutateDownloadLables(layer.aoiId); - console.log("Downloading AOI Labels as Geojson"); - }} - > - + {/* Zoom to TA */} { const lat = - layer.latlngs.reduce(function ( - accumulator, - curValue - ) { - return accumulator + curValue.lat; - }, - 0) / layer.latlngs.length; + layer.latlngs.reduce( + (accumulator, curValue) => + accumulator + curValue.lat, + 0 + ) / layer.latlngs.length; const lng = - layer.latlngs.reduce(function ( - accumulator, - curValue - ) { - return accumulator + curValue.lng; - }, - 0) / layer.latlngs.length; + layer.latlngs.reduce( + (accumulator, curValue) => + accumulator + curValue.lng, + 0 + ) / layer.latlngs.length; props.selectAOIHandler([lat, lng], 17); }} > - + + {/* Expand More Options */} + { - mutateDeleteAOI(layer.aoiId, layer.id); - }} + className="margin1" + onClick={() => handleExpandClick(layer.aoiId)} > - + {expandedAoi === layer.aoiId ? ( + + ) : ( + + )} - handleFileChange(e, layer.aoiId)} - /> + {/* Collapsible section for more options */} + + + {/* Download AOI */} + + { + mutateDownload(layer.aoiId); + }} + > + + + + + {/* Download Labels */} + + { + mutateDownloadLables(layer.aoiId); + }} + > + + + + + {/* Delete TA */} + + { + mutateDeleteAOI(layer.aoiId, layer.id); + }} + > + + + + + {/* Upload GeoJSON */} + handleFileChange(e, layer.aoiId)} + /> + + ))}