From a6e6cd07571f684132f2cf91b1a1c8177ccc5573 Mon Sep 17 00:00:00 2001 From: g Date: Mon, 12 Jan 2026 11:13:25 +0000 Subject: [PATCH] Remove widget resizing and edit mode from dashboard Eliminated the ability to resize dashboard widgets by removing colSpan from WidgetConfig, related UI, and logic. Removed edit mode functionality and the EditDashboardButton, simplifying the dashboard layout and widget management. Updated drag-and-drop strategy to vertical list and incremented the storage key version. --- components/dashboard/content.tsx | 30 +++++------------ components/dashboard/dashboard-editor.tsx | 33 ++----------------- components/dashboard/draggable-widget.tsx | 11 +------ .../dashboard/widget-settings-modal.tsx | 27 ++------------- hooks/useWidgetLayout.ts | 25 +++++--------- 5 files changed, 23 insertions(+), 103 deletions(-) diff --git a/components/dashboard/content.tsx b/components/dashboard/content.tsx index 7681540..9f4d906 100644 --- a/components/dashboard/content.tsx +++ b/components/dashboard/content.tsx @@ -6,7 +6,7 @@ import QuickActions from "./quick-actions" import RecentActivity from "./recent-activity" import { WidgetSettings } from "./widget-settings" import { WidgetSettingsModal } from "./widget-settings-modal" -import { DashboardEditor, EditDashboardButton } from "./dashboard-editor" +import { DashboardEditor } from "./dashboard-editor" import { DraggableWidget } from "./draggable-widget" import RevenueWidget from "./revenue-widget" import LowStockWidget from "./low-stock-widget" @@ -46,9 +46,8 @@ export default function Content({ username, orderStats }: ContentProps) { const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const { toast } = useToast(); - const { widgets, toggleWidget, moveWidget, reorderWidgets, resetLayout, isWidgetVisible, updateWidgetSettings, updateWidgetColSpan } = useWidgetLayout(); + const { widgets, toggleWidget, moveWidget, reorderWidgets, resetLayout, isWidgetVisible, updateWidgetSettings } = useWidgetLayout(); const [configuredWidget, setConfiguredWidget] = useState(null); - const [isEditMode, setIsEditMode] = useState(false); // Initialize with a default quote to match server-side rendering, then randomize on client const [randomQuote, setRandomQuote] = useState({ text: "Loading wisdom...", author: "..." }); @@ -232,10 +231,6 @@ export default function Content({ username, orderStats }: ContentProps) {

- setIsEditMode(!isEditMode)} - /> setIsEditMode(false)} + isEditMode={false} + onToggleEditMode={() => { }} onReorder={reorderWidgets} onReset={resetLayout} > -
+
{widgets.map((widget) => { - if (!widget.visible && !isEditMode) return null; + if (!widget.visible) return null; return ( setConfiguredWidget(widget)} onToggleVisibility={() => toggleWidget(widget.id)} > - {!widget.visible && isEditMode ? ( -
- {renderWidget(widget)} -
- ) : ( - renderWidget(widget) - )} + {renderWidget(widget)}
); })} @@ -283,9 +272,8 @@ export default function Content({ username, orderStats }: ContentProps) { widget={configuredWidget} open={!!configuredWidget} onOpenChange={(open) => !open && setConfiguredWidget(null)} - onSave={(widgetId, settings, colSpan) => { + onSave={(widgetId, settings) => { updateWidgetSettings(widgetId, settings); - if (colSpan !== undefined) updateWidgetColSpan(widgetId, colSpan); }} />
diff --git a/components/dashboard/dashboard-editor.tsx b/components/dashboard/dashboard-editor.tsx index bdd6765..063bfe0 100644 --- a/components/dashboard/dashboard-editor.tsx +++ b/components/dashboard/dashboard-editor.tsx @@ -15,7 +15,7 @@ import { import { SortableContext, sortableKeyboardCoordinates, - rectSortingStrategy, + verticalListSortingStrategy, arrayMove, } from "@dnd-kit/sortable" import { Button } from "@/components/ui/button" @@ -81,7 +81,7 @@ export function DashboardEditor({ > w.id)} - strategy={rectSortingStrategy} + strategy={verticalListSortingStrategy} > {children} @@ -126,32 +126,3 @@ export function DashboardEditor({ ) } -// Edit button component to add to the header -export function EditDashboardButton({ - isEditMode, - onToggle -}: { - isEditMode: boolean - onToggle: () => void -}) { - return ( - - ) -} diff --git a/components/dashboard/draggable-widget.tsx b/components/dashboard/draggable-widget.tsx index e4291b5..b404471 100644 --- a/components/dashboard/draggable-widget.tsx +++ b/components/dashboard/draggable-widget.tsx @@ -1,6 +1,6 @@ "use client" -import React from "react" +import React, { useState, useEffect, useRef } from "react" import { useSortable } from "@dnd-kit/sortable" import { CSS } from "@dnd-kit/utilities" import { GripVertical, Settings, X, Eye, EyeOff } from "lucide-react" @@ -41,21 +41,12 @@ export function DraggableWidget({ zIndex: isDragging ? 1000 : 1, } - const colSpanClasses = { - 1: "lg:col-span-1", - 2: "lg:col-span-2", - 3: "lg:col-span-3", - 4: "lg:col-span-4", - }[widget.colSpan || 4] || "lg:col-span-4" - return (
void - onSave: (widgetId: string, settings: Record, colSpan: number) => void + onSave: (widgetId: string, settings: Record) => void } export function WidgetSettingsModal({ widget, open, onOpenChange, onSave }: WidgetSettingsModalProps) { const [localSettings, setLocalSettings] = useState>({}) - const [localColSpan, setLocalColSpan] = useState(4) // Initialize local settings when widget changes const handleOpenChange = (isOpen: boolean) => { if (isOpen && widget) { setLocalSettings({ ...widget.settings }) - setLocalColSpan(widget.colSpan || 4) } onOpenChange(isOpen) } const handleSave = () => { if (widget) { - onSave(widget.id, localSettings, localColSpan) + onSave(widget.id, localSettings) onOpenChange(false) } } @@ -72,27 +70,6 @@ export function WidgetSettingsModal({ widget, open, onOpenChange, onSave }: Widg
- {/* Resize Selection */} -
- -
- - -
-
{/* Recent Activity Settings */} diff --git a/hooks/useWidgetLayout.ts b/hooks/useWidgetLayout.ts index b2b0b22..51be753 100644 --- a/hooks/useWidgetLayout.ts +++ b/hooks/useWidgetLayout.ts @@ -50,22 +50,21 @@ export interface WidgetConfig { title: string visible: boolean order: number - colSpan: number // 1, 2, 3, 4 (full) settings?: Record } const DEFAULT_WIDGETS: WidgetConfig[] = [ - { id: "quick-actions", title: "Quick Actions", visible: true, order: 0, colSpan: 4 }, - { id: "overview", title: "Overview", visible: true, order: 1, colSpan: 4, settings: { showChange: false } }, - { id: "recent-activity", title: "Recent Activity", visible: true, order: 2, colSpan: 2, settings: { itemCount: 10 } }, - { id: "top-products", title: "Top Products", visible: true, order: 3, colSpan: 2, settings: { itemCount: 5, showRevenue: true } }, - { id: "revenue-chart", title: "Revenue Chart", visible: false, order: 4, colSpan: 2, settings: { days: 7, showComparison: false } }, - { id: "low-stock", title: "Low Stock Alerts", visible: false, order: 5, colSpan: 2, settings: { threshold: 5, itemCount: 5 } }, - { id: "recent-customers", title: "Recent Customers", visible: false, order: 6, colSpan: 2, settings: { itemCount: 5, showSpent: true } }, - { id: "pending-chats", title: "Pending Chats", visible: false, order: 7, colSpan: 2, settings: { showPreview: true } }, + { id: "quick-actions", title: "Quick Actions", visible: true, order: 0 }, + { id: "overview", title: "Overview", visible: true, order: 1, settings: { showChange: false } }, + { id: "recent-activity", title: "Recent Activity", visible: true, order: 2, settings: { itemCount: 10 } }, + { id: "top-products", title: "Top Products", visible: true, order: 3, settings: { itemCount: 5, showRevenue: true } }, + { id: "revenue-chart", title: "Revenue Chart", visible: false, order: 4, settings: { days: 7, showComparison: false } }, + { id: "low-stock", title: "Low Stock Alerts", visible: false, order: 5, settings: { threshold: 5, itemCount: 5 } }, + { id: "recent-customers", title: "Recent Customers", visible: false, order: 6, settings: { itemCount: 5, showSpent: true } }, + { id: "pending-chats", title: "Pending Chats", visible: false, order: 7, settings: { showPreview: true } }, ] -const STORAGE_KEY = "dashboard-widget-layout-v3" +const STORAGE_KEY = "dashboard-widget-layout-v4" /** * useWidgetLayout - Persist and manage dashboard widget visibility, order, and settings @@ -140,11 +139,6 @@ export function useWidgetLayout() { ) }, []) - const updateWidgetColSpan = useCallback((widgetId: string, colSpan: number) => { - setWidgets(prev => - prev.map(w => w.id === widgetId ? { ...w, colSpan } : w) - ) - }, []) const getWidgetSettings = useCallback(>(widgetId: string): T | undefined => { return widgets.find(w => w.id === widgetId)?.settings as T | undefined @@ -185,7 +179,6 @@ export function useWidgetLayout() { moveWidget, reorderWidgets, updateWidgetSettings, - updateWidgetColSpan, getWidgetSettings, resetLayout, getVisibleWidgets,