Add hover-reveal edit button to widget cards + auto-open edit mode
Each widget card now shows a settings icon in the top-right corner on hover (desktop) or always-visible (mobile via mobile-touch-target). Clicking it opens the WidgetConfigDialog directly in edit mode for that widget (via a new editWidgetId prop on WidgetConfigDialog that auto-enters the draft-edit path via useEffect). Wired across all three widget surfaces: - Dashboard (both mobile section + desktop grid) - Service OverviewTab - NamedDashboardPage 128 tests pass; build/lint green.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -56,6 +56,8 @@ interface Props {
|
|||||||
serviceId?: string;
|
serviceId?: string;
|
||||||
/** When set, enable widget references ("Add existing") for this dashboard scope. */
|
/** When set, enable widget references ("Add existing") for this dashboard scope. */
|
||||||
dashboardScope?: string;
|
dashboardScope?: string;
|
||||||
|
/** When set, auto-open in edit mode for this widget id (instead of the list view). */
|
||||||
|
editWidgetId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Draft {
|
interface Draft {
|
||||||
@@ -203,6 +205,7 @@ export function WidgetConfigDialog({
|
|||||||
onClose,
|
onClose,
|
||||||
serviceId,
|
serviceId,
|
||||||
dashboardScope,
|
dashboardScope,
|
||||||
|
editWidgetId,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { data: instances = [] } = useWidgetInstances(serviceId);
|
const { data: instances = [] } = useWidgetInstances(serviceId);
|
||||||
const { data: services = [] } = useServiceInstances();
|
const { data: services = [] } = useServiceInstances();
|
||||||
@@ -220,6 +223,18 @@ export function WidgetConfigDialog({
|
|||||||
|
|
||||||
const [draft, setDraft] = useState<Draft | null>(null);
|
const [draft, setDraft] = useState<Draft | null>(null);
|
||||||
|
|
||||||
|
// When editWidgetId is set and the dialog opens, auto-enter edit mode for
|
||||||
|
// that widget (instead of showing the list view).
|
||||||
|
useEffect(() => {
|
||||||
|
if (open && editWidgetId && instances.length > 0) {
|
||||||
|
const target = instances.find((w) => w.id === editWidgetId);
|
||||||
|
if (target) {
|
||||||
|
startEdit(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [open, editWidgetId, instances]);
|
||||||
|
|
||||||
function startAddBuiltIn(kind: string) {
|
function startAddBuiltIn(kind: string) {
|
||||||
const binding = BUILTIN_WIDGETS[kind];
|
const binding = BUILTIN_WIDGETS[kind];
|
||||||
setDraft({
|
setDraft({
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Settings2 } from "lucide-react";
|
||||||
import { useServiceInstances } from "../hooks/useServices";
|
import { useServiceInstances } from "../hooks/useServices";
|
||||||
import { resolveWidget } from "../integrations/registry";
|
import { resolveWidget } from "../integrations/registry";
|
||||||
import type { WidgetInstance } from "../types";
|
import type { WidgetInstance } from "../types";
|
||||||
@@ -6,9 +8,11 @@ import { SectionCard } from "./SectionCard";
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
widget: WidgetInstance;
|
widget: WidgetInstance;
|
||||||
|
/** When provided, a hover-reveal edit button appears in the top-right corner. */
|
||||||
|
onEdit?: (widgetId: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WidgetInstanceCard({ widget }: Props) {
|
export function WidgetInstanceCard({ widget, onEdit }: Props) {
|
||||||
const { data: services = [] } = useServiceInstances();
|
const { data: services = [] } = useServiceInstances();
|
||||||
const resolved = resolveWidget(widget, services);
|
const resolved = resolveWidget(widget, services);
|
||||||
|
|
||||||
@@ -17,20 +21,46 @@ export function WidgetInstanceCard({ widget }: Props) {
|
|||||||
? `Unknown widget: ${widget.widget_kind} (service-bound)`
|
? `Unknown widget: ${widget.widget_kind} (service-bound)`
|
||||||
: `Unknown widget: ${widget.widget_kind} (built-in)`;
|
: `Unknown widget: ${widget.widget_kind} (built-in)`;
|
||||||
return (
|
return (
|
||||||
<SectionCard title={widget.title}>
|
<div className="group relative">
|
||||||
<Alert>
|
{onEdit ? (
|
||||||
<AlertDescription>{label}</AlertDescription>
|
<Button
|
||||||
</Alert>
|
variant="ghost"
|
||||||
</SectionCard>
|
size="icon-sm"
|
||||||
|
className="absolute right-2 top-2 z-10 opacity-0 transition-opacity group-hover:opacity-100 mobile-touch-target"
|
||||||
|
onClick={() => onEdit(widget.id)}
|
||||||
|
aria-label="Edit widget"
|
||||||
|
>
|
||||||
|
<Settings2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
<SectionCard title={widget.title}>
|
||||||
|
<Alert>
|
||||||
|
<AlertDescription>{label}</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
</SectionCard>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Component = resolved.component;
|
const Component = resolved.component;
|
||||||
return (
|
return (
|
||||||
<Component
|
<div className="group relative">
|
||||||
widget={widget}
|
{onEdit ? (
|
||||||
refreshIntervalMs={resolved.refreshIntervalMs}
|
<Button
|
||||||
description={resolved.description}
|
variant="ghost"
|
||||||
/>
|
size="icon-sm"
|
||||||
|
className="absolute right-2 top-2 z-10 opacity-0 transition-opacity group-hover:opacity-100 mobile-touch-target"
|
||||||
|
onClick={() => onEdit(widget.id)}
|
||||||
|
aria-label="Edit widget"
|
||||||
|
>
|
||||||
|
<Settings2 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
<Component
|
||||||
|
widget={widget}
|
||||||
|
refreshIntervalMs={resolved.refreshIntervalMs}
|
||||||
|
description={resolved.description}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,10 @@ function groupWidgetsBySection(
|
|||||||
|
|
||||||
function MobileWidgetSections({
|
function MobileWidgetSections({
|
||||||
sections,
|
sections,
|
||||||
|
onEditWidget,
|
||||||
}: {
|
}: {
|
||||||
sections: { id: SectionId; widgets: WidgetInstance[] }[];
|
sections: { id: SectionId; widgets: WidgetInstance[] }[];
|
||||||
|
onEditWidget?: (widgetId: string) => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -137,11 +139,11 @@ function MobileWidgetSections({
|
|||||||
{SECTION_META[section.id].label}
|
{SECTION_META[section.id].label}
|
||||||
</h3>
|
</h3>
|
||||||
{section.widgets.map((widget) => (
|
{section.widgets.map((widget) => (
|
||||||
<WidgetInstanceCard key={widget.id} widget={widget} />
|
<WidgetInstanceCard key={widget.id} widget={widget} onEdit={onEditWidget ? (id) => onEditWidget(id) : undefined} />
|
||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -448,6 +450,7 @@ export function Dashboard() {
|
|||||||
);
|
);
|
||||||
const [deleteShortcutId, setDeleteShortcutId] = useState<string | null>(null);
|
const [deleteShortcutId, setDeleteShortcutId] = useState<string | null>(null);
|
||||||
const [widgetDialogOpen, setWidgetDialogOpen] = useState(false);
|
const [widgetDialogOpen, setWidgetDialogOpen] = useState(false);
|
||||||
|
const [editWidgetId, setEditWidgetId] = useState<string | undefined>();
|
||||||
const { data: widgetInstances = [] } = useWidgetInstances(
|
const { data: widgetInstances = [] } = useWidgetInstances(
|
||||||
undefined,
|
undefined,
|
||||||
"dashboard",
|
"dashboard",
|
||||||
@@ -564,10 +567,10 @@ export function Dashboard() {
|
|||||||
</SectionCard>
|
</SectionCard>
|
||||||
|
|
||||||
{isMobile && mobileSections.length > 0 ? (
|
{isMobile && mobileSections.length > 0 ? (
|
||||||
<MobileWidgetSections sections={mobileSections} />
|
<MobileWidgetSections sections={mobileSections} onEditWidget={(id) => { setEditWidgetId(id); setWidgetDialogOpen(true); }} />
|
||||||
) : (
|
) : (
|
||||||
visibleWidgets.map((widget) => (
|
visibleWidgets.map((widget) => (
|
||||||
<WidgetInstanceCard key={widget.id} widget={widget} />
|
<WidgetInstanceCard key={widget.id} widget={widget} onEdit={(id) => { setEditWidgetId(id); setWidgetDialogOpen(true); }} />
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -593,8 +596,9 @@ export function Dashboard() {
|
|||||||
/>
|
/>
|
||||||
<WidgetConfigDialog
|
<WidgetConfigDialog
|
||||||
open={widgetDialogOpen}
|
open={widgetDialogOpen}
|
||||||
onClose={() => setWidgetDialogOpen(false)}
|
onClose={() => { setWidgetDialogOpen(false); setEditWidgetId(undefined); }}
|
||||||
dashboardScope="main"
|
dashboardScope="main"
|
||||||
|
editWidgetId={editWidgetId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export function NamedDashboardPage() {
|
|||||||
const dashboardScope = `named:${slug}`;
|
const dashboardScope = `named:${slug}`;
|
||||||
const { data: widgetRefs = [] } = useWidgetReferences(dashboardScope);
|
const { data: widgetRefs = [] } = useWidgetReferences(dashboardScope);
|
||||||
const [configOpen, setConfigOpen] = useState(false);
|
const [configOpen, setConfigOpen] = useState(false);
|
||||||
|
const [editWidgetId, setEditWidgetId] = useState<string | undefined>();
|
||||||
|
|
||||||
const items = useMemo(
|
const items = useMemo(
|
||||||
() => parseItems(dashboard?.payload ?? {}),
|
() => parseItems(dashboard?.payload ?? {}),
|
||||||
@@ -96,7 +97,7 @@ export function NamedDashboardPage() {
|
|||||||
{visibleWidgets.length > 0 ? (
|
{visibleWidgets.length > 0 ? (
|
||||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||||
{visibleWidgets.map((widget) => (
|
{visibleWidgets.map((widget) => (
|
||||||
<WidgetInstanceCard key={widget.id} widget={widget} />
|
<WidgetInstanceCard key={widget.id} widget={widget} onEdit={(id) => { setEditWidgetId(id); setConfigOpen(true); }} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -124,8 +125,9 @@ export function NamedDashboardPage() {
|
|||||||
|
|
||||||
<WidgetConfigDialog
|
<WidgetConfigDialog
|
||||||
open={configOpen}
|
open={configOpen}
|
||||||
onClose={() => setConfigOpen(false)}
|
onClose={() => { setConfigOpen(false); setEditWidgetId(undefined); }}
|
||||||
dashboardScope={dashboardScope}
|
dashboardScope={dashboardScope}
|
||||||
|
editWidgetId={editWidgetId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import type { ServiceInstance } from "../../types";
|
|||||||
export function OverviewTab({ instance }: { instance: ServiceInstance }) {
|
export function OverviewTab({ instance }: { instance: ServiceInstance }) {
|
||||||
const { data: widgets = [] } = useWidgetInstances(instance.id);
|
const { data: widgets = [] } = useWidgetInstances(instance.id);
|
||||||
const [configOpen, setConfigOpen] = useState(false);
|
const [configOpen, setConfigOpen] = useState(false);
|
||||||
|
const [editWidgetId, setEditWidgetId] = useState<string | undefined>();
|
||||||
|
|
||||||
const visibleWidgets = useMemo(
|
const visibleWidgets = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -48,7 +49,7 @@ export function OverviewTab({ instance }: { instance: ServiceInstance }) {
|
|||||||
{visibleWidgets.length > 0 ? (
|
{visibleWidgets.length > 0 ? (
|
||||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||||
{visibleWidgets.map((widget) => (
|
{visibleWidgets.map((widget) => (
|
||||||
<WidgetInstanceCard key={widget.id} widget={widget} />
|
<WidgetInstanceCard key={widget.id} widget={widget} onEdit={(id) => { setEditWidgetId(id); setConfigOpen(true); }} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -71,8 +72,9 @@ export function OverviewTab({ instance }: { instance: ServiceInstance }) {
|
|||||||
|
|
||||||
<WidgetConfigDialog
|
<WidgetConfigDialog
|
||||||
open={configOpen}
|
open={configOpen}
|
||||||
onClose={() => setConfigOpen(false)}
|
onClose={() => { setConfigOpen(false); setEditWidgetId(undefined); }}
|
||||||
serviceId={instance.id}
|
serviceId={instance.id}
|
||||||
|
editWidgetId={editWidgetId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user