From 416873fc08e2e9715bf8d15cd0c9c2bc884ce949 Mon Sep 17 00:00:00 2001 From: "Daniel S. Hansen" Date: Tue, 29 Jul 2025 09:59:17 -0700 Subject: [PATCH 1/4] Save point, page is rendering with view tracking --- .../src/components/layout/Canvas/Canvas.jsx | 6 +++-- .../layout/Canvas/views/DashboardCanvas.jsx | 13 +++++++--- client/src/components/layout/Dashboard.jsx | 5 +++- .../src/components/layout/Sidebar/Sidebar.jsx | 26 ++++++++++++++++--- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/client/src/components/layout/Canvas/Canvas.jsx b/client/src/components/layout/Canvas/Canvas.jsx index 3067854..e097f28 100644 --- a/client/src/components/layout/Canvas/Canvas.jsx +++ b/client/src/components/layout/Canvas/Canvas.jsx @@ -9,14 +9,16 @@ import VolcanoCanvas from "./views/VolcanoCanvas"; import AdminCanvas from "./views/AdminCanvas"; import { DashboardCanvas } from "./views/DashboardCanvas"; -export default function Canvas({ view, layout, setLayout, onLayoutChange }) { +export default function Canvas({ view, setView, layout, setLayout, onLayoutChange }) { const recipe = useRecipe({ key: "canvas" }); const styles = recipe(); return ( {view === "widget" && - + - + My Dashboard @@ -131,7 +136,7 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) { {/* CANVAS */} - + - + setLayout( newLayout )} diff --git a/client/src/components/layout/Sidebar/Sidebar.jsx b/client/src/components/layout/Sidebar/Sidebar.jsx index 1db12b9..6c8ca8d 100644 --- a/client/src/components/layout/Sidebar/Sidebar.jsx +++ b/client/src/components/layout/Sidebar/Sidebar.jsx @@ -7,9 +7,10 @@ import { FaGlobeAmericas } from "react-icons/fa"; import { FaMapMarkerAlt } from "react-icons/fa"; import { HiUsers } from "react-icons/hi2"; import { VscThreeBars } from "react-icons/vsc"; -import { useState } from "react"; +import { useState, useEffect } from "react"; +import { Seismic } from "../Canvas/views/DashboardCanvasNav/Seismic"; -export default function Sidebar({ onChangeView }) { +export default function Sidebar({ view, onChangeView }) { const [isOpen, setIsOpen] = useState(true); const [activeButton, setActiveButton] = useState(0) @@ -30,6 +31,25 @@ export default function Sidebar({ onChangeView }) { else setIsOpen(true); }; + // Track currrent view from both Sidebar and Canvas when 'view' changes + useEffect(() => { + console.log("Current view = ", view); + const dashboardViews = ["widget", "gas", "seismic", "remote", "activity"]; + + const newIndex = buttons.findIndex((btn) => { + if (btn.view === "widget") { + return dashboardViews.includes(view); // Group match + } + return btn.view === view; // Exact match + }); + + if (newIndex !== -1 ) { + setActiveButton(newIndex); + } + }, [view]); + + + return ( { - setActiveButton(idx); + // setActiveButton(idx); onChangeView(button.view); // Trigger state change in Dashboard }} bg={activeButton === idx ? "primary":undefined} From 89c32e4f6ecfd5ba3ef0da9a5758fbe9c9ed6ef5 Mon Sep 17 00:00:00 2001 From: "Daniel S. Hansen" Date: Tue, 29 Jul 2025 11:04:29 -0700 Subject: [PATCH 2/4] Add keyViews.js file inside src/constants to track current view in Sidebar and Canvas --- client/src/components/layout/Canvas/Canvas.jsx | 7 +++++-- .../layout/Canvas/views/DashboardCanvas.jsx | 14 ++++++++------ client/src/components/layout/Sidebar/Sidebar.jsx | 8 ++++---- client/src/constants/viewKeys.js | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 client/src/constants/viewKeys.js diff --git a/client/src/components/layout/Canvas/Canvas.jsx b/client/src/components/layout/Canvas/Canvas.jsx index e097f28..9280c4b 100644 --- a/client/src/components/layout/Canvas/Canvas.jsx +++ b/client/src/components/layout/Canvas/Canvas.jsx @@ -8,6 +8,7 @@ import RegionalMapCanvas from "./views/RegionalMapCanvas"; import VolcanoCanvas from "./views/VolcanoCanvas"; import AdminCanvas from "./views/AdminCanvas"; import { DashboardCanvas } from "./views/DashboardCanvas"; +import { DASHBOARD_VIEWS } from "@/constants/viewKeys"; export default function Canvas({ view, setView, layout, setLayout, onLayoutChange }) { const recipe = useRecipe({ key: "canvas" }); @@ -15,14 +16,16 @@ export default function Canvas({ view, setView, layout, setLayout, onLayoutChang return ( - {view === "widget" && + {/* {view === "widget" && */} + { DASHBOARD_VIEWS.includes(view) && ( } + /> + )} {view === "global" && } {view === "regional" && } {view === "volcano" && } diff --git a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx index 239d2bd..1b5a3a0 100644 --- a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx +++ b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx @@ -83,9 +83,11 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan /* HEADER */ setView(e.value)} + // onValueChange={(value) => setView(value)} > Seismic - + Remote Sensing - + Daily Activity @@ -151,10 +153,10 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan - + - + diff --git a/client/src/components/layout/Sidebar/Sidebar.jsx b/client/src/components/layout/Sidebar/Sidebar.jsx index 6c8ca8d..3ff8794 100644 --- a/client/src/components/layout/Sidebar/Sidebar.jsx +++ b/client/src/components/layout/Sidebar/Sidebar.jsx @@ -9,6 +9,7 @@ import { HiUsers } from "react-icons/hi2"; import { VscThreeBars } from "react-icons/vsc"; import { useState, useEffect } from "react"; import { Seismic } from "../Canvas/views/DashboardCanvasNav/Seismic"; +import { DASHBOARD_VIEWS } from "@/constants/viewKeys"; export default function Sidebar({ view, onChangeView }) { const [isOpen, setIsOpen] = useState(true); @@ -33,12 +34,13 @@ export default function Sidebar({ view, onChangeView }) { // Track currrent view from both Sidebar and Canvas when 'view' changes useEffect(() => { + console.log("typeof view =", typeof view); console.log("Current view = ", view); - const dashboardViews = ["widget", "gas", "seismic", "remote", "activity"]; + // const dashboardViews = ["widget", "gas", "seismic", "remote", "daily"]; const newIndex = buttons.findIndex((btn) => { if (btn.view === "widget") { - return dashboardViews.includes(view); // Group match + return DASHBOARD_VIEWS.includes(view); // Group match } return btn.view === view; // Exact match }); @@ -47,8 +49,6 @@ export default function Sidebar({ view, onChangeView }) { setActiveButton(newIndex); } }, [view]); - - return ( Date: Tue, 29 Jul 2025 11:51:33 -0700 Subject: [PATCH 3/4] Add tab navigation prevention while in Editable mode --- client/src/components/layout/Canvas/Canvas.jsx | 2 +- .../layout/Canvas/views/DashboardCanvas.jsx | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client/src/components/layout/Canvas/Canvas.jsx b/client/src/components/layout/Canvas/Canvas.jsx index 9280c4b..d94300e 100644 --- a/client/src/components/layout/Canvas/Canvas.jsx +++ b/client/src/components/layout/Canvas/Canvas.jsx @@ -16,7 +16,7 @@ export default function Canvas({ view, setView, layout, setLayout, onLayoutChang return ( - {/* {view === "widget" && */} + {/* Check if view is a tab inside the Canvas Header */} { DASHBOARD_VIEWS.includes(view) && ( setView(e.value)} // onValueChange={(value) => setView(value)} + // onValueChange={(e) => setView(e.value)} + onValueChange={(e) => { + const nextView = e.value; + + if (view === "widget" && isEditable && nextView !== "widget") { + const confirmed = window.confirm( + "You have unsaved changes. Do you wish to discard them and continue?" + ); + if (!confirmed) return; + onCancel(); + } + setView(nextView); + }} > Date: Tue, 29 Jul 2025 12:08:36 -0700 Subject: [PATCH 4/4] Remove garbage comments --- .../src/components/layout/Canvas/views/DashboardCanvas.jsx | 6 ++---- client/src/components/layout/Sidebar/Sidebar.jsx | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx index 70386aa..25effed 100644 --- a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx +++ b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx @@ -83,11 +83,9 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan /* HEADER */ setView(value)} - // onValueChange={(e) => setView(e.value)} + + // Prevent navigation away from 'My Dashboard' while in Edit mode onValueChange={(e) => { const nextView = e.value; diff --git a/client/src/components/layout/Sidebar/Sidebar.jsx b/client/src/components/layout/Sidebar/Sidebar.jsx index 3ff8794..f527395 100644 --- a/client/src/components/layout/Sidebar/Sidebar.jsx +++ b/client/src/components/layout/Sidebar/Sidebar.jsx @@ -70,10 +70,10 @@ export default function Sidebar({ view, onChangeView }) { const Icon = button.icon; const buttonElement = ( ); - // console.log("buttonElement is:", buttonElement) console.log("Returning:", !isOpen ? "Tooltip" : "Button", buttonElement); return !isOpen ? (