From 7726c32d3e6de0cc505dd2a240c679f51120832a Mon Sep 17 00:00:00 2001 From: mseng10 Date: Sun, 14 Jul 2024 20:48:21 -0500 Subject: [PATCH] MISC: Misc cleanup --- client/react/src/App.js | 5 ++-- client/react/src/elements/{page => }/Page.js | 0 client/react/src/forms/create/NewGenusForm.js | 2 -- client/react/src/forms/create/NewLightForm.js | 12 +++++++--- client/react/src/forms/create/NewPlantForm.js | 1 + client/react/src/models/System.js | 10 ++++---- client/react/src/navigation/AppNavigation.js | 2 -- client/react/src/navigation/CreateOptions.js | 24 +++++++++---------- client/react/src/navigation/ViewOptions.js | 10 ++++---- client/react/src/pages/Alerts.js | 4 ++-- client/react/src/pages/Home.js | 17 +------------ client/react/src/pages/Plants.js | 18 +++++++++++++- client/react/src/pages/Todos.js | 2 +- server/app.py | 1 - 14 files changed, 53 insertions(+), 55 deletions(-) rename client/react/src/elements/{page => }/Page.js (100%) diff --git a/client/react/src/App.js b/client/react/src/App.js index 40f3de9..0ff515d 100644 --- a/client/react/src/App.js +++ b/client/react/src/App.js @@ -23,7 +23,6 @@ import NewTodoForm from './forms/create/NewTodoForm'; import NewTypeForm from './forms/create/NewTypeForm'; import NewLightForm from './forms/create/NewLightForm'; import NewGenusForm from './forms/create/NewGenusForm'; -import Page from './elements/page/Page'; const drawerWidth = 240; @@ -83,11 +82,11 @@ function App() { } /> } /> - } /> + } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/client/react/src/elements/page/Page.js b/client/react/src/elements/Page.js similarity index 100% rename from client/react/src/elements/page/Page.js rename to client/react/src/elements/Page.js diff --git a/client/react/src/forms/create/NewGenusForm.js b/client/react/src/forms/create/NewGenusForm.js index c92ea8e..eff4abd 100644 --- a/client/react/src/forms/create/NewGenusForm.js +++ b/client/react/src/forms/create/NewGenusForm.js @@ -101,5 +101,3 @@ const NewGenusForm = () => { }; export default NewGenusForm; - - diff --git a/client/react/src/forms/create/NewLightForm.js b/client/react/src/forms/create/NewLightForm.js index 11160bb..cbb8688 100644 --- a/client/react/src/forms/create/NewLightForm.js +++ b/client/react/src/forms/create/NewLightForm.js @@ -9,20 +9,22 @@ import Autocomplete from '@mui/material/Autocomplete'; import TungstenSharpIcon from '@mui/icons-material/TungstenSharp'; import {useNavigate} from "react-router-dom" - +// Form to create a light that is potentially used on a system. const NewLightForm = ({ systems }) => { + // Fields const [name, setName] = useState(''); const [system, setSystem] = useState(null); const [cost, setCost] = useState(0); - const [allSystems, setAllSystems] = useState([]); - + // Submitted state const [submitted, setSubmitted] = useState(false); // Navigation const navigate = useNavigate(); + // Available systems + const [allSystems, setAllSystems] = useState([]); useEffect(() => { if (!systems) { fetch('http://127.0.0.1:5000/system') @@ -32,6 +34,7 @@ const NewLightForm = ({ systems }) => { } }, [systems]); + // POST useEffect(() => { if (submitted) { const requestOptions = { @@ -52,16 +55,19 @@ const NewLightForm = ({ systems }) => { } }, [submitted, name, cost, system]); + // Initiate POST const handleSubmit = (event) => { event.preventDefault(); setSubmitted(true); // Update submitted state }; + // Exit const handleCancel = () => { clearForm(); navigate("/create"); }; + // Clear Form Fields const clearForm = () => { setName(''); setCost(0); diff --git a/client/react/src/forms/create/NewPlantForm.js b/client/react/src/forms/create/NewPlantForm.js index da6cafc..f7a1b9e 100644 --- a/client/react/src/forms/create/NewPlantForm.js +++ b/client/react/src/forms/create/NewPlantForm.js @@ -10,6 +10,7 @@ import Autocomplete from '@mui/material/Autocomplete'; import MenuItem from '@mui/material/MenuItem'; import {useNavigate} from "react-router-dom" +// Creating Plant Form const NewPlantForm = () => { const phases = ["cutting", "seed", "juvy", "adult"] diff --git a/client/react/src/models/System.js b/client/react/src/models/System.js index ce21579..1956a25 100644 --- a/client/react/src/models/System.js +++ b/client/react/src/models/System.js @@ -58,8 +58,8 @@ const System = ({ system, full }) => { - + + } title={system.name} @@ -67,7 +67,7 @@ const System = ({ system, full }) => { /> - + { /> - + { /> - + {currentNavigation === NAVS.CREATE && ( setCurrentNavigation(null)} /> )} {currentNavigation === NAVS.VIEW && ( setCurrentNavigation(null)} /> )} diff --git a/client/react/src/navigation/CreateOptions.js b/client/react/src/navigation/CreateOptions.js index c20244e..acccaba 100644 --- a/client/react/src/navigation/CreateOptions.js +++ b/client/react/src/navigation/CreateOptions.js @@ -29,45 +29,43 @@ const CreateOptions = () => {
- + navigate("/plant/create")}> - + - + navigate("/type/create")}> - + - + navigate("/genus/create")}> - + - + navigate("/system/create")}> - + - + navigate("/light/create")}> - + @@ -75,7 +73,7 @@ const CreateOptions = () => { navigate("/todo/create")}> - + diff --git a/client/react/src/navigation/ViewOptions.js b/client/react/src/navigation/ViewOptions.js index 45e3fc0..69dc35a 100644 --- a/client/react/src/navigation/ViewOptions.js +++ b/client/react/src/navigation/ViewOptions.js @@ -21,13 +21,11 @@ const ViewOptions = () => {
- - + + navigate("/plant/view")}> - + @@ -35,7 +33,7 @@ const ViewOptions = () => { navigate("/system/view")}> - + diff --git a/client/react/src/pages/Alerts.js b/client/react/src/pages/Alerts.js index 334a64a..ec281da 100644 --- a/client/react/src/pages/Alerts.js +++ b/client/react/src/pages/Alerts.js @@ -8,7 +8,7 @@ import { CardActionArea, CardHeader } from '@mui/material'; import Avatar from '@mui/material/Avatar'; import IconButton from '@mui/material/IconButton'; import CardActions from '@mui/material/CardActions'; -import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered'; +import ReportGmailerrorredSharpIcon from '@mui/icons-material/ReportGmailerrorredSharp'; // import Typography from '@mui/material/Typography'; import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; @@ -65,7 +65,7 @@ const Alerts = () => { - + } title={plantAlert.alert_type} diff --git a/client/react/src/pages/Home.js b/client/react/src/pages/Home.js index 5024389..336d975 100644 --- a/client/react/src/pages/Home.js +++ b/client/react/src/pages/Home.js @@ -1,7 +1,6 @@ // Home.js import GrassOutlinedIcon from '@mui/icons-material/GrassOutlined'; -import System from '../models/System' -import React, { useState, useEffect } from 'react'; +import React from 'react'; import IconButton from '@mui/material/IconButton'; import {useNavigate} from "react-router-dom" @@ -9,25 +8,11 @@ const Home = () => { // Navigation const navigate = useNavigate(); - // Passable Data - const [systems, setSystems] = useState([]); - - useEffect(() => { - // Fetch system data from the server - fetch('http://localhost:5000/systems') - .then((response) => response.json()) - .then((data) => setSystems(data)) - .catch(() => console.log("Oh no")); - }, []); - return ( <>
-
{ navigate("/plant/view")}}> diff --git a/client/react/src/pages/Plants.js b/client/react/src/pages/Plants.js index 167e54d..9a7ecf8 100644 --- a/client/react/src/pages/Plants.js +++ b/client/react/src/pages/Plants.js @@ -18,6 +18,13 @@ import { DataGrid,GridToolbarContainer, GridToolbarDensitySelector, } from '@mui/x-data-grid'; import Box from '@mui/material/Box'; +const phasesToLabels = { + "cutting": "Cutting", + "seed": "Seed", + "juvy": "Juvy", + "adult": "Adult", +} + const Plants = () => { const [plants, setPlants] = useState([]); @@ -25,6 +32,7 @@ const Plants = () => { const [systems, setSystems] = useState([]); const [types, setTypes] = useState([]); + // Grid Columns for plants const columns = [ { field: 'type_id', @@ -105,10 +113,16 @@ const Plants = () => { { field: 'phase', headerName: 'Phase', - width: 60, + width: 120, + valueGetter: (value) => { + const label = phasesToLabels[value.value]; + + return label ? label : "NaN"; + } }, ]; + // Form Openers const [isUpdatePlantFormOpen, setIsUpdatePlantFormOpen] = useState(false); const [isWaterPlantsFormOpen, setIsWaterPlantsFormOpen] = useState(false); const [isKillPlantsFormOpen, setIsKillPlantsFormOpen] = useState(false); @@ -117,6 +131,7 @@ const Plants = () => { const [selectedPlants, setSelectedPlants] = useState([]); + // Grid Toolbar function CustomToolbar() { return ( @@ -161,6 +176,7 @@ const Plants = () => { ); } + // Data useEffect(() => { // TODO: Merge plants, genus, type to same model // Fetch plant data from the server diff --git a/client/react/src/pages/Todos.js b/client/react/src/pages/Todos.js index cc43f33..c1d8387 100644 --- a/client/react/src/pages/Todos.js +++ b/client/react/src/pages/Todos.js @@ -64,7 +64,7 @@ const Todos = () => { - + } title={todo.name} diff --git a/server/app.py b/server/app.py index b51e944..76e53d5 100644 --- a/server/app.py +++ b/server/app.py @@ -130,7 +130,6 @@ def kill_plants(): return jsonify({"message": f"{len(plants)} Plants killed successfully:("}), 201 - @app.route("/genus", methods=["GET"]) def get_genuses(): """