From fa97ae040007ce464a581f78925212d17fe726f3 Mon Sep 17 00:00:00 2001 From: robbond Date: Thu, 5 Mar 2026 18:29:33 +0000 Subject: [PATCH] feat(ui): collapse connect instance panel when instances exist --- components/dashboard/dashboard-controls.tsx | 181 +++++++++++++------- 1 file changed, 119 insertions(+), 62 deletions(-) diff --git a/components/dashboard/dashboard-controls.tsx b/components/dashboard/dashboard-controls.tsx index 116aad2..b1a0888 100644 --- a/components/dashboard/dashboard-controls.tsx +++ b/components/dashboard/dashboard-controls.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import type { ChangeEvent } from "react"; import type { FormEvent } from "react"; import { formatDateTime } from "@/lib/dates"; @@ -167,6 +167,7 @@ export function DashboardControls({ autoSyncByInstance, healthEventsByInstance, }: Props) { + const hasInstances = instances.length > 0; const autoSyncFrequencyOptions = [15, 30, 60, 180, 360, 1440]; const [instanceName, setInstanceName] = useState(""); const [baseUrl, setBaseUrl] = useState(""); @@ -182,6 +183,39 @@ export function DashboardControls({ const [domainStatus, setDomainStatus] = useState("all"); const [message, setMessage] = useState(null); const [loading, setLoading] = useState(false); + const [isConnectPanelOpen, setIsConnectPanelOpen] = useState(!hasInstances); + + useEffect(() => { + if (!hasInstances) { + setIsConnectPanelOpen(true); + return; + } + + const savedState = window.localStorage.getItem( + "dashboard_connect_panel_open", + ); + + if (savedState === "true") { + setIsConnectPanelOpen(true); + return; + } + + if (savedState === "false") { + setIsConnectPanelOpen(false); + return; + } + + setIsConnectPanelOpen(false); + }, [hasInstances]); + + useEffect(() => { + if (!hasInstances) return; + + window.localStorage.setItem( + "dashboard_connect_panel_open", + isConnectPanelOpen ? "true" : "false", + ); + }, [hasInstances, isConnectPanelOpen]); const healthCounts = instances.reduce( (acc, instance) => { @@ -416,79 +450,102 @@ export function DashboardControls({
-
-

Connect Plesk Instance

- ) => - setInstanceName(e.target.value) - } - className="w-full rounded border border-slate-300 px-3 py-2 text-sm" - placeholder="Instance name" - /> - ) => - setBaseUrl(e.target.value) - } - className="w-full rounded border border-slate-300 px-3 py-2 text-sm" - placeholder="https://plesk.example.com" - /> - - {authType === "api_key" ? ( - ) => - setApiKey(e.target.value) - } - className="w-full rounded border border-slate-300 px-3 py-2 text-sm" - placeholder="Plesk API key" - /> - ) : ( -
+
+
+

+ {hasInstances + ? "Connect another Plesk instance" + : "Connect Plesk Instance"} +

+ {hasInstances ? ( + + ) : null} +
+ + {!isConnectPanelOpen && hasInstances ? ( +

+ Add another server when needed. +

+ ) : null} + + {isConnectPanelOpen ? ( + ) => - setUsername(e.target.value) + setInstanceName(e.target.value) } className="w-full rounded border border-slate-300 px-3 py-2 text-sm" - placeholder="Plesk username" + placeholder="Instance name" /> ) => - setPassword(e.target.value) + setBaseUrl(e.target.value) } className="w-full rounded border border-slate-300 px-3 py-2 text-sm" - placeholder="Plesk password" + placeholder="https://plesk.example.com" /> -
- )} - - + + {authType === "api_key" ? ( + ) => + setApiKey(e.target.value) + } + className="w-full rounded border border-slate-300 px-3 py-2 text-sm" + placeholder="Plesk API key" + /> + ) : ( +
+ ) => + setUsername(e.target.value) + } + className="w-full rounded border border-slate-300 px-3 py-2 text-sm" + placeholder="Plesk username" + /> + ) => + setPassword(e.target.value) + } + className="w-full rounded border border-slate-300 px-3 py-2 text-sm" + placeholder="Plesk password" + /> +
+ )} + + + ) : null} +

Plesk Instances