Mobile Settings: machine editor SheetForm (Slice 7)
Below md, the machine editor Dialog renders as a SheetForm (triggered by the same Edit/Add buttons via machineDialogOpen state). The shared MachineEditor body (fields + SSH validate button) renders inside the sheet; the ConfirmDialog is a sibling outside. Desktop Dialog is byte-for-byte identical. No navigation needed on close -- the Settings page content (tabbed cards, machine list) is always visible behind the sheet, so there is no stranding risk (unlike ServicePage where the sheet was the whole page). Added saveDisabled prop to SheetForm (additive, default false) so the machine editor can gate Save on required fields (name + host for SSH mode), matching the desktop DialogFooter confirmDisabled semantics. Scope note: SSHKeyManager is an inline two-panel layout (SelectionRailCard + SectionCard), not a dialog, and already stacks responsively via grid-cols-1 md:grid-cols-[...]. Wrapping it in SheetForm would break its always-visible selection rail. Left as-is. Tests: 3 new mobile cases (SheetForm render, save payload, cancel closes) + desktop unchanged. 113 tests pass; lint/build green. Refs openspec/changes/mobile-responsive-parity/ (spec R4, tasks slice 7).
This commit is contained in:
@@ -17,6 +17,8 @@ import {
|
||||
useSaveSSHKey,
|
||||
useTestMonitoringMachineSSH,
|
||||
} from "../hooks/useSettings";
|
||||
import { useIsMobile } from "../hooks/useIsMobile";
|
||||
import { SheetForm } from "@/components/ui/sheet-form";
|
||||
import { DialogFooter } from "../components/DialogFooter";
|
||||
import { HoverEditButton } from "../components/HoverEditButton";
|
||||
import { SectionCard } from "../components/SectionCard";
|
||||
@@ -850,6 +852,7 @@ export function Settings() {
|
||||
const [editingMachine, setEditingMachine] =
|
||||
useState<MonitoringMachine | null>(null);
|
||||
const [selectedMachineId, setSelectedMachineId] = useState("");
|
||||
const isMobile = useIsMobile();
|
||||
const orderedMachines = useMemo(() => machines ?? [], [machines]);
|
||||
const selectedMachine = useMemo(
|
||||
() =>
|
||||
@@ -1135,21 +1138,24 @@ export function Settings() {
|
||||
)}
|
||||
{tab === "danger" && <ResetLocalDatabaseCard />}
|
||||
</TabbedCard>
|
||||
<Dialog
|
||||
open={machineDialogOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) closeMachineDialog();
|
||||
}}
|
||||
>
|
||||
<DialogContent className="sm:max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{machineDraft.id ? "Edit machine" : "Create machine"}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{machineDraft.mode === "local" ? "Local API host" : "SSH target"}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{isMobile ? (
|
||||
<SheetForm
|
||||
open={machineDialogOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) closeMachineDialog();
|
||||
}}
|
||||
title={machineDraft.id ? "Edit machine" : "Create machine"}
|
||||
onSave={() => {
|
||||
void saveMachineDraft(machineDraft);
|
||||
}}
|
||||
onCancel={closeMachineDialog}
|
||||
isPending={saveMachine.isPending}
|
||||
saveDisabled={
|
||||
!machineDraft.name ||
|
||||
(machineDraft.mode === "ssh" && !machineDraft.host.trim())
|
||||
}
|
||||
saveLabel={machineDraft.id ? "Save machine" : "Create machine"}
|
||||
>
|
||||
<MachineEditor
|
||||
key={`${machineDraft.id ?? machineDraft.mode}-${machineDraft.mode}`}
|
||||
title={
|
||||
@@ -1170,32 +1176,80 @@ export function Settings() {
|
||||
sshValidationError={sshValidationError}
|
||||
sshValidationStatus={sshValidationStatus}
|
||||
/>
|
||||
<DialogFooter
|
||||
onCancel={closeMachineDialog}
|
||||
cancelLabel="Cancel"
|
||||
onConfirm={() => {
|
||||
void saveMachineDraft(machineDraft);
|
||||
}}
|
||||
confirmLabel={machineDraft.id ? "Save machine" : "Create machine"}
|
||||
confirmDisabled={
|
||||
!machineDraft.name ||
|
||||
(machineDraft.mode === "ssh" && !machineDraft.host.trim())
|
||||
}
|
||||
secondaryAction={
|
||||
machineDraft.id ? (
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => {
|
||||
setDeleteMachineId(machineDraft.id as string);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
{machineDraft.id ? (
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => setDeleteMachineId(machineDraft.id as string)}
|
||||
>
|
||||
Delete machine
|
||||
</Button>
|
||||
) : null}
|
||||
</SheetForm>
|
||||
) : (
|
||||
<Dialog
|
||||
open={machineDialogOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) closeMachineDialog();
|
||||
}}
|
||||
>
|
||||
<DialogContent className="sm:max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{machineDraft.id ? "Edit machine" : "Create machine"}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
{machineDraft.mode === "local"
|
||||
? "Local API host"
|
||||
: "SSH target"}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<MachineEditor
|
||||
key={`${machineDraft.id ?? machineDraft.mode}-${machineDraft.mode}`}
|
||||
title={
|
||||
machineDraft.id
|
||||
? machineDraft.name || "Edit machine"
|
||||
: "New machine"
|
||||
}
|
||||
hint={
|
||||
machineDraft.mode === "local" ? "Local API host" : "SSH target"
|
||||
}
|
||||
machine={machineDraft}
|
||||
sshKeys={sshKeys}
|
||||
editingMachine={editingMachine}
|
||||
onChange={updateMachineDraft}
|
||||
onValidateSSH={validateMachineSSH}
|
||||
isValidatingSSH={testMachineSSH.isPending}
|
||||
sshValidationMessage={sshValidationMessage}
|
||||
sshValidationError={sshValidationError}
|
||||
sshValidationStatus={sshValidationStatus}
|
||||
/>
|
||||
<DialogFooter
|
||||
onCancel={closeMachineDialog}
|
||||
cancelLabel="Cancel"
|
||||
onConfirm={() => {
|
||||
void saveMachineDraft(machineDraft);
|
||||
}}
|
||||
confirmLabel={machineDraft.id ? "Save machine" : "Create machine"}
|
||||
confirmDisabled={
|
||||
!machineDraft.name ||
|
||||
(machineDraft.mode === "ssh" && !machineDraft.host.trim())
|
||||
}
|
||||
secondaryAction={
|
||||
machineDraft.id ? (
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => {
|
||||
setDeleteMachineId(machineDraft.id as string);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
<ConfirmDialog
|
||||
open={Boolean(deleteMachineId)}
|
||||
title="Delete machine?"
|
||||
|
||||
Reference in New Issue
Block a user