Skip to content

Commit eb26870

Browse files
committed
fix: machine delete from sidebar — show uninstall steps, use correct id
The sidebar's remove button was passing the display label (not the machine id) to the removal handler, so the lookup silently failed. - Add machine_id, label, hostname to overview host entries - Sidebar × button now opens the UninstallMachineModal with uninstall instructions before removing the record - Portal.jsx onRemove receives the machine id directly - SelfHost.jsx onRemove resolves machine_id back to hostname for the self-host API
1 parent c54d7af commit eb26870

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

site/src/components/Portal.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,7 @@ export default function Portal({ onClose, user, onUser, onSelfHost }) {
314314
hosts={data?.hosts || []}
315315
onPhase={() => {}}
316316
onRename={(id, label) => cloud.rename(id, label).catch(() => {})}
317-
onRemove={(host) => {
318-
/* Cloud uses machine id, not hostname. Find the machine. */
319-
const m = (machines || []).find(x => x.host === host || x.id === host)
320-
if (m) cloud.remove(m.id).catch(() => {})
321-
}}
317+
onRemove={(id) => cloud.remove(id).catch(() => {})}
322318
/>
323319
)}
324320

site/src/components/SelfHost.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,12 @@ export default function SelfHost({ onClose }) {
638638
.then(() => fetchData())
639639
.catch(() => {})
640640
}}
641-
onRemove={(host) => {
641+
onRemove={(id) => {
642+
/* The self-host remove API uses the hostname (the `host`
643+
column in SQLite). The sidebar now passes the machine id;
644+
find the matching host entry to get the hostname. */
645+
const entry = (data?.hosts || []).find(h => h.machine_id === id)
646+
const host = entry?.host || id
642647
apiFetch(serverUrl.current, apiKeyRef.current,
643648
'/api/v1/machines/remove', { host })
644649
.then(() => fetchData())

site/src/components/admin/AdminSidebar.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef, useState } from 'react'
2-
import { Ic } from '../board/Rail'
32
import { Pill } from '../board/panels'
3+
import { Ic } from '../board/Rail'
44

55
function MachineRow({ h, isCur, outdated, collapsed, onPick, onRename, onRemove }) {
66
const [editing, setEditing] = useState(false)
@@ -19,7 +19,7 @@ function MachineRow({ h, isCur, outdated, collapsed, onPick, onRename, onRemove
1919

2020
const doRemove = (e) => {
2121
e.stopPropagation()
22-
onRemove(h.host)
22+
onRemove({ id: h.machine_id, label: h.label, hostname: h.hostname })
2323
}
2424

2525
const commitEdit = () => {
@@ -86,6 +86,7 @@ export default function AdminSidebar({
8686
onRename,
8787
onRemove,
8888
}) {
89+
const [uninstalling, setUninstalling] = useState(null)
8990
const bs = board || {}
9091
const nav = bs.nav || []
9192
const active = bs.active
@@ -118,7 +119,7 @@ export default function AdminSidebar({
118119
if (phase !== 'live') onPhase('live')
119120
}}
120121
onRename={onRename}
121-
onRemove={onRemove}
122+
onRemove={setUninstalling}
122123
/>
123124
))}
124125
{!collapsed && phase === 'live' && bs.onAdd && (
@@ -196,6 +197,13 @@ export default function AdminSidebar({
196197
{!collapsed && <span>Collapse</span>}
197198
</button>
198199
</div>
200+
{uninstalling && (
201+
<UninstallMachineModal
202+
machine={uninstalling}
203+
onClose={() => setUninstalling(null)}
204+
onRemove={(id) => { onRemove(id); setUninstalling(null) }}
205+
/>
206+
)}
199207
</aside>
200208
)
201209
}

site/src/components/board/enroll.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ const UNINSTALL_CMD = `curl -fsSL ${location.origin}/uninstall.sh | sh`
504504
necessary local action explicit and give it to them before the record goes
505505
away. This also prevents a still-running agent from looking like it was
506506
uninstalled just because its next heartbeat was rejected. */
507-
function UninstallMachineModal({ machine, onClose, onRemove }) {
507+
export function UninstallMachineModal({ machine, onClose, onRemove }) {
508508
const [copied, setCopied] = useState(false)
509509
const [removing, setRemoving] = useState(false)
510510
const [error, setError] = useState(null)

site/src/lib/overview.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export function buildOverview(machines, now = Date.now()) {
2929
const age = (now - Date.parse(m.lastSeenAt)) / 1000
3030
return {
3131
host: m.label,
32+
machine_id: m.id,
33+
label: m.label,
34+
hostname: m.hostname,
3235
last_seen: m.lastSeenAt,
3336
agent_version: m.agentVersion,
3437
ageSeconds: Number.isFinite(age) ? age : null,

0 commit comments

Comments
 (0)