fix: correct UTC timestamp display and pre-existing code quality issues
This commit is contained in:
@@ -78,7 +78,7 @@ export function PendingDeviceModal({ device, onClose, onApprove, onHide, onIgnor
|
|||||||
|
|
||||||
const TypeIcon = TYPE_ICONS[device.suggested_type ?? 'generic'] ?? Circle
|
const TypeIcon = TYPE_ICONS[device.suggested_type ?? 'generic'] ?? Circle
|
||||||
|
|
||||||
const handleApprove = () => { onApprove(device); onClose() }
|
const handleApprove = () => { onApprove(device) }
|
||||||
const handleHide = () => { onHide(device); onClose() }
|
const handleHide = () => { onHide(device); onClose() }
|
||||||
const handleIgnore = () => { onIgnore(device); onClose() }
|
const handleIgnore = () => { onIgnore(device); onClose() }
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ describe('PendingDeviceModal', () => {
|
|||||||
|
|
||||||
// ── Actions ───────────────────────────────────────────────────────────────
|
// ── Actions ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
it('calls onApprove with the device and onClose when Approve is clicked', () => {
|
it('calls onApprove with the device when Approve is clicked (parent controls close on success)', () => {
|
||||||
const device = makeDevice()
|
const device = makeDevice()
|
||||||
const onApprove = vi.fn()
|
const onApprove = vi.fn()
|
||||||
const onClose = vi.fn()
|
const onClose = vi.fn()
|
||||||
@@ -135,7 +135,7 @@ describe('PendingDeviceModal', () => {
|
|||||||
)
|
)
|
||||||
fireEvent.click(screen.getByRole('button', { name: 'Approve' }))
|
fireEvent.click(screen.getByRole('button', { name: 'Approve' }))
|
||||||
expect(onApprove).toHaveBeenCalledWith(device)
|
expect(onApprove).toHaveBeenCalledWith(device)
|
||||||
expect(onClose).toHaveBeenCalledOnce()
|
expect(onClose).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls onHide with the device and onClose when Hide is clicked', () => {
|
it('calls onHide with the device and onClose when Hide is clicked', () => {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ export function DetailPanel({ onEdit }: DetailPanelProps) {
|
|||||||
const handleAddService = () => {
|
const handleAddService = () => {
|
||||||
const port = parseInt(newSvc.port, 10)
|
const port = parseInt(newSvc.port, 10)
|
||||||
if (!newSvc.service_name.trim() || isNaN(port) || port < 1 || port > 65535) return
|
if (!newSvc.service_name.trim() || isNaN(port) || port < 1 || port > 65535) return
|
||||||
|
snapshotHistory()
|
||||||
const svc: ServiceInfo = { port, protocol: newSvc.protocol, service_name: newSvc.service_name.trim() }
|
const svc: ServiceInfo = { port, protocol: newSvc.protocol, service_name: newSvc.service_name.trim() }
|
||||||
updateNode(node.id, { services: [...services, svc] })
|
updateNode(node.id, { services: [...services, svc] })
|
||||||
setNewSvc(EMPTY_FORM)
|
setNewSvc(EMPTY_FORM)
|
||||||
@@ -92,6 +93,7 @@ export function DetailPanel({ onEdit }: DetailPanelProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleRemoveService = (index: number) => {
|
const handleRemoveService = (index: number) => {
|
||||||
|
snapshotHistory()
|
||||||
const updated = services.filter((_, i) => i !== index)
|
const updated = services.filter((_, i) => i !== index)
|
||||||
updateNode(node.id, { services: updated })
|
updateNode(node.id, { services: updated })
|
||||||
if (editingIndex === index) setEditingFor(null)
|
if (editingIndex === index) setEditingFor(null)
|
||||||
@@ -109,6 +111,7 @@ export function DetailPanel({ onEdit }: DetailPanelProps) {
|
|||||||
if (editingIndex === null) return
|
if (editingIndex === null) return
|
||||||
const port = parseInt(editSvc.port, 10)
|
const port = parseInt(editSvc.port, 10)
|
||||||
if (!editSvc.service_name.trim() || isNaN(port) || port < 1 || port > 65535) return
|
if (!editSvc.service_name.trim() || isNaN(port) || port < 1 || port > 65535) return
|
||||||
|
snapshotHistory()
|
||||||
const updated = services.map((svc, i) =>
|
const updated = services.map((svc, i) =>
|
||||||
i === editingIndex ? { ...svc, port, protocol: editSvc.protocol, service_name: editSvc.service_name.trim() } : svc
|
i === editingIndex ? { ...svc, port, protocol: editSvc.protocol, service_name: editSvc.service_name.trim() } : svc
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ export function Sidebar({ onAddNode, onAddGroupRect, onScan, onSave, onNodeAppro
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const COMMON_PORTS = new Set([22, 80, 443])
|
||||||
|
|
||||||
function PendingDevicesPanel({ onNodeApproved, highlightId }: { onNodeApproved: (nodeId: string) => void; highlightId?: string }) {
|
function PendingDevicesPanel({ onNodeApproved, highlightId }: { onNodeApproved: (nodeId: string) => void; highlightId?: string }) {
|
||||||
const [devices, setDevices] = useState<PendingDevice[]>([])
|
const [devices, setDevices] = useState<PendingDevice[]>([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
@@ -223,6 +225,7 @@ function PendingDevicesPanel({ onNodeApproved, highlightId }: { onNodeApproved:
|
|||||||
})
|
})
|
||||||
toast.success(`Approved ${nodeData.label}`)
|
toast.success(`Approved ${nodeData.label}`)
|
||||||
setDevices((prev) => prev.filter((d) => d.id !== device.id))
|
setDevices((prev) => prev.filter((d) => d.id !== device.id))
|
||||||
|
setSelected(null)
|
||||||
onNodeApproved(nodeId)
|
onNodeApproved(nodeId)
|
||||||
} catch {
|
} catch {
|
||||||
toast.error('Failed to approve device')
|
toast.error('Failed to approve device')
|
||||||
@@ -269,7 +272,6 @@ function PendingDevicesPanel({ onNodeApproved, highlightId }: { onNodeApproved:
|
|||||||
<p className="text-xs text-muted-foreground text-center py-4">No pending devices</p>
|
<p className="text-xs text-muted-foreground text-center py-4">No pending devices</p>
|
||||||
)}
|
)}
|
||||||
{devices.map((d) => {
|
{devices.map((d) => {
|
||||||
const COMMON_PORTS = new Set([22, 80, 443])
|
|
||||||
const namedService = d.services.find((s) => s.category != null && !COMMON_PORTS.has(s.port))
|
const namedService = d.services.find((s) => s.category != null && !COMMON_PORTS.has(s.port))
|
||||||
const titleService = namedService
|
const titleService = namedService
|
||||||
?? d.services.find((s) => s.port === 80)
|
?? d.services.find((s) => s.port === 80)
|
||||||
|
|||||||
Reference in New Issue
Block a user