From 92326984b52e9494667eed0d7507547bbd525bf8 Mon Sep 17 00:00:00 2001 From: karanikiotis Date: Tue, 22 Oct 2024 14:20:09 +0300 Subject: [PATCH] Add third dashboard page --- src/api/index.js | 1 + src/components/Sidebar.js | 6 ++ src/index.js | 2 + src/screens/Dashboard2.js | 142 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 src/screens/Dashboard2.js diff --git a/src/api/index.js b/src/api/index.js index 56a81e1..4913b73 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -69,3 +69,4 @@ export const inviteUser = (email) => api.post("user", { email }); export const removeUser = (id) => api.post("user/delete", { id }); export const getUsersData = () => api.get("user"); export const submitUserRole = (userId, role) => api.post("user/role", { id: userId, role }); +export const getData = () => api.get("data"); diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js index 1c9476a..7f708d3 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -94,6 +94,12 @@ const Sidebar = ({ isSmall: sidebarIsSmall }) => { navigate("/dashboard1"); }, }, + { + text: "Dashboard 2", + handler: () => { + navigate("/dashboard2"); + }, + }, ]; return ( diff --git a/src/index.js b/src/index.js index 3039afd..5eb2fe8 100644 --- a/src/index.js +++ b/src/index.js @@ -28,6 +28,7 @@ import Auth from "./screens/Auth.js"; import Users from "./screens/Users.js"; import Dashboard from "./screens/Dashboard.js"; import Dashboard1 from "./screens/Dashboard1.js"; +import Dashboard2 from "./screens/Dashboard2.js"; import { adjustColors, jwt, colorSuggestions } from "./utils/index.js"; import Map from "./components/Map.js"; @@ -100,6 +101,7 @@ const App = () => { } />} /> } />} /> } />} /> + } />} /> } />} /> } /> diff --git a/src/screens/Dashboard2.js b/src/screens/Dashboard2.js new file mode 100644 index 0000000..6e21d8d --- /dev/null +++ b/src/screens/Dashboard2.js @@ -0,0 +1,142 @@ +import { useEffect, useState } from "react"; +import { Grid, Typography } from "@mui/material"; +import Dropdown from "../components/Dropdown.js"; +import Card from "../components/Card.js"; +import Plot from "../components/Plot.js"; + +import { getData } from "../api/index.js"; + +const availableCities = ["Thessaloniki", "Athens", "Patras"]; + +const Dashboard = () => { + const [selectedCity, setSelectedCity] = useState("Thessaloniki"); + const [data, setData] = useState({ localFoodCropProduction: {}, comparisonOfIrrigationWaterVsNeeds: {}, timePlot: {} }); + + useEffect(() => { + getData().then((tempData) => { + const { success, localFoodCropProduction, comparisonOfIrrigationWaterVsNeeds, timePlot } = tempData; + + if (success) { + setData({ localFoodCropProduction, comparisonOfIrrigationWaterVsNeeds, timePlot }); + } + }); + }, [selectedCity]); + + return ( + + + Dashboard + + + + Dashboard Area: + ({ value: city, text: city }))} + value={selectedCity} + onChange={(event) => setSelectedCity(event.target.value)} + /> + + + + + + + + + + + month.etc), + type: "bar", + color: "primary", + title: "ETc", + }, + { + x: ["March", "April", "May", "June", "July", "August"], + y: Object.values(data?.comparisonOfIrrigationWaterVsNeeds).map(month => month.irrigation), + type: "bar", + color: "secondary", + title: "Irrigation", + }, + { + x: ["March", "April", "May", "June", "July", "August"], + y: Object.values(data?.comparisonOfIrrigationWaterVsNeeds).map(month => month.rainfall), + type: "bar", + color: "third", + title: "Rainfall", + }, + ]} + showLegend={true} + displayBar={false} + height="300px" + marginBottom="40" + /> + + + + + i + 1), + y: data?.timePlot?.meteo, + type: "line", + color: "primary", + }, + { + title: "In situ data", + x: Array.from({ length: 20 }, (_, i) => i + 1), + y: data?.timePlot?.inSitu, + type: "line", + color: "secondary", + }, + { + title: "Generated data", + x: Array.from({ length: 20 }, (_, i) => i + 1), + y: data?.timePlot?.generated, + type: "line", + color: "third", + }, + ]} + showLegend={true} + displayBar={false} + height="300px" + marginBottom="40" + /> + + + + + ); +}; + +export default Dashboard;