fix(ui): подтверждать операции рекурсивных маршрутов
This commit is contained in:
1 parent
79a8d95e7d
commit
f5fc9282e2
11 files changed
+364
-138
No files matched your search
@@ -69,6 +69,7 @@ export function ConfigHistorySheet({
|
||||
onRetry,
|
||||
restoring,
|
||||
onRestore,
|
||||
restoreDisabled = false,
|
||||
}: {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
@@ -79,6 +80,7 @@ export function ConfigHistorySheet({
|
||||
loadError?: string | null
|
||||
onRetry?: () => void
|
||||
restoring: boolean
|
||||
restoreDisabled?: boolean
|
||||
onRestore: (id: string) => Promise<void> | void
|
||||
}) {
|
||||
const [pending, setPending] = useState<ConfigRevisionDto | null>(null)
|
||||
@@ -87,7 +89,7 @@ export function ConfigHistorySheet({
|
||||
const [restoreError, setRestoreError] = useState<string | null>(null)
|
||||
const busy = restoring || submitting
|
||||
async function confirmRestore() {
|
||||
if (!pending || restoreLock.current || restoring) return
|
||||
if (!pending || restoreLock.current || restoring || restoreDisabled) return
|
||||
restoreLock.current = true
|
||||
setSubmitting(true)
|
||||
setRestoreError(null)
|
||||
@@ -162,7 +164,7 @@ export function ConfigHistorySheet({
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={busy}
|
||||
disabled={busy || restoreDisabled}
|
||||
onClick={() => { setRestoreError(null); setPending(rev) }}
|
||||
>
|
||||
<RotateCcwIcon className="size-3.5" />
|
||||
@@ -205,7 +207,7 @@ export function ConfigHistorySheet({
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={busy} onClick={() => setPending(null)}>Отмена</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
disabled={busy || !pending}
|
||||
disabled={busy || restoreDisabled || !pending}
|
||||
type="button"
|
||||
onClick={() => void confirmRestore()}
|
||||
>
|
||||
|
||||
@@ -113,6 +113,8 @@ interface RecursiveRoutesDataGridProps {
|
||||
onExpandedChange?: (key: string | null) => void
|
||||
onEdit: (group: RecursiveRouteGroup) => void
|
||||
onDelete: (group: RecursiveRouteGroup) => void
|
||||
mutationsDisabled?: boolean
|
||||
emptyTitle?: string
|
||||
}
|
||||
|
||||
function RecursiveRoutesDataGrid({
|
||||
@@ -121,6 +123,8 @@ function RecursiveRoutesDataGrid({
|
||||
onExpandedChange,
|
||||
onEdit,
|
||||
onDelete,
|
||||
mutationsDisabled = false,
|
||||
emptyTitle = "Нет маршрутов",
|
||||
}: RecursiveRoutesDataGridProps) {
|
||||
const [confirmDeleteKey, setConfirmDeleteKey] = useState<string | null>(null)
|
||||
|
||||
@@ -243,13 +247,16 @@ function RecursiveRoutesDataGrid({
|
||||
const confirmDel = confirmDeleteKey === g.key
|
||||
return (
|
||||
<div
|
||||
className="flex items-center gap-0.5 justify-end opacity-0 group-hover/row:opacity-100 transition-opacity"
|
||||
className="flex items-center gap-0.5 justify-end"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="size-7 p-0 text-muted-foreground hover:text-foreground"
|
||||
type="button"
|
||||
aria-label={`Редактировать маршрут ${g.dstAddress} · ${g.routingTable}`}
|
||||
disabled={mutationsDisabled}
|
||||
onClick={() => onEdit(g)}
|
||||
>
|
||||
<PencilIcon className="size-3.5" />
|
||||
@@ -263,7 +270,11 @@ function RecursiveRoutesDataGrid({
|
||||
? "text-destructive bg-destructive/10 hover:bg-destructive/20"
|
||||
: "text-muted-foreground hover:text-destructive",
|
||||
)}
|
||||
type="button"
|
||||
aria-label={`${confirmDel ? "Подтвердить удаление" : "Удалить маршрут"} ${g.dstAddress} · ${g.routingTable}`}
|
||||
disabled={mutationsDisabled}
|
||||
onClick={() => {
|
||||
if (mutationsDisabled) return
|
||||
if (!confirmDel) setConfirmDeleteKey(g.key)
|
||||
else {
|
||||
onDelete(g)
|
||||
@@ -285,7 +296,7 @@ function RecursiveRoutesDataGrid({
|
||||
meta: { headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST },
|
||||
},
|
||||
],
|
||||
[confirmDeleteKey, expandedKey, onDelete, onEdit],
|
||||
[confirmDeleteKey, expandedKey, onDelete, onEdit, mutationsDisabled],
|
||||
)
|
||||
|
||||
const table = useTable({
|
||||
@@ -302,7 +313,7 @@ function RecursiveRoutesDataGrid({
|
||||
return (
|
||||
<EmptyState
|
||||
icon={<RouteIcon className="size-4" />}
|
||||
title="Нет маршрутов"
|
||||
title={emptyTitle}
|
||||
className="border-0 py-10"
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user