quality / commitlint (push) Skipped
quality / changes (push) Successful in 9s
quality / docker-check (push) Skipped
quality / openapi (push) Successful in 39s
quality / web (push) Successful in 1m29s
quality / go (push) Successful in 1m3s
quality / bird2 (push) Successful in 15s
CD / quality (push) Successful in 3m43s
CD / publish (push) Failing after 8m29s
Единый kitDataGridTableLayout и ResourcePage/FrameDataGrid на всех списках. Календарь задач переведён на EventCalendar, lookup — на cascader, у операций появился вид доски. Удалены settings-7 и самописные DataGridSection/toolbar. Co-authored-by: Cursor <[email protected]>
227 lines
6.8 KiB
TypeScript
227 lines
6.8 KiB
TypeScript
import { useState } from 'react'
|
|
import { Plus } from 'lucide-react'
|
|
import { toast } from 'sonner'
|
|
|
|
import { Button } from '@evobgp/ui/components/button'
|
|
|
|
import { ConfirmDialog } from '@/components/confirm-dialog'
|
|
import { ModuleEntriesGrid, type ModuleEntryDeleteTarget } from '@/components/modules/module-entries-grid'
|
|
import { ModuleAsEntryDialog } from '@/components/modules/module-as-entry-dialog'
|
|
import { ModuleCdnSourceDialog } from '@/components/modules/module-cdn-source-dialog'
|
|
import { ModuleDomainEntryDialog } from '@/components/modules/module-domain-entry-dialog'
|
|
import { ModuleIpRangeEntryDialog } from '@/components/modules/module-ip-range-entry-dialog'
|
|
import { ApiError, apiMutate } from '@/lib/api-client'
|
|
import type {
|
|
AsEntry,
|
|
BgpCommunity,
|
|
CdnSource,
|
|
DomainEntry,
|
|
IpRangeEntry,
|
|
ModuleRow,
|
|
} from '@/types/api'
|
|
|
|
interface ModuleEntriesSectionProps {
|
|
moduleId: string
|
|
mod: ModuleRow
|
|
items: Record<string, unknown>[]
|
|
communities: BgpCommunity[]
|
|
isLoading: boolean
|
|
isError: boolean
|
|
error: Error | null
|
|
onRetry: () => void
|
|
onChanged: () => void | Promise<void>
|
|
}
|
|
|
|
type DeleteTarget = ModuleEntryDeleteTarget
|
|
|
|
const CARD_META: Record<
|
|
ModuleRow['type'],
|
|
{ title: string; description: string; emptyTitle: string; emptyDescription: string }
|
|
> = {
|
|
DOMAINS: {
|
|
title: 'Домены',
|
|
description: 'FQDN для резолвинга через DoH.',
|
|
emptyTitle: 'Нет доменов',
|
|
emptyDescription: 'Добавьте FQDN для резолвинга.',
|
|
},
|
|
IP_RANGES: {
|
|
title: 'IP-диапазоны',
|
|
description: 'Статические CIDR для анонса.',
|
|
emptyTitle: 'Нет диапазонов',
|
|
emptyDescription: 'Добавьте CIDR.',
|
|
},
|
|
CDN_CIDRS: {
|
|
title: 'CDN-источники',
|
|
description: 'URL источников для скачивания списков CIDR.',
|
|
emptyTitle: 'Нет источников',
|
|
emptyDescription: 'Добавьте CDN-источник.',
|
|
},
|
|
AS_PREFIXES: {
|
|
title: 'AS-записи',
|
|
description: 'ASN для получения префиксов через RIPEstat.',
|
|
emptyTitle: 'Нет записей',
|
|
emptyDescription: 'Добавьте ASN.',
|
|
},
|
|
}
|
|
|
|
export function ModuleEntriesSection({
|
|
moduleId,
|
|
mod,
|
|
items,
|
|
communities,
|
|
isLoading,
|
|
isError,
|
|
error,
|
|
onRetry,
|
|
onChanged,
|
|
}: ModuleEntriesSectionProps) {
|
|
const meta = CARD_META[mod.type]
|
|
const [dialogOpen, setDialogOpen] = useState(false)
|
|
const [deleteTarget, setDeleteTarget] = useState<DeleteTarget | null>(null)
|
|
const [deleting, setDeleting] = useState(false)
|
|
|
|
const [editDomain, setEditDomain] = useState<DomainEntry | null>(null)
|
|
const [editIpRange, setEditIpRange] = useState<IpRangeEntry | null>(null)
|
|
const [editCdn, setEditCdn] = useState<CdnSource | null>(null)
|
|
const [editAs, setEditAs] = useState<AsEntry | null>(null)
|
|
|
|
function openCreate() {
|
|
setEditDomain(null)
|
|
setEditIpRange(null)
|
|
setEditCdn(null)
|
|
setEditAs(null)
|
|
setDialogOpen(true)
|
|
}
|
|
|
|
function closeDialog() {
|
|
setDialogOpen(false)
|
|
setEditDomain(null)
|
|
setEditIpRange(null)
|
|
setEditCdn(null)
|
|
setEditAs(null)
|
|
}
|
|
|
|
async function confirmDelete() {
|
|
if (!deleteTarget) return
|
|
setDeleting(true)
|
|
try {
|
|
const { kind, entry } = deleteTarget
|
|
const pathByKind = {
|
|
domain: `/v1/modules/${moduleId}/domain-entries/${entry.id}`,
|
|
'ip-range': `/v1/modules/${moduleId}/ip-range-entries/${entry.id}`,
|
|
cdn: `/v1/modules/${moduleId}/cdn-sources/${entry.id}`,
|
|
as: `/v1/modules/${moduleId}/as-entries/${entry.id}`,
|
|
} as const
|
|
await apiMutate(pathByKind[kind], 'DELETE', undefined, { idempotent: false })
|
|
toast.success('Удалено')
|
|
setDeleteTarget(null)
|
|
await onChanged()
|
|
} catch (e) {
|
|
toast.error(e instanceof ApiError ? e.message : String(e))
|
|
} finally {
|
|
setDeleting(false)
|
|
}
|
|
}
|
|
|
|
const addButton = (
|
|
<Button size="sm" type="button" onClick={openCreate}>
|
|
<Plus />
|
|
Добавить
|
|
</Button>
|
|
)
|
|
|
|
return (
|
|
<>
|
|
<ModuleEntriesGrid
|
|
mod={mod}
|
|
rows={items}
|
|
communities={communities}
|
|
isLoading={isLoading}
|
|
isError={isError}
|
|
error={error}
|
|
onRetry={onRetry}
|
|
title={meta.title}
|
|
description={meta.description}
|
|
actions={addButton}
|
|
emptyTitle={meta.emptyTitle}
|
|
emptyDescription={meta.emptyDescription}
|
|
onEdit={(target) => {
|
|
if (target.kind === 'domain') setEditDomain(target.entry)
|
|
if (target.kind === 'ip-range') setEditIpRange(target.entry)
|
|
if (target.kind === 'cdn') setEditCdn(target.entry)
|
|
if (target.kind === 'as') setEditAs(target.entry)
|
|
setDialogOpen(true)
|
|
}}
|
|
onDelete={setDeleteTarget}
|
|
/>
|
|
|
|
{mod.type === 'DOMAINS' ? (
|
|
<ModuleDomainEntryDialog
|
|
open={dialogOpen}
|
|
moduleId={moduleId}
|
|
edit={editDomain}
|
|
communities={communities}
|
|
onOpenChange={(open) => (open ? setDialogOpen(true) : closeDialog())}
|
|
onSaved={onChanged}
|
|
/>
|
|
) : null}
|
|
{mod.type === 'IP_RANGES' ? (
|
|
<ModuleIpRangeEntryDialog
|
|
open={dialogOpen}
|
|
moduleId={moduleId}
|
|
edit={editIpRange}
|
|
communities={communities}
|
|
onOpenChange={(open) => (open ? setDialogOpen(true) : closeDialog())}
|
|
onSaved={onChanged}
|
|
/>
|
|
) : null}
|
|
{mod.type === 'CDN_CIDRS' ? (
|
|
<ModuleCdnSourceDialog
|
|
open={dialogOpen}
|
|
moduleId={moduleId}
|
|
edit={editCdn}
|
|
communities={communities}
|
|
onOpenChange={(open) => (open ? setDialogOpen(true) : closeDialog())}
|
|
onSaved={onChanged}
|
|
/>
|
|
) : null}
|
|
{mod.type === 'AS_PREFIXES' ? (
|
|
<ModuleAsEntryDialog
|
|
open={dialogOpen}
|
|
moduleId={moduleId}
|
|
edit={editAs}
|
|
communities={communities}
|
|
onOpenChange={(open) => (open ? setDialogOpen(true) : closeDialog())}
|
|
onSaved={onChanged}
|
|
/>
|
|
) : null}
|
|
|
|
<ConfirmDialog
|
|
open={deleteTarget !== null}
|
|
onOpenChange={(open) => !open && setDeleteTarget(null)}
|
|
title="Удалить запись?"
|
|
description={deleteDescription(deleteTarget)}
|
|
confirmLabel="Удалить"
|
|
confirmLoadingLabel="Удаление…"
|
|
destructive
|
|
confirmLoading={deleting}
|
|
onConfirm={() => void confirmDelete()}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
function deleteDescription(target: DeleteTarget | null): string {
|
|
if (!target) return ''
|
|
switch (target.kind) {
|
|
case 'domain':
|
|
return target.entry.fqdn
|
|
case 'ip-range':
|
|
return target.entry.prefix
|
|
case 'cdn':
|
|
return target.entry.url
|
|
case 'as':
|
|
return `AS${target.entry.asn}`
|
|
}
|
|
}
|