diff --git a/client/src/components/layout/Canvas/components/CancelButton.jsx b/client/src/components/layout/Canvas/components/CancelButton.jsx
new file mode 100644
index 0000000..28b68a7
--- /dev/null
+++ b/client/src/components/layout/Canvas/components/CancelButton.jsx
@@ -0,0 +1,7 @@
+import { Button } from "@chakra-ui/react";
+
+export function CancelButton ({onCancel}) {
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/client/src/components/layout/Canvas/components/SaveButton.jsx b/client/src/components/layout/Canvas/components/SaveButton.jsx
new file mode 100644
index 0000000..19365f0
--- /dev/null
+++ b/client/src/components/layout/Canvas/components/SaveButton.jsx
@@ -0,0 +1,7 @@
+import { Button } from "@chakra-ui/react";
+
+export function SaveButton ({onSave}) {
+ return (
+
+ )
+}
\ No newline at end of file
diff --git a/client/src/components/layout/Canvas/components/Widget.jsx b/client/src/components/layout/Canvas/components/Widget.jsx
index 6b723ea..0f6e9ea 100644
--- a/client/src/components/layout/Canvas/components/Widget.jsx
+++ b/client/src/components/layout/Canvas/components/Widget.jsx
@@ -1,13 +1,26 @@
-import { useSlotRecipe, chakra } from "@chakra-ui/react"
+import { useSlotRecipe, chakra, Flex, CloseButton, Text } from "@chakra-ui/react"
-export default function Widget({ title }) {
+export default function Widget({ id, title, isEditable, isDelete, DeleteWidget }) {
+ console.log("rendering widget");
const recipe = useSlotRecipe({ key: "widget" });
const styles = recipe();
return (
<>
-
- {title}
+ {console.log("This widgets id is: ", id)}
+
+ {isDelete ? (
+ <>
+
+ {title}
+ DeleteWidget(id)} size="xs" _hover={{bg: "tomato", color: "white"}}/>
+
+ >
+ ):(
+ <>
+ {title}
+ >
+ )}
This is their widget content - drag or resize me!
diff --git a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx
index 549584e..8678a50 100644
--- a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx
+++ b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx
@@ -6,22 +6,16 @@ import { DailyActivity } from "./DashboardCanvasNav/DailyActivity";
import { Gas } from "./DashboardCanvasNav/Gas";
import { Seismic } from "./DashboardCanvasNav/Seismic";
import { RemoteSensing } from "./DashboardCanvasNav/RemoteSensing";
-import { useState, useEffect } from "react";
+import { useState, useEffect, useDebugValue } from "react";
+import { CancelButton } from "../components/CancelButton";
+import { SaveButton } from "../components/SaveButton";
export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
const [isEditable, setIsEditable] = useState(false); // editable=true means static=false (vice versa)
+ const [isDelete, setIsDelete] = useState(false);
const [newCounter, setNewCounter] = useState(3);
const [originalLayout, setOriginalLayout] = useState([]);
- useEffect(() => {
- setLayout(prevLayout =>
- prevLayout.map(item => ({
- ...item,
- static: !isEditable // static false means resizable/editable
- }))
- );
- }, [isEditable]);
-
const onAddWidget = () => {
const newId = newCounter.toString();
setLayout(prev => [
@@ -37,6 +31,16 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
setNewCounter(prev => prev + 1);
};
+ useEffect(() => {
+ console.log("static change effect");
+ setLayout(prevLayout =>
+ prevLayout.map(item => ({
+ ...item,
+ static: !isEditable // static false means resizable/editable
+ }))
+ );
+ }, [isEditable]);
+
const onEditWidgets = () => {
console.log("widgets are now editable");
setOriginalLayout(layout); // Backup layout before editing
@@ -44,23 +48,35 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
}
const onSave = () => {
- setOriginalLayout([]) // Clear backup layout
+ console.log("saving widgets...");
setIsEditable(false);
+ setIsDelete(false);
+ setOriginalLayout([]) // Clear backup layout
}
const onCancel = () => {
+ console.log("canceling changes...");
if (originalLayout.length) {
setLayout(originalLayout.map(item => ({
...item,
static: true
})));
};
- setOriginalLayout([]);
setIsEditable(false);
+ setIsDelete(false);
+ setOriginalLayout([]);
}
- const onDeleteWidgets = (id) => {
- setLayout(prev => prev.filter(w => w.i !== id));
+ const onDeleteWidgets = () => {
+ console.log("Start deleting widgets...");
+ setOriginalLayout(layout);
+ setIsEditable(true);
+ setIsDelete(true);
+ }
+
+ const DeleteWidget = (id) => {
+ console.log("Deleting widget with id: ", id);
+ setLayout(layout => layout.filter(w => w.i !== id));
}
return (
@@ -96,10 +112,10 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
- {isEditable ? (
+ {isEditable || isDelete ? (
<>
-
-
+
+
>
):(
<>
@@ -119,6 +135,9 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
diff --git a/client/src/components/layout/Canvas/views/DashboardCanvasNav/WidgetCanvas.jsx b/client/src/components/layout/Canvas/views/DashboardCanvasNav/WidgetCanvas.jsx
index 523fc04..589979d 100644
--- a/client/src/components/layout/Canvas/views/DashboardCanvasNav/WidgetCanvas.jsx
+++ b/client/src/components/layout/Canvas/views/DashboardCanvasNav/WidgetCanvas.jsx
@@ -7,7 +7,8 @@ import GridLayout, { WidthProvider } from 'react-grid-layout';
import Widget from '../../components/Widget.jsx';
import { useSlotRecipe, chakra, Flex } from '@chakra-ui/react';
-export default function WidgetCanvas({layout, onLayoutChange}) {
+export default function WidgetCanvas({layout, onLayoutChange, isEditable, isDelete, DeleteWidget}) {
+ console.log("rendering widgetcanvas");
// Define widgets initial position and size
// TODO Add dynamic adding/deleting of widgets via options button
const recipe = useSlotRecipe({ key: "widget" });
@@ -24,26 +25,26 @@ export default function WidgetCanvas({layout, onLayoutChange}) {
};
return (
-
-
- {layout.map((item) => (
- // this flex wrapper allows the widget to shrink down to the header size, no less
-
-
-
- ))}
-
-
- );
+
+
+ {layout.map((item) => (
+ // this flex wrapper allows the widget to shrink down to the header size, no less
+
+
+
+ ))}
+
+
+ );
}
diff --git a/client/src/theme.js b/client/src/theme.js
index a7746a9..879a494 100644
--- a/client/src/theme.js
+++ b/client/src/theme.js
@@ -70,7 +70,9 @@ const widgetRecipe = defineSlotRecipe({
bg: "base200",
cursor: "move",
borderRadius: "sm",
- whiteSpace: "nowrap"
+ whiteSpace: "nowrap",
+ textAlign: "left",
+ pl: "2"
},
canvas: {
flex: "1 1 auto",