Merge branch 'main' into 'dashboardCanvas/Widget/add-widgets-menu'
# Conflicts: # client/src/components/layout/Canvas/views/DashboardCanvas.jsx
This commit is contained in:
@@ -29,42 +29,37 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan
|
||||
static: false
|
||||
}
|
||||
]);
|
||||
onEditWidgets();
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
// Set all widgets to editable, static: false
|
||||
setLayout(prevLayout =>
|
||||
prevLayout.map(item => ({
|
||||
...item,
|
||||
static: false
|
||||
}))
|
||||
);
|
||||
setIsEditable(true); // Enable edit mode
|
||||
}
|
||||
|
||||
const onSave = () => {
|
||||
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,
|
||||
// Set all widgets back to static: true
|
||||
setLayout(prevLayout =>
|
||||
prevLayout.map(item => ({
|
||||
...item,
|
||||
static: true
|
||||
})));
|
||||
};
|
||||
}))
|
||||
);
|
||||
|
||||
setIsEditable(false);
|
||||
setIsDelete(false);
|
||||
setOriginalLayout([]);
|
||||
setOriginalLayout([]); // Clear backup layout
|
||||
}
|
||||
|
||||
const onDeleteWidgets = () => {
|
||||
@@ -101,15 +96,7 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan
|
||||
// Prevent navigation away from 'My Dashboard' while in Edit mode
|
||||
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);
|
||||
onChangeView(nextView);
|
||||
}}
|
||||
>
|
||||
<Flex
|
||||
|
||||
Reference in New Issue
Block a user