fix(ui): подтверждать переключение проб через API

This commit is contained in:
Denozordec committed 2026-09-21 21:03:14 +07:00
1 parent 2f5b617e8c
commit 4f235058be
4 files changed
+63 -21

No files matched your search

+18 -19
View File
@@ -1056,6 +1056,7 @@ function ResourcesTab({ resources, serversList, liveApi }: { resources: ServerRe
function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId: string | null; allProbesHref: string }) {
const { mode, backendUrl, backendStatus, checkBackend } = useDataSource()
const draftProbeId = useRef("")
const [probeSaving, setProbeSaving] = useState(false)
const [probeSaveError, setProbeSaveError] = useState<string | null>(null)
const savingRef = useRef(false)
@@ -1579,11 +1580,8 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
// ── actions ──
const toggleProbe = (id: string, v: boolean) => {
if (!requireWrite()) return
setProbes((prev) => {
const next = prev.map((x) => x.id === id ? { ...x, enabled: v } : x)
void persistProbes(next).catch(error => setOpError(serverOperationError(error)))
return next
})
const next = probes.map(p => p.id === id ? { ...p, enabled: v } : p)
void saveProbeForm(() => persistProbes(next), () => setProbes(next))
}
const deleteProbe = (id: string) => {
@@ -1637,6 +1635,7 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
const openAddSheet = () => {
if (!requireWrite()) return
draftProbeId.current = "p" + Date.now()
setProbeSaveError(null)
setEditingProbeId(null)
setNewSrcId(selectableSources[0]?.id ?? "")
@@ -1649,7 +1648,7 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
if (!requireWrite()) return
if (!newName.trim() || !newTarget.trim() || !newSrcId) return
const probeBase: PingProbe = {
id: editingProbeId ?? `p${Date.now()}`,
id: editingProbeId ?? draftProbeId.current,
srcServerId: newSrcId,
srcInterface: newSrcInterface,
name: newName.trim(),
@@ -1883,18 +1882,15 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
const updateSpeedProbe = (id: string, patch: Partial<SpeedProbeRow>) => {
if (!requireWrite()) return
setSpeedProbes((prev) => {
const nextRows = prev.map((p) => {
if (p.id !== id) return p
const next = { ...p, ...patch }
if (patch.srcServerId && patch.srcServerId === next.dstServerId) {
next.dstServerId = selectableSources.find((s) => s.id !== patch.srcServerId)?.id ?? patch.srcServerId
}
return next
})
void persistSpeedProbes(nextRows).catch(error => setSpeedError(serverOperationError(error)))
return nextRows
const nextRows = speedProbes.map(p => {
if (p.id !== id) return p
const next = { ...p, ...patch }
if (patch.srcServerId && patch.srcServerId === next.dstServerId) {
next.dstServerId = selectableSources.find(s => s.id !== patch.srcServerId)?.id ?? patch.srcServerId
}
return next
})
void saveProbeForm(() => persistSpeedProbes(nextRows), () => setSpeedProbes(nextRows))
}
const openAddSpeedSheet = () => {
@@ -1904,7 +1900,7 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
const src = selectableSources[0]?.id ?? ""
const dst = selectableSources.find((s) => s.id !== src)?.id ?? src
setSpeedDraft({
id: "",
id: "sp-" + Date.now(),
srcServerId: src,
dstServerId: dst,
srcInterface: "",
@@ -1937,7 +1933,7 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
if (!speedDraft.srcServerId || !speedDraft.dstServerId) return
const next = editingSpeedProbeId ? speedProbes.map(p => p.id === editingSpeedProbeId
? { ...p, ...speedDraft, id: editingSpeedProbeId, durationSec: String(speedDraft.durationSec ?? "10") } : p)
: [{ ...speedDraft, id: "sp-" + Date.now() }, ...speedProbes]
: [{ ...speedDraft, id: speedDraft.id }, ...speedProbes]
void saveProbeForm(() => persistSpeedProbes(next), () => {
setSpeedProbes(next)
setEditingSpeedProbeId(null)
@@ -2008,6 +2004,8 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
{!canWrite && <ContextAlert variant="info" role="status"><ContextTitle>Только просмотр</ContextTitle><ContextDescription>Изменение проб и запуск измерений требуют разрешения на запись. Обновление данных загружает сохранённые результаты.</ContextDescription></ContextAlert>}
{permissionError && !sheetOpen && !speedSheetOpen && <ContextAlert variant="destructive" role="alert"><ContextDescription>{permissionError}</ContextDescription></ContextAlert>}
{probeSaveError && !sheetOpen && !speedSheetOpen && <ContextAlert variant="destructive" role="alert"><ContextDescription>{probeSaveError}</ContextDescription></ContextAlert>}
{/* ── Live indicator ── */}
{!isPaused && (
<div className="flex items-center gap-2 px-6 py-1.5 border-b shrink-0 text-[11px]"
@@ -2682,6 +2680,7 @@ function UptimePageContent({ selectedProbeId, allProbesHref }: { selectedProbeId
onClick={() => {
if (!requireWrite()) return
setProbeSaveError(null)
draftProbeId.current = "p" + Date.now()
setEditingProbeId(null)
setNewSrcId(srv.id)
setNewSrcInterface("")