Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
144d342c16 | ||
|
|
0af37d55c4 | ||
|
|
78f2ecc246 | ||
|
|
8c97445f7e | ||
|
|
0ea5b3b738 | ||
|
|
66b785f7cb | ||
|
|
cb14194a5f | ||
|
|
9c38e1bc57 | ||
|
|
4ac99e43ae | ||
|
|
f26c15401c |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"pid": 44608,
|
"pid": 48400,
|
||||||
"version": "0.9.9",
|
"version": "0.9.9",
|
||||||
"socketPath": "\\\\.\\pipe\\codegraph-97b92efdcc5351da",
|
"socketPath": "\\\\.\\pipe\\codegraph-97b92efdcc5351da",
|
||||||
"startedAt": 1781240018712
|
"startedAt": 1783060842523
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ UI-правила репозитория: `.cursor/rules/web-shadcn.mdc` (MCP +
|
|||||||
1. **Контракт HTTP** — `docs/openapi.yaml` (не Context7).
|
1. **Контракт HTTP** — `docs/openapi.yaml` (не Context7).
|
||||||
2. **Context7** — синтаксис и API библиотек из таблицы.
|
2. **Context7** — синтаксис и API библиотек из таблицы.
|
||||||
3. **Локальные docs** — `docs/`, `web/README.md`, `AGENTS.md`.
|
3. **Локальные docs** — `docs/`, `web/README.md`, `AGENTS.md`.
|
||||||
4. **Официальный сайт** — BIRD: https://bird.network.cz/?get_doc (если Context7 не покрыл кейс).
|
4. **Официальный сайт** — BIRD: https://bird.nic.cz/?get_doc (если Context7 не покрыл кейс).
|
||||||
|
|
||||||
## Примеры запросов
|
## Примеры запросов
|
||||||
|
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ alwaysApply: true
|
|||||||
| OpenAPI / problem+json | `docs/openapi.yaml`, RFC 9457 |
|
| OpenAPI / problem+json | `docs/openapi.yaml`, RFC 9457 |
|
||||||
| Svelte / Kit | https://svelte.dev/docs , https://kit.svelte.dev/docs |
|
| Svelte / Kit | https://svelte.dev/docs , https://kit.svelte.dev/docs |
|
||||||
| shadcn-svelte | https://shadcn-svelte.com/docs |
|
| shadcn-svelte | https://shadcn-svelte.com/docs |
|
||||||
| BIRD 2 | https://bird.network.cz/?get_doc |
|
| BIRD 2 | https://bird.nic.cz/?get_doc |
|
||||||
| Prometheus Go | https://pkg.go.dev/github.com/prometheus/client_golang |
|
| Prometheus Go | https://pkg.go.dev/github.com/prometheus/client_golang |
|
||||||
|
|
||||||
**DOC-SYNC-01** | MUST | Новый API библиотеки — сверка версии в `go.mod`/`package.json` с официальной документацией.
|
**DOC-SYNC-01** | MUST | Новый API библиотеки — сверка версии в `go.mod`/`package.json` с официальной документацией.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ alwaysApply: false
|
|||||||
| Параметры BIRD tenant | Global settings: `bird_router_id`, `bird_local_asn`, … (`docs/manual.md`) |
|
| Параметры BIRD tenant | Global settings: `bird_router_id`, `bird_local_asn`, … (`docs/manual.md`) |
|
||||||
| BGP peers | `BGPPeer` + `ParsePeerNeighbor` |
|
| BGP peers | `BGPPeer` + `ParsePeerNeighbor` |
|
||||||
|
|
||||||
**BIRD2 docs:** https://bird.network.cz/?get_doc
|
**BIRD2 docs:** https://bird.nic.cz/?get_doc
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ alwaysApply: false
|
|||||||
|
|
||||||
## Documentation Sync
|
## Documentation Sync
|
||||||
|
|
||||||
**DOC-SYNC-05** | MUST | BIRD — https://bird.network.cz/?get_doc
|
**DOC-SYNC-05** | MUST | BIRD — https://bird.nic.cz/?get_doc
|
||||||
**DOC-SYNC-08** | MUST | BGP policy — RFC 4271, 4760, 7454 + BIRD docs + `birdfmt`
|
**DOC-SYNC-08** | MUST | BGP policy — RFC 4271, 4760, 7454 + BIRD docs + `birdfmt`
|
||||||
**DOC-SYNC-09** | MUST | CIDR — https://pkg.go.dev/net/netip ; примеры — RFC 5737, 3849
|
**DOC-SYNC-09** | MUST | CIDR — https://pkg.go.dev/net/netip ; примеры — RFC 5737, 3849
|
||||||
|
|
||||||
|
|||||||
@@ -167,14 +167,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: pnpm/action-setup@v4
|
|
||||||
with:
|
|
||||||
version: 10
|
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: "22"
|
node-version: "22"
|
||||||
cache: pnpm
|
- name: Enable pnpm via corepack
|
||||||
cache-dependency-path: pnpm-lock.yaml
|
run: corepack enable
|
||||||
- name: pnpm install, typecheck, lint, build
|
- name: pnpm install, typecheck, lint, build
|
||||||
run: |
|
run: |
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import { useMemo } from 'react'
|
||||||
|
|
||||||
|
import { Label } from '@evobgp/ui/components/label'
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@evobgp/ui/components/select'
|
||||||
|
|
||||||
|
import {
|
||||||
|
NONE_OPTION,
|
||||||
|
communityOptionLabel,
|
||||||
|
fromNullableSelect,
|
||||||
|
nullableSelectValue,
|
||||||
|
} from '@/lib/modules/helpers'
|
||||||
|
import type { BgpCommunity } from '@/types/api'
|
||||||
|
|
||||||
|
interface CommunitySelectProps {
|
||||||
|
id?: string
|
||||||
|
label?: string
|
||||||
|
value: string | null
|
||||||
|
onValueChange: (value: string | null) => void
|
||||||
|
communities: BgpCommunity[]
|
||||||
|
nullable?: boolean
|
||||||
|
placeholder?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CommunitySelect({
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
onValueChange,
|
||||||
|
communities,
|
||||||
|
nullable = false,
|
||||||
|
placeholder = 'Выберите community',
|
||||||
|
}: CommunitySelectProps) {
|
||||||
|
const items = useMemo(() => {
|
||||||
|
const communityItems = communities.map((c) => ({
|
||||||
|
value: c.id,
|
||||||
|
label: communityOptionLabel(c),
|
||||||
|
}))
|
||||||
|
if (nullable) {
|
||||||
|
return [{ value: NONE_OPTION, label: 'Не выбрано' }, ...communityItems]
|
||||||
|
}
|
||||||
|
return communityItems
|
||||||
|
}, [communities, nullable])
|
||||||
|
|
||||||
|
const selectValue = nullable ? nullableSelectValue(value) : (value ?? '')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
{label ? <Label htmlFor={id}>{label}</Label> : null}
|
||||||
|
<Select
|
||||||
|
items={items}
|
||||||
|
value={selectValue}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
if (!v) return
|
||||||
|
onValueChange(nullable ? fromNullableSelect(v) : v)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SelectTrigger id={id} className="w-full">
|
||||||
|
<SelectValue placeholder={placeholder} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{items.map((item) => (
|
||||||
|
<SelectItem key={item.value} value={item.value}>
|
||||||
|
{item.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@evobgp/ui/components/dialog'
|
||||||
|
import { Input } from '@evobgp/ui/components/input'
|
||||||
|
import { Label } from '@evobgp/ui/components/label'
|
||||||
|
|
||||||
|
import { LoadingButton } from '@/components/loading-button'
|
||||||
|
import { CommunitySelect } from '@/components/modules/community-select'
|
||||||
|
import { ApiError, apiMutate } from '@/lib/api-client'
|
||||||
|
import type { AsEntry, AsEntryCreate, AsEntryPatch, BgpCommunity } from '@/types/api'
|
||||||
|
|
||||||
|
interface ModuleAsEntryDialogProps {
|
||||||
|
open: boolean
|
||||||
|
moduleId: string
|
||||||
|
edit: AsEntry | null
|
||||||
|
communities: BgpCommunity[]
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
onSaved: () => void | Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ModuleAsEntryDialog({
|
||||||
|
open,
|
||||||
|
moduleId,
|
||||||
|
edit,
|
||||||
|
communities,
|
||||||
|
onOpenChange,
|
||||||
|
onSaved,
|
||||||
|
}: ModuleAsEntryDialogProps) {
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [form, setForm] = useState<AsEntryCreate>({ asn: 0, community_id: null })
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return
|
||||||
|
setForm(
|
||||||
|
edit
|
||||||
|
? { asn: edit.asn, community_id: edit.community_id }
|
||||||
|
: { asn: 0, community_id: null },
|
||||||
|
)
|
||||||
|
}, [open, edit])
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const asn = Number(form.asn)
|
||||||
|
if (!Number.isFinite(asn) || asn < 1 || asn > 4294967295) {
|
||||||
|
toast.error('Укажите корректный ASN (1–4294967295)')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setSaving(true)
|
||||||
|
try {
|
||||||
|
const body: AsEntryCreate | AsEntryPatch = { asn, community_id: form.community_id }
|
||||||
|
if (edit) {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/as-entries/${edit.id}`, 'PATCH', body)
|
||||||
|
toast.success('Запись обновлена')
|
||||||
|
} else {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/as-entries`, 'POST', body as AsEntryCreate)
|
||||||
|
toast.success('Запись добавлена')
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
await onSaved()
|
||||||
|
} catch (e) {
|
||||||
|
toast.error(e instanceof ApiError ? e.message : String(e))
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{edit ? 'Редактировать запись' : 'Новая AS-запись'}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Номер автономной системы и community для политики анонса.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="space-y-4 py-2">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label htmlFor="as-asn">ASN</Label>
|
||||||
|
<Input
|
||||||
|
id="as-asn"
|
||||||
|
type="number"
|
||||||
|
placeholder="12345"
|
||||||
|
value={form.asn || ''}
|
||||||
|
min={1}
|
||||||
|
max={4294967295}
|
||||||
|
onChange={(e) => setForm((s) => ({ ...s, asn: Number(e.target.value) }))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<CommunitySelect
|
||||||
|
id="as-comm"
|
||||||
|
label="Community"
|
||||||
|
value={form.community_id ?? null}
|
||||||
|
onValueChange={(v) => setForm((s) => ({ ...s, community_id: v }))}
|
||||||
|
communities={communities}
|
||||||
|
nullable
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<LoadingButton variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
|
Отмена
|
||||||
|
</LoadingButton>
|
||||||
|
<LoadingButton loading={saving} onClick={() => void save()}>
|
||||||
|
{edit ? 'Сохранить' : 'Добавить'}
|
||||||
|
</LoadingButton>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@evobgp/ui/components/dialog'
|
||||||
|
import { Input } from '@evobgp/ui/components/input'
|
||||||
|
import { Label } from '@evobgp/ui/components/label'
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@evobgp/ui/components/select'
|
||||||
|
import { Button } from '@evobgp/ui/components/button'
|
||||||
|
|
||||||
|
import { LoadingButton } from '@/components/loading-button'
|
||||||
|
import { CommunitySelect } from '@/components/modules/community-select'
|
||||||
|
import { ApiError, apiMutate } from '@/lib/api-client'
|
||||||
|
import { normalizeCdnSourceKind } from '@/lib/modules/helpers'
|
||||||
|
import type { BgpCommunity, CdnPreviewResponse, CdnSource, CdnSourceCreate } from '@/types/api'
|
||||||
|
|
||||||
|
const CDN_KIND_ITEMS = [
|
||||||
|
{ value: 'plaintext', label: 'plaintext' },
|
||||||
|
{ value: 'json', label: 'json' },
|
||||||
|
] as const
|
||||||
|
|
||||||
|
interface ModuleCdnSourceDialogProps {
|
||||||
|
open: boolean
|
||||||
|
moduleId: string
|
||||||
|
edit: CdnSource | null
|
||||||
|
communities: BgpCommunity[]
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
onSaved: () => void | Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
type CdnForm = CdnSourceCreate & { refresh_interval_sec?: number | null }
|
||||||
|
|
||||||
|
export function ModuleCdnSourceDialog({
|
||||||
|
open,
|
||||||
|
moduleId,
|
||||||
|
edit,
|
||||||
|
communities,
|
||||||
|
onOpenChange,
|
||||||
|
onSaved,
|
||||||
|
}: ModuleCdnSourceDialogProps) {
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [previewLoading, setPreviewLoading] = useState(false)
|
||||||
|
const [previewItems, setPreviewItems] = useState<string[]>([])
|
||||||
|
const [previewTotal, setPreviewTotal] = useState(0)
|
||||||
|
const [previewTruncated, setPreviewTruncated] = useState(false)
|
||||||
|
const [previewError, setPreviewError] = useState<string | null>(null)
|
||||||
|
const [previewOk, setPreviewOk] = useState(false)
|
||||||
|
const [form, setForm] = useState<CdnForm>({
|
||||||
|
url: '',
|
||||||
|
source_kind: 'plaintext',
|
||||||
|
prefix_path: '',
|
||||||
|
community_id: null,
|
||||||
|
})
|
||||||
|
|
||||||
|
const kindItems = useMemo(() => [...CDN_KIND_ITEMS], [])
|
||||||
|
|
||||||
|
function clearPreview() {
|
||||||
|
setPreviewLoading(false)
|
||||||
|
setPreviewItems([])
|
||||||
|
setPreviewTotal(0)
|
||||||
|
setPreviewTruncated(false)
|
||||||
|
setPreviewError(null)
|
||||||
|
setPreviewOk(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) {
|
||||||
|
clearPreview()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setForm(
|
||||||
|
edit
|
||||||
|
? {
|
||||||
|
url: edit.url,
|
||||||
|
source_kind: normalizeCdnSourceKind(edit.source_kind),
|
||||||
|
prefix_path: edit.prefix_path ?? '',
|
||||||
|
community_id: edit.community_id,
|
||||||
|
refresh_interval_sec: edit.refresh_interval_sec,
|
||||||
|
}
|
||||||
|
: { url: '', source_kind: 'plaintext', prefix_path: '', community_id: null },
|
||||||
|
)
|
||||||
|
clearPreview()
|
||||||
|
}, [open, edit])
|
||||||
|
|
||||||
|
async function previewCdn() {
|
||||||
|
const urlTrim = form.url.trim()
|
||||||
|
if (!urlTrim) {
|
||||||
|
toast.error('Укажите URL')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setPreviewLoading(true)
|
||||||
|
setPreviewError(null)
|
||||||
|
setPreviewOk(false)
|
||||||
|
try {
|
||||||
|
const res = await apiMutate<CdnPreviewResponse>(
|
||||||
|
`/v1/modules/${moduleId}/cdn-sources/preview`,
|
||||||
|
'POST',
|
||||||
|
{
|
||||||
|
url: urlTrim,
|
||||||
|
source_kind: form.source_kind,
|
||||||
|
prefix_path: form.prefix_path?.trim() ?? '',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
setPreviewItems(res.items)
|
||||||
|
setPreviewTotal(res.total)
|
||||||
|
setPreviewTruncated(res.truncated)
|
||||||
|
setPreviewOk(true)
|
||||||
|
} catch (e) {
|
||||||
|
setPreviewError(e instanceof ApiError ? e.message : String(e))
|
||||||
|
setPreviewItems([])
|
||||||
|
setPreviewTotal(0)
|
||||||
|
setPreviewTruncated(false)
|
||||||
|
setPreviewOk(false)
|
||||||
|
} finally {
|
||||||
|
setPreviewLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const urlTrim = form.url.trim()
|
||||||
|
if (!urlTrim) {
|
||||||
|
toast.error('Укажите URL')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setSaving(true)
|
||||||
|
try {
|
||||||
|
const body = {
|
||||||
|
...form,
|
||||||
|
url: urlTrim,
|
||||||
|
source_kind: form.source_kind,
|
||||||
|
prefix_path: form.prefix_path?.trim() ?? '',
|
||||||
|
}
|
||||||
|
if (edit) {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/cdn-sources/${edit.id}`, 'PATCH', body)
|
||||||
|
toast.success('Источник обновлён')
|
||||||
|
} else {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/cdn-sources`, 'POST', body)
|
||||||
|
toast.success('Источник добавлен')
|
||||||
|
}
|
||||||
|
clearPreview()
|
||||||
|
onOpenChange(false)
|
||||||
|
await onSaved()
|
||||||
|
} catch (e) {
|
||||||
|
toast.error(e instanceof ApiError ? e.message : String(e))
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-lg">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{edit ? 'Редактировать источник' : 'Новый CDN-источник'}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="space-y-4 py-2">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label htmlFor="cdn-url">URL</Label>
|
||||||
|
<Input
|
||||||
|
id="cdn-url"
|
||||||
|
placeholder="https://example.com/list.txt"
|
||||||
|
value={form.url}
|
||||||
|
onChange={(e) => setForm((s) => ({ ...s, url: e.target.value }))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label htmlFor="cdn-kind">Тип источника</Label>
|
||||||
|
<Select
|
||||||
|
items={kindItems}
|
||||||
|
value={form.source_kind}
|
||||||
|
onValueChange={(v) => v && setForm((s) => ({ ...s, source_kind: v }))}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="cdn-kind" className="w-full">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{kindItems.map((item) => (
|
||||||
|
<SelectItem key={item.value} value={item.value}>
|
||||||
|
{item.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label htmlFor="cdn-prefix-path">JSON path (prefix_path)</Label>
|
||||||
|
<Input
|
||||||
|
id="cdn-prefix-path"
|
||||||
|
placeholder="напр. prefixes[] или data.items[].cidr"
|
||||||
|
value={form.prefix_path ?? ''}
|
||||||
|
onChange={(e) => setForm((s) => ({ ...s, prefix_path: e.target.value }))}
|
||||||
|
/>
|
||||||
|
{form.source_kind === 'json' && !form.prefix_path?.trim() ? (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Для JSON укажите путь к полям с CIDR; пустой путь может не дать префиксов.
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<CommunitySelect
|
||||||
|
id="cdn-comm"
|
||||||
|
label="Community"
|
||||||
|
value={form.community_id ?? null}
|
||||||
|
onValueChange={(v) => setForm((s) => ({ ...s, community_id: v }))}
|
||||||
|
communities={communities}
|
||||||
|
nullable
|
||||||
|
/>
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label htmlFor="cdn-interval">Интервал обновления (сек)</Label>
|
||||||
|
<Input
|
||||||
|
id="cdn-interval"
|
||||||
|
type="number"
|
||||||
|
placeholder="3600"
|
||||||
|
value={form.refresh_interval_sec ?? ''}
|
||||||
|
onChange={(e) =>
|
||||||
|
setForm((s) => ({
|
||||||
|
...s,
|
||||||
|
refresh_interval_sec: e.target.value ? Number(e.target.value) : null,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2 rounded-lg border border-border p-3">
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => void previewCdn()}
|
||||||
|
disabled={previewLoading}
|
||||||
|
>
|
||||||
|
{previewLoading ? 'Загрузка…' : 'Предпросмотр'}
|
||||||
|
</Button>
|
||||||
|
{previewError ? (
|
||||||
|
<span className="text-sm text-destructive">{previewError}</span>
|
||||||
|
) : previewOk ? (
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
Всего: {previewTotal}
|
||||||
|
{previewTruncated ? (
|
||||||
|
<span className="text-amber-600 dark:text-amber-500"> (обрезано)</span>
|
||||||
|
) : null}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
{previewItems.length > 0 ? (
|
||||||
|
<ul className="max-h-48 overflow-y-auto rounded-md border bg-muted/40 p-2 font-mono text-xs">
|
||||||
|
{previewItems.map((item, i) => (
|
||||||
|
<li key={`${i}-${item}`} className="py-0.5">
|
||||||
|
{item}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<LoadingButton variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
|
Отмена
|
||||||
|
</LoadingButton>
|
||||||
|
<LoadingButton loading={saving} onClick={() => void save()}>
|
||||||
|
{edit ? 'Сохранить' : 'Добавить'}
|
||||||
|
</LoadingButton>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@evobgp/ui/components/dialog'
|
||||||
|
import { Input } from '@evobgp/ui/components/input'
|
||||||
|
import { Label } from '@evobgp/ui/components/label'
|
||||||
|
|
||||||
|
import { LoadingButton } from '@/components/loading-button'
|
||||||
|
import { CommunitySelect } from '@/components/modules/community-select'
|
||||||
|
import { ApiError, apiMutate } from '@/lib/api-client'
|
||||||
|
import type { BgpCommunity, DomainEntry, DomainEntryCreate } from '@/types/api'
|
||||||
|
|
||||||
|
interface ModuleDomainEntryDialogProps {
|
||||||
|
open: boolean
|
||||||
|
moduleId: string
|
||||||
|
edit: DomainEntry | null
|
||||||
|
communities: BgpCommunity[]
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
onSaved: () => void | Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ModuleDomainEntryDialog({
|
||||||
|
open,
|
||||||
|
moduleId,
|
||||||
|
edit,
|
||||||
|
communities,
|
||||||
|
onOpenChange,
|
||||||
|
onSaved,
|
||||||
|
}: ModuleDomainEntryDialogProps) {
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [form, setForm] = useState<DomainEntryCreate>({ fqdn: '', community_id: null })
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return
|
||||||
|
setForm(
|
||||||
|
edit
|
||||||
|
? { fqdn: edit.fqdn, community_id: edit.community_id }
|
||||||
|
: { fqdn: '', community_id: null },
|
||||||
|
)
|
||||||
|
}, [open, edit])
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
if (!form.fqdn.trim()) {
|
||||||
|
toast.error('Укажите FQDN')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setSaving(true)
|
||||||
|
try {
|
||||||
|
const body = { fqdn: form.fqdn.trim(), community_id: form.community_id }
|
||||||
|
if (edit) {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/domain-entries/${edit.id}`, 'PATCH', body)
|
||||||
|
toast.success('Домен обновлён')
|
||||||
|
} else {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/domain-entries`, 'POST', body)
|
||||||
|
toast.success('Домен добавлен')
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
await onSaved()
|
||||||
|
} catch (e) {
|
||||||
|
toast.error(e instanceof ApiError ? e.message : String(e))
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{edit ? 'Редактировать домен' : 'Новый домен'}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="space-y-4 py-2">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label htmlFor="dom-fqdn">FQDN</Label>
|
||||||
|
<Input
|
||||||
|
id="dom-fqdn"
|
||||||
|
placeholder="example.com"
|
||||||
|
value={form.fqdn}
|
||||||
|
onChange={(e) => setForm((s) => ({ ...s, fqdn: e.target.value }))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<CommunitySelect
|
||||||
|
id="dom-comm"
|
||||||
|
label="Community"
|
||||||
|
value={form.community_id ?? null}
|
||||||
|
onValueChange={(v) => setForm((s) => ({ ...s, community_id: v }))}
|
||||||
|
communities={communities}
|
||||||
|
nullable
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<LoadingButton variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
|
Отмена
|
||||||
|
</LoadingButton>
|
||||||
|
<LoadingButton loading={saving} onClick={() => void save()}>
|
||||||
|
{edit ? 'Сохранить' : 'Добавить'}
|
||||||
|
</LoadingButton>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,437 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { Pencil, Plus, Trash2 } from 'lucide-react'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@evobgp/ui/components/alert-dialog'
|
||||||
|
import { Button } from '@evobgp/ui/components/button'
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@evobgp/ui/components/card'
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableBody,
|
||||||
|
TableCell,
|
||||||
|
TableHead,
|
||||||
|
TableHeader,
|
||||||
|
TableRow,
|
||||||
|
} from '@evobgp/ui/components/table'
|
||||||
|
|
||||||
|
import { QueryState } from '@/components/query-state'
|
||||||
|
import { TableSkeleton } from '@/components/skeletons'
|
||||||
|
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 { communityLabel } from '@/lib/modules/helpers'
|
||||||
|
import { formatDateTime } from '@/lib/modules/display'
|
||||||
|
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 =
|
||||||
|
| { kind: 'domain'; entry: DomainEntry }
|
||||||
|
| { kind: 'ip-range'; entry: IpRangeEntry }
|
||||||
|
| { kind: 'cdn'; entry: CdnSource }
|
||||||
|
| { kind: 'as'; entry: AsEntry }
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="flex flex-col gap-3 border-b py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<CardTitle className="text-base">{meta.title}</CardTitle>
|
||||||
|
<CardDescription>{meta.description}</CardDescription>
|
||||||
|
</div>
|
||||||
|
<div className="flex shrink-0 flex-wrap items-center justify-end gap-2 self-start sm:self-auto">
|
||||||
|
<Button size="sm" onClick={openCreate}>
|
||||||
|
<Plus />
|
||||||
|
Добавить
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="p-0">
|
||||||
|
<QueryState
|
||||||
|
data={items}
|
||||||
|
isLoading={isLoading}
|
||||||
|
isError={isError}
|
||||||
|
error={error}
|
||||||
|
empty={items.length === 0}
|
||||||
|
emptyTitle={meta.emptyTitle}
|
||||||
|
emptyDescription={meta.emptyDescription}
|
||||||
|
skeleton={<TableSkeleton rows={5} cols={3} />}
|
||||||
|
onRetry={onRetry}
|
||||||
|
>
|
||||||
|
{(rows) => (
|
||||||
|
<EntriesTable
|
||||||
|
mod={mod}
|
||||||
|
rows={rows}
|
||||||
|
communities={communities}
|
||||||
|
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}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</QueryState>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{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}
|
||||||
|
|
||||||
|
<AlertDialog open={deleteTarget !== null} onOpenChange={(open) => !open && setDeleteTarget(null)}>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Удалить запись?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>{deleteDescription(deleteTarget)}</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={deleting}>Отмена</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
variant="destructive"
|
||||||
|
disabled={deleting}
|
||||||
|
onClick={() => void confirmDelete()}
|
||||||
|
>
|
||||||
|
{deleting ? 'Удаление…' : 'Удалить'}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function EntriesTable({
|
||||||
|
mod,
|
||||||
|
rows,
|
||||||
|
communities,
|
||||||
|
onEdit,
|
||||||
|
onDelete,
|
||||||
|
}: {
|
||||||
|
mod: ModuleRow
|
||||||
|
rows: Record<string, unknown>[]
|
||||||
|
communities: BgpCommunity[]
|
||||||
|
onEdit: (target: DeleteTarget) => void
|
||||||
|
onDelete: (target: DeleteTarget) => void
|
||||||
|
}) {
|
||||||
|
if (mod.type === 'DOMAINS') {
|
||||||
|
const entries = rows as unknown as DomainEntry[]
|
||||||
|
return (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>FQDN</TableHead>
|
||||||
|
<TableHead>Community</TableHead>
|
||||||
|
<TableHead className="w-20" />
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{entries.map((entry) => (
|
||||||
|
<TableRow key={entry.id}>
|
||||||
|
<TableCell className="font-mono text-sm">{entry.fqdn}</TableCell>
|
||||||
|
<TableCell className="text-sm text-muted-foreground">
|
||||||
|
{communityLabel(entry.community_id, communities)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<RowActions
|
||||||
|
onEdit={() => onEdit({ kind: 'domain', entry })}
|
||||||
|
onDelete={() => onDelete({ kind: 'domain', entry })}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mod.type === 'IP_RANGES') {
|
||||||
|
const entries = rows as unknown as IpRangeEntry[]
|
||||||
|
return (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Префикс (CIDR)</TableHead>
|
||||||
|
<TableHead>Community</TableHead>
|
||||||
|
<TableHead className="w-20" />
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{entries.map((entry) => (
|
||||||
|
<TableRow key={entry.id}>
|
||||||
|
<TableCell className="font-mono text-sm">{entry.prefix}</TableCell>
|
||||||
|
<TableCell className="text-sm text-muted-foreground">
|
||||||
|
{communityLabel(entry.community_id, communities)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<RowActions
|
||||||
|
onEdit={() => onEdit({ kind: 'ip-range', entry })}
|
||||||
|
onDelete={() => onDelete({ kind: 'ip-range', entry })}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mod.type === 'CDN_CIDRS') {
|
||||||
|
const entries = rows as unknown as CdnSource[]
|
||||||
|
return (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>URL</TableHead>
|
||||||
|
<TableHead>Тип</TableHead>
|
||||||
|
<TableHead>Community</TableHead>
|
||||||
|
<TableHead>Обновлено</TableHead>
|
||||||
|
<TableHead className="w-20" />
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{entries.map((entry) => (
|
||||||
|
<TableRow key={entry.id}>
|
||||||
|
<TableCell className="max-w-xs truncate font-mono text-xs">{entry.url}</TableCell>
|
||||||
|
<TableCell className="text-sm">{entry.source_kind}</TableCell>
|
||||||
|
<TableCell className="text-sm text-muted-foreground">
|
||||||
|
{communityLabel(entry.community_id, communities)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-xs text-muted-foreground">
|
||||||
|
{formatDateTime(entry.last_refreshed_at)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<RowActions
|
||||||
|
onEdit={() => onEdit({ kind: 'cdn', entry })}
|
||||||
|
onDelete={() => onDelete({ kind: 'cdn', entry })}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries = rows as unknown as AsEntry[]
|
||||||
|
return (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>ASN</TableHead>
|
||||||
|
<TableHead>Имя</TableHead>
|
||||||
|
<TableHead>Префиксов</TableHead>
|
||||||
|
<TableHead>Community</TableHead>
|
||||||
|
<TableHead className="w-20" />
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{entries.map((entry) => (
|
||||||
|
<TableRow key={entry.id}>
|
||||||
|
<TableCell className="font-mono text-sm">{entry.asn}</TableCell>
|
||||||
|
<TableCell className="text-sm">{entry.asn_name ?? '—'}</TableCell>
|
||||||
|
<TableCell className="font-mono text-sm">{entry.prefix_count ?? '—'}</TableCell>
|
||||||
|
<TableCell className="text-sm text-muted-foreground">
|
||||||
|
{communityLabel(entry.community_id, communities)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<RowActions
|
||||||
|
onEdit={() => onEdit({ kind: 'as', entry })}
|
||||||
|
onDelete={() => onDelete({ kind: 'as', entry })}
|
||||||
|
/>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function RowActions({ onEdit, onDelete }: { onEdit: () => void; onDelete: () => void }) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-end gap-1">
|
||||||
|
<Button variant="ghost" size="icon-sm" onClick={onEdit} aria-label="Редактировать">
|
||||||
|
<Pencil className="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon-sm"
|
||||||
|
className="text-destructive"
|
||||||
|
onClick={onDelete}
|
||||||
|
aria-label="Удалить"
|
||||||
|
>
|
||||||
|
<Trash2 className="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@evobgp/ui/components/dialog'
|
||||||
|
import { Input } from '@evobgp/ui/components/input'
|
||||||
|
import { Label } from '@evobgp/ui/components/label'
|
||||||
|
|
||||||
|
import { LoadingButton } from '@/components/loading-button'
|
||||||
|
import { CommunitySelect } from '@/components/modules/community-select'
|
||||||
|
import { ApiError, apiMutate } from '@/lib/api-client'
|
||||||
|
import type { BgpCommunity, IpRangeEntry, IpRangeEntryCreate } from '@/types/api'
|
||||||
|
|
||||||
|
interface ModuleIpRangeEntryDialogProps {
|
||||||
|
open: boolean
|
||||||
|
moduleId: string
|
||||||
|
edit: IpRangeEntry | null
|
||||||
|
communities: BgpCommunity[]
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
onSaved: () => void | Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ModuleIpRangeEntryDialog({
|
||||||
|
open,
|
||||||
|
moduleId,
|
||||||
|
edit,
|
||||||
|
communities,
|
||||||
|
onOpenChange,
|
||||||
|
onSaved,
|
||||||
|
}: ModuleIpRangeEntryDialogProps) {
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [form, setForm] = useState<IpRangeEntryCreate>({ prefix: '', community_id: '' })
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return
|
||||||
|
setForm(
|
||||||
|
edit
|
||||||
|
? { prefix: edit.prefix, community_id: edit.community_id }
|
||||||
|
: { prefix: '', community_id: '' },
|
||||||
|
)
|
||||||
|
}, [open, edit])
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
if (!form.prefix.trim() || !form.community_id) {
|
||||||
|
toast.error('Укажите префикс и community')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setSaving(true)
|
||||||
|
try {
|
||||||
|
const body = { prefix: form.prefix.trim(), community_id: form.community_id }
|
||||||
|
if (edit) {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/ip-range-entries/${edit.id}`, 'PATCH', body)
|
||||||
|
toast.success('Диапазон обновлён')
|
||||||
|
} else {
|
||||||
|
await apiMutate(`/v1/modules/${moduleId}/ip-range-entries`, 'POST', body)
|
||||||
|
toast.success('Диапазон добавлен')
|
||||||
|
}
|
||||||
|
onOpenChange(false)
|
||||||
|
await onSaved()
|
||||||
|
} catch (e) {
|
||||||
|
toast.error(e instanceof ApiError ? e.message : String(e))
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-sm">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{edit ? 'Редактировать диапазон' : 'Новый IP-диапазон'}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="space-y-4 py-2">
|
||||||
|
<div className="flex flex-col gap-1.5">
|
||||||
|
<Label htmlFor="ip-prefix">Префикс (CIDR)</Label>
|
||||||
|
<Input
|
||||||
|
id="ip-prefix"
|
||||||
|
placeholder="203.0.113.0/24"
|
||||||
|
value={form.prefix}
|
||||||
|
onChange={(e) => setForm((s) => ({ ...s, prefix: e.target.value }))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<CommunitySelect
|
||||||
|
id="ip-comm"
|
||||||
|
label="Community (обязательно)"
|
||||||
|
value={form.community_id || null}
|
||||||
|
onValueChange={(v) => setForm((s) => ({ ...s, community_id: v ?? '' }))}
|
||||||
|
communities={communities}
|
||||||
|
placeholder="Выберите community"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<LoadingButton variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
|
Отмена
|
||||||
|
</LoadingButton>
|
||||||
|
<LoadingButton loading={saving} onClick={() => void save()}>
|
||||||
|
{edit ? 'Сохранить' : 'Добавить'}
|
||||||
|
</LoadingButton>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import {
|
||||||
|
ArrowDownUp,
|
||||||
|
Network,
|
||||||
|
RefreshCw,
|
||||||
|
ShieldCheck,
|
||||||
|
Timer,
|
||||||
|
} from 'lucide-react'
|
||||||
|
|
||||||
|
import { SectionCards, type SectionCardItem } from '@/components/section-cards'
|
||||||
|
import { SectionCardsSkeleton } from '@/components/skeletons'
|
||||||
|
import { formatDateTime, moduleIntervalLabel } from '@/lib/modules/display'
|
||||||
|
import {
|
||||||
|
communityLabel,
|
||||||
|
dohProfileLabel,
|
||||||
|
moduleDohProfileIds,
|
||||||
|
} from '@/lib/modules/helpers'
|
||||||
|
import { dohPolicyRu } from '@/lib/ui-labels'
|
||||||
|
import type { AsEntry, BgpCommunity, DohProfile, ModuleRow } from '@/types/api'
|
||||||
|
|
||||||
|
interface ModuleKpiCardsProps {
|
||||||
|
mod: ModuleRow | null
|
||||||
|
communities: BgpCommunity[]
|
||||||
|
dohProfiles: DohProfile[]
|
||||||
|
asEntries: AsEntry[]
|
||||||
|
loading?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ModuleKpiCards({
|
||||||
|
mod,
|
||||||
|
communities,
|
||||||
|
dohProfiles,
|
||||||
|
asEntries,
|
||||||
|
loading = false,
|
||||||
|
}: ModuleKpiCardsProps) {
|
||||||
|
if (loading || !mod) {
|
||||||
|
return <SectionCardsSkeleton count={5} />
|
||||||
|
}
|
||||||
|
|
||||||
|
const asPrefixTotal = asEntries.reduce((acc, entry) => acc + (entry.prefix_count ?? 0), 0)
|
||||||
|
const dohIds = moduleDohProfileIds(mod)
|
||||||
|
|
||||||
|
const items: SectionCardItem[] = [
|
||||||
|
{
|
||||||
|
label: 'Приоритет',
|
||||||
|
value: String(mod.priority ?? 0),
|
||||||
|
hint: 'порядок в сборке ревизии',
|
||||||
|
icon: <ArrowDownUp className="size-3.5" />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Интервал',
|
||||||
|
value: moduleIntervalLabel(mod),
|
||||||
|
hint: 'refresh_interval_sec / cron',
|
||||||
|
icon: <Timer className="size-3.5" />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'DoH',
|
||||||
|
value: mod.type === 'DOMAINS' ? dohPolicyRu(mod.doh_resolver_policy) : '—',
|
||||||
|
hint:
|
||||||
|
mod.type === 'DOMAINS'
|
||||||
|
? dohIds.length
|
||||||
|
? dohIds.map((id) => dohProfileLabel(id, dohProfiles)).join('; ')
|
||||||
|
: 'Системный DNS'
|
||||||
|
: 'не применимо',
|
||||||
|
icon: <Network className="size-3.5" />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Community по умолч.',
|
||||||
|
value: communityLabel(mod.default_community_id, communities),
|
||||||
|
hint: 'для записей без своего community',
|
||||||
|
icon: <ShieldCheck className="size-3.5" />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Последнее обновление',
|
||||||
|
value: formatDateTime(mod.last_refreshed_at),
|
||||||
|
hint:
|
||||||
|
mod.type === 'AS_PREFIXES'
|
||||||
|
? `ASN: ${asEntries.length}, префиксов: ${asPrefixTotal}`
|
||||||
|
: 'время последнего refresh',
|
||||||
|
icon: <RefreshCw className="size-3.5" />,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
return <SectionCards items={items} />
|
||||||
|
}
|
||||||
@@ -153,6 +153,10 @@ function DataGridPagination(props: DataGridPaginationProps): React.JSX.Element {
|
|||||||
{mergedProps.rowsPerPageLabel}
|
{mergedProps.rowsPerPageLabel}
|
||||||
</div>
|
</div>
|
||||||
<Select
|
<Select
|
||||||
|
items={mergedProps?.sizes?.map((size: number) => ({
|
||||||
|
value: `${size}`,
|
||||||
|
label: `${size}`,
|
||||||
|
}))}
|
||||||
value={`${pageSize}`}
|
value={`${pageSize}`}
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
const newPageSize = Number(value)
|
const newPageSize = Number(value)
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { ModuleRow } from '@/types/api'
|
||||||
|
|
||||||
|
export function formatDateTime(value: string | null | undefined): string {
|
||||||
|
if (typeof value !== 'string' || value.trim().length === 0) return '—'
|
||||||
|
const parsed = new Date(value)
|
||||||
|
if (Number.isNaN(parsed.getTime())) return '—'
|
||||||
|
return parsed.toLocaleString('ru-RU')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moduleIntervalLabel(moduleRow: ModuleRow): string {
|
||||||
|
const cron = typeof moduleRow.cron_expr === 'string' ? moduleRow.cron_expr.trim() : ''
|
||||||
|
const raw = moduleRow.refresh_interval_sec as unknown
|
||||||
|
const interval =
|
||||||
|
typeof raw === 'number'
|
||||||
|
? raw
|
||||||
|
: typeof raw === 'string' && raw.trim().length > 0
|
||||||
|
? Number(raw)
|
||||||
|
: null
|
||||||
|
const intervalLabel = interval !== null && Number.isFinite(interval) ? `${interval}с` : ''
|
||||||
|
if (cron && intervalLabel) return `${intervalLabel} (${cron})`
|
||||||
|
if (cron) return cron
|
||||||
|
if (intervalLabel) return intervalLabel
|
||||||
|
return '—'
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import type { BgpCommunity, DohProfile, ModuleRow } from '@/types/api'
|
||||||
|
|
||||||
|
export const NONE_OPTION = '__none__'
|
||||||
|
|
||||||
|
export function communityLabel(id: string | null | undefined, communities: BgpCommunity[]): string {
|
||||||
|
if (!id) return '—'
|
||||||
|
const c = communities.find((x) => x.id === id)
|
||||||
|
if (!c) return `${id.slice(0, 8)}…`
|
||||||
|
const t = c.title?.trim()
|
||||||
|
return t || c.community
|
||||||
|
}
|
||||||
|
|
||||||
|
export function communityOptionLabel(c: BgpCommunity): string {
|
||||||
|
const t = c.title?.trim()
|
||||||
|
return t || c.community
|
||||||
|
}
|
||||||
|
|
||||||
|
export function nullableSelectValue(value: string | null | undefined): string {
|
||||||
|
if (value === null || value === undefined || value === '') return NONE_OPTION
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fromNullableSelect(value: string): string | null {
|
||||||
|
if (value === NONE_OPTION || value === '') return null
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moduleDohProfileIds(modRow: ModuleRow | null): string[] {
|
||||||
|
if (!modRow) return []
|
||||||
|
if (modRow.doh_profile_ids?.length) return modRow.doh_profile_ids
|
||||||
|
return modRow.doh_profile_id ? [modRow.doh_profile_id] : []
|
||||||
|
}
|
||||||
|
|
||||||
|
export function dohProfileLabel(id: string, dohProfiles: DohProfile[]): string {
|
||||||
|
const p = dohProfiles.find((d) => d.id === id)
|
||||||
|
return p ? (p.name?.trim() ? `${p.name} (${p.url})` : p.url) : `${id.slice(0, 8)}…`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeCdnSourceKind(k: string): 'plaintext' | 'json' {
|
||||||
|
return k.trim().toLowerCase() === 'json' ? 'json' : 'plaintext'
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import type { DohResolverPolicy } from '@/types/api'
|
||||||
|
|
||||||
|
export function dohPolicyRu(policy: DohResolverPolicy | string | null | undefined): string {
|
||||||
|
switch (policy) {
|
||||||
|
case 'primary_only':
|
||||||
|
return 'Только первый'
|
||||||
|
case 'failover':
|
||||||
|
return 'Резервирование'
|
||||||
|
case 'union':
|
||||||
|
return 'Объединение'
|
||||||
|
default:
|
||||||
|
return 'Только первый'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moduleTypeRu(type: string): string {
|
||||||
|
switch (type) {
|
||||||
|
case 'AS_PREFIXES':
|
||||||
|
return 'AS (номера)'
|
||||||
|
case 'CDN_CIDRS':
|
||||||
|
return 'CDN CIDR'
|
||||||
|
case 'DOMAINS':
|
||||||
|
return 'Домены'
|
||||||
|
case 'IP_RANGES':
|
||||||
|
return 'IP-диапазоны'
|
||||||
|
default:
|
||||||
|
return type
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,44 +1,82 @@
|
|||||||
import { createFileRoute, Link } from '@tanstack/react-router'
|
import { createFileRoute, Link } from '@tanstack/react-router'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { ArrowLeft, RefreshCw } from 'lucide-react'
|
import { ArrowLeft, Info, RefreshCw } from 'lucide-react'
|
||||||
|
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from '@evobgp/ui/components/alert'
|
||||||
import { Button } from '@evobgp/ui/components/button'
|
import { Button } from '@evobgp/ui/components/button'
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@evobgp/ui/components/card'
|
|
||||||
import {
|
|
||||||
Table,
|
|
||||||
TableBody,
|
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from '@evobgp/ui/components/table'
|
|
||||||
import { Badge } from '@/components/reui/badge'
|
|
||||||
|
|
||||||
import { PageHeader } from '@/components/page-header'
|
import { PageHeader } from '@/components/page-header'
|
||||||
import { QueryState } from '@/components/query-state'
|
import { QueryState } from '@/components/query-state'
|
||||||
import { TableSkeleton } from '@/components/skeletons'
|
import { TableSkeleton } from '@/components/skeletons'
|
||||||
import { StatusBadge } from '@/components/status-badge'
|
import { StatusBadge } from '@/components/status-badge'
|
||||||
import { moduleDetailQueryOptions, moduleEntriesQueryOptions } from '@/queries/modules'
|
import { ModuleEntriesSection } from '@/components/modules/module-entries-section'
|
||||||
|
import { ModuleKpiCards } from '@/components/modules/module-kpi-cards'
|
||||||
|
import { moduleTypeRu } from '@/lib/ui-labels'
|
||||||
|
import {
|
||||||
|
directoriesCommunitiesQueryOptions,
|
||||||
|
directoriesDohQueryOptions,
|
||||||
|
} from '@/queries/directories'
|
||||||
|
import { moduleDetailQueryOptions, moduleEntriesQueryOptions, modulesKeys } from '@/queries/modules'
|
||||||
|
import type { AsEntry, ModuleRow } from '@/types/api'
|
||||||
|
|
||||||
export const Route = createFileRoute('/_auth/modules/$moduleId')({
|
export const Route = createFileRoute('/_auth/modules/$moduleId')({
|
||||||
component: ModuleDetailComponent,
|
component: ModuleDetailComponent,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function moduleTypeAlert(type: ModuleRow['type']): string {
|
||||||
|
switch (type) {
|
||||||
|
case 'AS_PREFIXES':
|
||||||
|
return 'Модуль AS получает префиксы через RIPEstat по указанным ASN. После refresh счётчики префиксов обновляются в таблице записей.'
|
||||||
|
case 'CDN_CIDRS':
|
||||||
|
return 'Модуль CDN скачивает списки CIDR по URL (plaintext или JSON). Используйте предпросмотр при добавлении источника.'
|
||||||
|
case 'DOMAINS':
|
||||||
|
return 'Модуль доменов резолвит FQDN через DoH-профили и конвертирует IP в префиксы. Политика и профили настраиваются в редактировании модуля.'
|
||||||
|
case 'IP_RANGES':
|
||||||
|
return 'Модуль IP-диапазонов использует статические CIDR без внешнего refresh (сервер может вернуть 204). Записи участвуют в агрегации напрямую.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function ModuleDetailComponent() {
|
function ModuleDetailComponent() {
|
||||||
const { moduleId } = Route.useParams()
|
const { moduleId } = Route.useParams()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const detail = useQuery(moduleDetailQueryOptions(moduleId))
|
const detail = useQuery(moduleDetailQueryOptions(moduleId))
|
||||||
const mod = detail.data
|
const mod = detail.data
|
||||||
|
|
||||||
|
const communitiesQ = useQuery(directoriesCommunitiesQueryOptions())
|
||||||
|
const dohQ = useQuery(directoriesDohQueryOptions())
|
||||||
|
|
||||||
const entriesQuery = useQuery({
|
const entriesQuery = useQuery({
|
||||||
...moduleEntriesQueryOptions(moduleId, mod?.type ?? 'DOMAINS'),
|
...moduleEntriesQueryOptions(moduleId, mod?.type ?? 'DOMAINS'),
|
||||||
enabled: !!mod,
|
enabled: !!mod,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const asEntriesQ = useQuery({
|
||||||
|
...moduleEntriesQueryOptions(moduleId, 'AS_PREFIXES'),
|
||||||
|
enabled: mod?.type === 'AS_PREFIXES',
|
||||||
|
select: (data) => data.items as unknown as AsEntry[],
|
||||||
|
})
|
||||||
|
|
||||||
|
async function refreshAll() {
|
||||||
|
await Promise.all([detail.refetch(), entriesQuery.refetch(), communitiesQ.refetch(), dohQ.refetch()])
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onEntriesChanged() {
|
||||||
|
await entriesQuery.refetch()
|
||||||
|
if (mod?.type === 'AS_PREFIXES') {
|
||||||
|
await queryClient.invalidateQueries({ queryKey: modulesKeys.asEntries(moduleId) })
|
||||||
|
}
|
||||||
|
await detail.refetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
const communities = communitiesQ.data?.items ?? []
|
||||||
|
const dohProfiles = dohQ.data?.items ?? []
|
||||||
|
const asEntries = mod?.type === 'AS_PREFIXES' ? (asEntriesQ.data ?? []) : []
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={mod?.name ?? moduleId}
|
title={mod?.name ?? moduleId}
|
||||||
description={mod ? `Тип: ${mod.type}` : 'Загрузка модуля…'}
|
description={mod ? `Тип: ${moduleTypeRu(mod.type)} (${mod.type})` : 'Загрузка модуля…'}
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
<Button variant="outline" size="sm" render={<Link to="/modules" />}>
|
<Button variant="outline" size="sm" render={<Link to="/modules" />}>
|
||||||
@@ -48,10 +86,7 @@ function ModuleDetailComponent() {
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => {
|
onClick={() => void refreshAll()}
|
||||||
void detail.refetch()
|
|
||||||
void entriesQuery.refetch()
|
|
||||||
}}
|
|
||||||
disabled={detail.isFetching}
|
disabled={detail.isFetching}
|
||||||
>
|
>
|
||||||
<RefreshCw className={detail.isFetching ? 'animate-spin' : ''} />
|
<RefreshCw className={detail.isFetching ? 'animate-spin' : ''} />
|
||||||
@@ -70,133 +105,43 @@ function ModuleDetailComponent() {
|
|||||||
onRetry={() => detail.refetch()}
|
onRetry={() => detail.refetch()}
|
||||||
>
|
>
|
||||||
{(m) => (
|
{(m) => (
|
||||||
<>
|
<div className="flex flex-col gap-6">
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
<Card>
|
{m.enabled ? (
|
||||||
<CardHeader className="border-b py-3">
|
<StatusBadge status="active" label="включён" />
|
||||||
<CardTitle className="text-base">Параметры</CardTitle>
|
) : (
|
||||||
</CardHeader>
|
<StatusBadge status="paused" label="выключен" />
|
||||||
<CardContent className="grid grid-cols-2 gap-3 p-4 text-sm">
|
)}
|
||||||
<Field label="ID" value={<code className="font-mono text-xs">{m.id}</code>} />
|
|
||||||
<Field label="Тип" value={<Badge variant="outline">{m.type}</Badge>} />
|
|
||||||
<Field label="Приоритет" value={<span className="font-mono">{m.priority}</span>} />
|
|
||||||
<Field
|
|
||||||
label="Состояние"
|
|
||||||
value={
|
|
||||||
m.enabled ? (
|
|
||||||
<StatusBadge status="active" label="включён" />
|
|
||||||
) : (
|
|
||||||
<StatusBadge status="paused" label="выключен" />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Field
|
|
||||||
label="Интервал"
|
|
||||||
value={
|
|
||||||
m.refresh_interval_sec ? `${m.refresh_interval_sec}s` : '—'
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Field
|
|
||||||
label="Cron"
|
|
||||||
value={m.cron_expr ? <code className="font-mono text-xs">{m.cron_expr}</code> : '—'}
|
|
||||||
/>
|
|
||||||
<Field
|
|
||||||
label="Последний рефреш"
|
|
||||||
value={
|
|
||||||
m.last_refreshed_at
|
|
||||||
? new Date(m.last_refreshed_at).toLocaleString('ru-RU')
|
|
||||||
: '—'
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader className="border-b py-3">
|
|
||||||
<CardTitle className="text-base">Маршрутные списки</CardTitle>
|
|
||||||
<CardDescription>Источник префиксов для модуля</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="p-0">
|
|
||||||
<QueryState
|
|
||||||
data={entriesQuery.data?.items}
|
|
||||||
isLoading={entriesQuery.isLoading}
|
|
||||||
isError={entriesQuery.isError}
|
|
||||||
error={entriesQuery.error}
|
|
||||||
empty={(entriesQuery.data?.items?.length ?? 0) === 0}
|
|
||||||
emptyTitle="Записей нет"
|
|
||||||
emptyDescription="Добавьте записи через API или создание ревизии."
|
|
||||||
skeleton={<TableSkeleton rows={5} cols={2} />}
|
|
||||||
onRetry={() => entriesQuery.refetch()}
|
|
||||||
>
|
|
||||||
{(items) => <EntriesTable items={items} moduleType={m.type} />}
|
|
||||||
</QueryState>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
|
<Alert>
|
||||||
|
<Info />
|
||||||
|
<AlertTitle>О модуле</AlertTitle>
|
||||||
|
<AlertDescription>{moduleTypeAlert(m.type)}</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
|
<ModuleKpiCards
|
||||||
|
mod={m}
|
||||||
|
communities={communities}
|
||||||
|
dohProfiles={dohProfiles}
|
||||||
|
asEntries={asEntries}
|
||||||
|
loading={detail.isLoading || communitiesQ.isLoading}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ModuleEntriesSection
|
||||||
|
moduleId={moduleId}
|
||||||
|
mod={m}
|
||||||
|
items={entriesQuery.data?.items ?? []}
|
||||||
|
communities={communities}
|
||||||
|
isLoading={entriesQuery.isLoading}
|
||||||
|
isError={entriesQuery.isError}
|
||||||
|
error={entriesQuery.error}
|
||||||
|
onRetry={() => entriesQuery.refetch()}
|
||||||
|
onChanged={onEntriesChanged}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</QueryState>
|
</QueryState>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Field({ label, value }: { label: string; value: React.ReactNode }) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col gap-0.5">
|
|
||||||
<span className="text-xs text-muted-foreground">{label}</span>
|
|
||||||
<span>{value}</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function EntriesTable({
|
|
||||||
items,
|
|
||||||
moduleType,
|
|
||||||
}: {
|
|
||||||
items: Record<string, unknown>[]
|
|
||||||
moduleType: string
|
|
||||||
}) {
|
|
||||||
const primary = ENTRY_PRIMARY_KEY[moduleType as keyof typeof ENTRY_PRIMARY_KEY] ?? 'id'
|
|
||||||
const secondary = ENTRY_SECONDARY_KEY[moduleType as keyof typeof ENTRY_SECONDARY_KEY] ?? null
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table>
|
|
||||||
<TableHeader>
|
|
||||||
<TableRow>
|
|
||||||
<TableHead>{primary}</TableHead>
|
|
||||||
{secondary ? <TableHead>{secondary}</TableHead> : null}
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{items.map((item, idx) => {
|
|
||||||
const id = String(item.id ?? idx)
|
|
||||||
const primaryVal = String(item[primary] ?? '—')
|
|
||||||
return (
|
|
||||||
<TableRow key={id}>
|
|
||||||
<TableCell className="font-mono text-sm">{primaryVal}</TableCell>
|
|
||||||
{secondary ? (
|
|
||||||
<TableCell className="font-mono text-xs text-muted-foreground">
|
|
||||||
{String(item[secondary] ?? '—')}
|
|
||||||
</TableCell>
|
|
||||||
) : null}
|
|
||||||
</TableRow>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const ENTRY_PRIMARY_KEY = {
|
|
||||||
DOMAINS: 'fqdn',
|
|
||||||
AS_PREFIXES: 'asn',
|
|
||||||
CDN_CIDRS: 'url',
|
|
||||||
IP_RANGES: 'prefix',
|
|
||||||
} as const
|
|
||||||
|
|
||||||
const ENTRY_SECONDARY_KEY = {
|
|
||||||
DOMAINS: 'community_id',
|
|
||||||
AS_PREFIXES: 'community_id',
|
|
||||||
CDN_CIDRS: 'community_id',
|
|
||||||
IP_RANGES: 'community_id',
|
|
||||||
} as const
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { createFileRoute, useSearch } from '@tanstack/react-router'
|
|||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { AlertTriangle, Clock, Activity, Info, RefreshCw } from 'lucide-react'
|
import { AlertTriangle, Clock, Activity, Info, RefreshCw } from 'lucide-react'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import { useState } from 'react'
|
import { useState, useMemo } from 'react'
|
||||||
|
|
||||||
import { Alert, AlertDescription, AlertTitle } from '@evobgp/ui/components/alert'
|
import { Alert, AlertDescription, AlertTitle } from '@evobgp/ui/components/alert'
|
||||||
import { Button } from '@evobgp/ui/components/button'
|
import { Button } from '@evobgp/ui/components/button'
|
||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
SelectContent,
|
SelectContent,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
} from '@evobgp/ui/components/select'
|
} from '@evobgp/ui/components/select'
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@evobgp/ui/components/tabs'
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@evobgp/ui/components/tabs'
|
||||||
import {
|
import {
|
||||||
@@ -367,6 +368,14 @@ function DiffTab({ revisions }: { revisions: import('@/types/api').RevisionRow[]
|
|||||||
const [a, setA] = useState('')
|
const [a, setA] = useState('')
|
||||||
const [b, setB] = useState('')
|
const [b, setB] = useState('')
|
||||||
const diffQ = useQuery(operationsDiffQueryOptions(a, b))
|
const diffQ = useQuery(operationsDiffQueryOptions(a, b))
|
||||||
|
const revisionItems = useMemo(
|
||||||
|
() =>
|
||||||
|
revisions.map((r) => ({
|
||||||
|
value: r.id,
|
||||||
|
label: `${r.id.slice(0, 12)}…`,
|
||||||
|
})),
|
||||||
|
[revisions],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
@@ -377,8 +386,10 @@ function DiffTab({ revisions }: { revisions: import('@/types/api').RevisionRow[]
|
|||||||
<div className="flex flex-wrap items-end gap-3">
|
<div className="flex flex-wrap items-end gap-3">
|
||||||
<div className="flex w-full max-w-xs flex-col gap-1">
|
<div className="flex w-full max-w-xs flex-col gap-1">
|
||||||
<span className="text-xs text-muted-foreground">Ревизия A</span>
|
<span className="text-xs text-muted-foreground">Ревизия A</span>
|
||||||
<Select value={a} onValueChange={(v) => v && setA(v)}>
|
<Select items={revisionItems} value={a} onValueChange={(v) => v && setA(v)}>
|
||||||
<SelectTrigger>{a ? a.slice(0, 12) + '…' : 'Выберите'}</SelectTrigger>
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Выберите" />
|
||||||
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{revisions.map((r) => (
|
{revisions.map((r) => (
|
||||||
<SelectItem key={r.id} value={r.id}>
|
<SelectItem key={r.id} value={r.id}>
|
||||||
@@ -390,8 +401,10 @@ function DiffTab({ revisions }: { revisions: import('@/types/api').RevisionRow[]
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex w-full max-w-xs flex-col gap-1">
|
<div className="flex w-full max-w-xs flex-col gap-1">
|
||||||
<span className="text-xs text-muted-foreground">Ревизия B</span>
|
<span className="text-xs text-muted-foreground">Ревизия B</span>
|
||||||
<Select value={b} onValueChange={(v) => v && setB(v)}>
|
<Select items={revisionItems} value={b} onValueChange={(v) => v && setB(v)}>
|
||||||
<SelectTrigger>{b ? b.slice(0, 12) + '…' : 'Выберите'}</SelectTrigger>
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="Выберите" />
|
||||||
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{revisions.map((r) => (
|
{revisions.map((r) => (
|
||||||
<SelectItem key={r.id} value={r.id}>
|
<SelectItem key={r.id} value={r.id}>
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ import { useQuery } from '@tanstack/react-query'
|
|||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@evobgp/ui/components/card'
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@evobgp/ui/components/card'
|
||||||
import { Input } from '@evobgp/ui/components/input'
|
import { Input } from '@evobgp/ui/components/input'
|
||||||
import { Label } from '@evobgp/ui/components/label'
|
import { Label } from '@evobgp/ui/components/label'
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger } from '@evobgp/ui/components/select'
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@evobgp/ui/components/select'
|
||||||
|
|
||||||
import { PageHeader } from '@/components/page-header'
|
import { PageHeader } from '@/components/page-header'
|
||||||
import { LoadingButton } from '@/components/loading-button'
|
import { LoadingButton } from '@/components/loading-button'
|
||||||
@@ -19,6 +25,12 @@ export const Route = createFileRoute('/_auth/settings')({
|
|||||||
component: SettingsComponent,
|
component: SettingsComponent,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const THEME_SELECT_ITEMS = [
|
||||||
|
{ value: 'light', label: 'Светлая' },
|
||||||
|
{ value: 'dark', label: 'Тёмная' },
|
||||||
|
{ value: 'system', label: 'Как в системе' },
|
||||||
|
] as const
|
||||||
|
|
||||||
function SettingsComponent() {
|
function SettingsComponent() {
|
||||||
const { data: session } = useQuery(authSessionQueryOptions())
|
const { data: session } = useQuery(authSessionQueryOptions())
|
||||||
const { theme, setTheme } = useTheme()
|
const { theme, setTheme } = useTheme()
|
||||||
@@ -84,8 +96,14 @@ function SettingsComponent() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col gap-2">
|
<CardContent className="flex flex-col gap-2">
|
||||||
<Label htmlFor="theme-select">Тема</Label>
|
<Label htmlFor="theme-select">Тема</Label>
|
||||||
<Select value={theme ?? 'system'} onValueChange={(v) => v && setTheme(v)}>
|
<Select
|
||||||
<SelectTrigger id="theme-select" className="w-full max-w-xs" />
|
items={[...THEME_SELECT_ITEMS]}
|
||||||
|
value={theme ?? 'system'}
|
||||||
|
onValueChange={(v) => v && setTheme(v)}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="theme-select" className="w-full max-w-xs">
|
||||||
|
<SelectValue placeholder="Выберите тему" />
|
||||||
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="light">Светлая</SelectItem>
|
<SelectItem value="light">Светлая</SelectItem>
|
||||||
<SelectItem value="dark">Тёмная</SelectItem>
|
<SelectItem value="dark">Тёмная</SelectItem>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
SelectContent,
|
SelectContent,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
} from '@evobgp/ui/components/select'
|
} from '@evobgp/ui/components/select'
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@evobgp/ui/components/tabs'
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@evobgp/ui/components/tabs'
|
||||||
import {
|
import {
|
||||||
@@ -48,6 +49,16 @@ export const Route = createFileRoute('/_auth/tenant-settings')({
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const RUNTIME_LOGS_ENABLED_ITEMS = [
|
||||||
|
{ value: 'true', label: 'Вкл' },
|
||||||
|
{ value: 'false', label: 'Выкл' },
|
||||||
|
] as const
|
||||||
|
|
||||||
|
const RUNTIME_LOGS_MODE_ITEMS = [
|
||||||
|
{ value: 'truncate', label: 'truncate — обнулить' },
|
||||||
|
{ value: 'delete', label: 'delete — удалить файл' },
|
||||||
|
] as const
|
||||||
|
|
||||||
const BIRD_LABELS: Record<BirdSettingKey, string> = {
|
const BIRD_LABELS: Record<BirdSettingKey, string> = {
|
||||||
bird_router_id: 'Router ID',
|
bird_router_id: 'Router ID',
|
||||||
bird_local_ipv4: 'Локальный IPv4',
|
bird_local_ipv4: 'Локальный IPv4',
|
||||||
@@ -241,6 +252,7 @@ function TenantSettingsComponent() {
|
|||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label>Авто-очистка включена</Label>
|
<Label>Авто-очистка включена</Label>
|
||||||
<Select
|
<Select
|
||||||
|
items={[...RUNTIME_LOGS_ENABLED_ITEMS]}
|
||||||
value={runtimeLogsForm.runtime_logs_auto_enabled ?? 'false'}
|
value={runtimeLogsForm.runtime_logs_auto_enabled ?? 'false'}
|
||||||
onValueChange={(v) =>
|
onValueChange={(v) =>
|
||||||
v &&
|
v &&
|
||||||
@@ -251,7 +263,7 @@ function TenantSettingsComponent() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
{runtimeLogsForm.runtime_logs_auto_enabled === 'true' ? 'Вкл' : 'Выкл'}
|
<SelectValue placeholder="Выберите" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="true">Вкл</SelectItem>
|
<SelectItem value="true">Вкл</SelectItem>
|
||||||
@@ -298,6 +310,7 @@ function TenantSettingsComponent() {
|
|||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label>Режим очистки</Label>
|
<Label>Режим очистки</Label>
|
||||||
<Select
|
<Select
|
||||||
|
items={[...RUNTIME_LOGS_MODE_ITEMS]}
|
||||||
value={runtimeLogsForm.runtime_logs_auto_mode ?? ''}
|
value={runtimeLogsForm.runtime_logs_auto_mode ?? ''}
|
||||||
onValueChange={(v) =>
|
onValueChange={(v) =>
|
||||||
v &&
|
v &&
|
||||||
@@ -308,11 +321,11 @@ function TenantSettingsComponent() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
{runtimeLogsForm.runtime_logs_auto_mode || 'Выберите'}
|
<SelectValue placeholder="Выберите" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem value="delete">Delete</SelectItem>
|
<SelectItem value="truncate">truncate — обнулить</SelectItem>
|
||||||
<SelectItem value="truncate">Truncate</SelectItem>
|
<SelectItem value="delete">delete — удалить файл</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<p className="font-mono text-xs text-muted-foreground">
|
<p className="font-mono text-xs text-muted-foreground">
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"root":["./src/main.tsx","./src/routetree.gen.ts","./src/components/confirm-dialog.tsx","./src/components/empty-state.tsx","./src/components/loading-button.tsx","./src/components/mode-toggle.tsx","./src/components/page-header.tsx","./src/components/page-shell.tsx","./src/components/query-state.tsx","./src/components/section-cards.tsx","./src/components/skeletons.tsx","./src/components/status-badge.tsx","./src/components/theme-provider.tsx","./src/components/truncated-text.tsx","./src/components/layout/app-shell.tsx","./src/components/reui/autocomplete.tsx","./src/components/reui/badge.tsx","./src/components/reui/date-selector.tsx","./src/components/reui/filters.tsx","./src/components/reui/number-field.tsx","./src/components/reui/data-grid/data-grid-column-filter.tsx","./src/components/reui/data-grid/data-grid-column-header.tsx","./src/components/reui/data-grid/data-grid-column-visibility.tsx","./src/components/reui/data-grid/data-grid-pagination.tsx","./src/components/reui/data-grid/data-grid-scroll-area.tsx","./src/components/reui/data-grid/data-grid-table-dnd-rows.tsx","./src/components/reui/data-grid/data-grid-table-dnd.tsx","./src/components/reui/data-grid/data-grid-table-virtual.tsx","./src/components/reui/data-grid/data-grid-table.tsx","./src/components/reui/data-grid/data-grid.tsx","./src/lib/api-client.ts","./src/lib/queryclient.ts","./src/lib/router.ts","./src/queries/api-keys.ts","./src/queries/auth.ts","./src/queries/directories.ts","./src/queries/modules.ts","./src/queries/monitoring.ts","./src/queries/network.ts","./src/queries/operations.ts","./src/queries/overview.ts","./src/queries/settings.ts","./src/routes/__root.tsx","./src/routes/_auth.tsx","./src/routes/index.tsx","./src/routes/_auth/access.tsx","./src/routes/_auth/dashboard.tsx","./src/routes/_auth/directories.tsx","./src/routes/_auth/monitoring.tsx","./src/routes/_auth/network.tsx","./src/routes/_auth/operations.tsx","./src/routes/_auth/schedule.tsx","./src/routes/_auth/settings.tsx","./src/routes/_auth/tenant-settings.tsx","./src/routes/_auth/modules/$moduleid.tsx","./src/routes/_auth/modules/index.tsx","./src/routes/_auth/modules/new.tsx","./src/types/api.ts","./vite.config.ts"],"version":"5.9.3"}
|
{"root":["./src/main.tsx","./src/routetree.gen.ts","./src/components/confirm-dialog.tsx","./src/components/empty-state.tsx","./src/components/loading-button.tsx","./src/components/mode-toggle.tsx","./src/components/page-header.tsx","./src/components/page-shell.tsx","./src/components/query-state.tsx","./src/components/section-cards.tsx","./src/components/skeletons.tsx","./src/components/status-badge.tsx","./src/components/theme-provider.tsx","./src/components/truncated-text.tsx","./src/components/layout/app-shell.tsx","./src/components/modules/community-select.tsx","./src/components/modules/module-as-entry-dialog.tsx","./src/components/modules/module-cdn-source-dialog.tsx","./src/components/modules/module-domain-entry-dialog.tsx","./src/components/modules/module-entries-section.tsx","./src/components/modules/module-ip-range-entry-dialog.tsx","./src/components/modules/module-kpi-cards.tsx","./src/components/reui/autocomplete.tsx","./src/components/reui/badge.tsx","./src/components/reui/date-selector.tsx","./src/components/reui/filters.tsx","./src/components/reui/number-field.tsx","./src/components/reui/data-grid/data-grid-column-filter.tsx","./src/components/reui/data-grid/data-grid-column-header.tsx","./src/components/reui/data-grid/data-grid-column-visibility.tsx","./src/components/reui/data-grid/data-grid-pagination.tsx","./src/components/reui/data-grid/data-grid-scroll-area.tsx","./src/components/reui/data-grid/data-grid-table-dnd-rows.tsx","./src/components/reui/data-grid/data-grid-table-dnd.tsx","./src/components/reui/data-grid/data-grid-table-virtual.tsx","./src/components/reui/data-grid/data-grid-table.tsx","./src/components/reui/data-grid/data-grid.tsx","./src/lib/api-client.ts","./src/lib/queryclient.ts","./src/lib/router.ts","./src/lib/ui-labels.ts","./src/lib/modules/display.ts","./src/lib/modules/helpers.ts","./src/queries/api-keys.ts","./src/queries/auth.ts","./src/queries/directories.ts","./src/queries/modules.ts","./src/queries/monitoring.ts","./src/queries/network.ts","./src/queries/operations.ts","./src/queries/overview.ts","./src/queries/settings.ts","./src/routes/__root.tsx","./src/routes/_auth.tsx","./src/routes/index.tsx","./src/routes/_auth/access.tsx","./src/routes/_auth/dashboard.tsx","./src/routes/_auth/directories.tsx","./src/routes/_auth/monitoring.tsx","./src/routes/_auth/network.tsx","./src/routes/_auth/operations.tsx","./src/routes/_auth/schedule.tsx","./src/routes/_auth/settings.tsx","./src/routes/_auth/tenant-settings.tsx","./src/routes/_auth/modules/$moduleid.tsx","./src/routes/_auth/modules/index.tsx","./src/routes/_auth/modules/new.tsx","./src/types/api.ts","./vite.config.ts"],"version":"5.9.3"}
|
||||||
@@ -18,7 +18,7 @@ apt-get install -y --no-install-recommends \
|
|||||||
|
|
||||||
cd /tmp
|
cd /tmp
|
||||||
rm -rf "bird-${BIRD_VERSION}"
|
rm -rf "bird-${BIRD_VERSION}"
|
||||||
curl -fsSL "https://bird.network.cz/download/bird-${BIRD_VERSION}.tar.gz" | tar xz
|
curl -fsSL "https://bird.nic.cz/download/bird-${BIRD_VERSION}.tar.gz" | tar xz
|
||||||
cd "bird-${BIRD_VERSION}"
|
cd "bird-${BIRD_VERSION}"
|
||||||
./configure --prefix=/usr/local --enable-client
|
./configure --prefix=/usr/local --enable-client
|
||||||
make -j"$(nproc)"
|
make -j"$(nproc)"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
FROM public.ecr.aws/docker/library/node:22-alpine AS deps
|
FROM public.ecr.aws/docker/library/node:22-alpine AS deps
|
||||||
WORKDIR /repo
|
WORKDIR /repo
|
||||||
RUN corepack enable
|
RUN corepack enable && corepack prepare [email protected] --activate
|
||||||
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
|
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
|
||||||
COPY apps/web/package.json ./apps/web/
|
COPY apps/web/package.json ./apps/web/
|
||||||
COPY packages/ui/package.json ./packages/ui/
|
COPY packages/ui/package.json ./packages/ui/
|
||||||
|
|||||||
+40
-4
@@ -184,6 +184,10 @@ type Registry struct {
|
|||||||
onTerminal func(j *Job)
|
onTerminal func(j *Job)
|
||||||
onEnqueued func(j *Job)
|
onEnqueued func(j *Job)
|
||||||
onRunning func(j *Job)
|
onRunning func(j *Job)
|
||||||
|
// inflightRefresh counts refresh-kind jobs (module_refresh, tenant_refresh) per tenant that
|
||||||
|
// have been enqueued but not yet finalized in finishModuleRefreshSuccess. Used for deterministic
|
||||||
|
// deploy coalescing under tenantRefreshMu (instead of polling job statuses).
|
||||||
|
inflightRefresh map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
type idempoKey struct {
|
type idempoKey struct {
|
||||||
@@ -194,10 +198,11 @@ type idempoKey struct {
|
|||||||
func NewRegistry(workerStart func(j *Job)) *Registry {
|
func NewRegistry(workerStart func(j *Job)) *Registry {
|
||||||
maxWorkers := registryMaxConcurrentJobs()
|
maxWorkers := registryMaxConcurrentJobs()
|
||||||
return &Registry{
|
return &Registry{
|
||||||
byID: make(map[string]*Job),
|
byID: make(map[string]*Job),
|
||||||
byIdempo: make(map[idempoKey]*Job),
|
byIdempo: make(map[idempoKey]*Job),
|
||||||
workerStart: workerStart,
|
workerStart: workerStart,
|
||||||
workerSem: make(chan struct{}, maxWorkers),
|
workerSem: make(chan struct{}, maxWorkers),
|
||||||
|
inflightRefresh: make(map[string]int),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,6 +345,9 @@ func (r *Registry) Enqueue(tenantID, kind string, idempotencyKey *string, module
|
|||||||
r.byIdempo[idempoKey{tenant: tenantID, key: *idempotencyKey}] = j
|
r.byIdempo[idempoKey{tenant: tenantID, key: *idempotencyKey}] = j
|
||||||
}
|
}
|
||||||
r.byID[j.ID] = j
|
r.byID[j.ID] = j
|
||||||
|
if isRefreshKind(kind) {
|
||||||
|
r.inflightRefresh[tenantID]++
|
||||||
|
}
|
||||||
r.pruneTerminalIfOver(maxJobs)
|
r.pruneTerminalIfOver(maxJobs)
|
||||||
enqueuedHook := r.onEnqueued
|
enqueuedHook := r.onEnqueued
|
||||||
workerStart := r.workerStart
|
workerStart := r.workerStart
|
||||||
@@ -474,6 +482,34 @@ func (r *Registry) CountOtherActiveRefresh(tenantID, excludeJobID string) int {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isRefreshKind reports whether a job kind participates in deploy coalescing.
|
||||||
|
func isRefreshKind(kind string) bool {
|
||||||
|
return kind == KindModuleRefresh || kind == KindTenantRefresh
|
||||||
|
}
|
||||||
|
|
||||||
|
// finalizeRefreshCoalesce is called from finishModuleRefreshSuccess under tenantRefreshMu.
|
||||||
|
// It atomically decrements the per-tenant inflight refresh counter and reports whether the
|
||||||
|
// caller is the last outstanding refresh for the tenant (and therefore should render+deploy).
|
||||||
|
//
|
||||||
|
// Unlike CountOtherActiveRefresh (which polls job statuses and races under -race), this counter
|
||||||
|
// is incremented in Enqueue under r.mu and decremented here, so the "last one" decision is
|
||||||
|
// deterministic regardless of how fast each refresh's ingest completes.
|
||||||
|
func (r *Registry) finalizeRefreshCoalesce(tenantID string) bool {
|
||||||
|
if r == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
n := r.inflightRefresh[tenantID]
|
||||||
|
if n <= 1 {
|
||||||
|
// Last (or already-balanced to zero) — clear the slot and let the caller deploy.
|
||||||
|
delete(r.inflightRefresh, tenantID)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
r.inflightRefresh[tenantID] = n - 1
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func parseCursor(s string, off *int) error {
|
func parseCursor(s string, off *int) error {
|
||||||
_, err := fmt.Sscanf(s, "%d", off)
|
_, err := fmt.Sscanf(s, "%d", off)
|
||||||
return err
|
return err
|
||||||
|
|||||||
+60
-23
@@ -119,26 +119,7 @@ func (w *Worker) Process(j *Job) {
|
|||||||
|
|
||||||
switch j.Kind {
|
switch j.Kind {
|
||||||
case KindModuleRefresh:
|
case KindModuleRefresh:
|
||||||
mid, _ := j.Meta["module_id"].(string)
|
w.runModuleRefresh(j)
|
||||||
if strings.TrimSpace(mid) == "" {
|
|
||||||
j.Fail("missing module_id in job meta")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx, cancel := j.workContext()
|
|
||||||
defer cancel()
|
|
||||||
if ctx.Err() != nil {
|
|
||||||
j.MarkCancelled()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := pipeline.RefreshModuleIngest(ctx, w.Store, w.httpClient(), j.TenantID, mid); err != nil {
|
|
||||||
if ctx.Err() != nil {
|
|
||||||
j.MarkCancelled()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
j.Fail(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.finishModuleRefreshSuccess(j, mid)
|
|
||||||
case KindTenantRefresh:
|
case KindTenantRefresh:
|
||||||
w.runTenantRefresh(j)
|
w.runTenantRefresh(j)
|
||||||
case KindPeerReconcile:
|
case KindPeerReconcile:
|
||||||
@@ -295,7 +276,55 @@ func (w *Worker) tenantRefreshMu(tenantID string) *sync.Mutex {
|
|||||||
|
|
||||||
// finishModuleRefreshSuccess marks the refresh job and, for the last active refresh in tenant,
|
// finishModuleRefreshSuccess marks the refresh job and, for the last active refresh in tenant,
|
||||||
// creates one aggregate revision and enqueues a single deploy_apply.
|
// creates one aggregate revision and enqueues a single deploy_apply.
|
||||||
|
// runModuleRefresh handles a single module_refresh job and guarantees the per-tenant inflight
|
||||||
|
// slot is released exactly once — even on failure/cancellation before finishModuleRefreshSuccess.
|
||||||
|
func (w *Worker) runModuleRefresh(j *Job) {
|
||||||
|
coalesceFinalized := false
|
||||||
|
defer func() {
|
||||||
|
if !coalesceFinalized && w != nil && w.Registry != nil {
|
||||||
|
// Refresh failed/was cancelled before reaching finishModuleRefreshSuccess.
|
||||||
|
// Decrement the counter under the tenant mutex so the "last one" logic stays sound.
|
||||||
|
mu := w.tenantRefreshMu(j.TenantID)
|
||||||
|
mu.Lock()
|
||||||
|
w.Registry.finalizeRefreshCoalesce(j.TenantID)
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
mid, _ := j.Meta["module_id"].(string)
|
||||||
|
if strings.TrimSpace(mid) == "" {
|
||||||
|
j.Fail("missing module_id in job meta")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx, cancel := j.workContext()
|
||||||
|
defer cancel()
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := pipeline.RefreshModuleIngest(ctx, w.Store, w.httpClient(), j.TenantID, mid); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
j.MarkCancelled()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j.Fail(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.finishModuleRefreshSuccess(j, mid)
|
||||||
|
coalesceFinalized = true
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Worker) runTenantRefresh(j *Job) {
|
func (w *Worker) runTenantRefresh(j *Job) {
|
||||||
|
coalesceFinalized := false
|
||||||
|
defer func() {
|
||||||
|
if !coalesceFinalized && w != nil && w.Registry != nil {
|
||||||
|
mu := w.tenantRefreshMu(j.TenantID)
|
||||||
|
mu.Lock()
|
||||||
|
w.Registry.finalizeRefreshCoalesce(j.TenantID)
|
||||||
|
mu.Unlock()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
moduleIDs := moduleIDsFromJobMeta(j.Meta)
|
moduleIDs := moduleIDsFromJobMeta(j.Meta)
|
||||||
if len(moduleIDs) == 0 {
|
if len(moduleIDs) == 0 {
|
||||||
j.Fail("missing module_ids in job meta")
|
j.Fail("missing module_ids in job meta")
|
||||||
@@ -318,6 +347,7 @@ func (w *Worker) runTenantRefresh(j *Job) {
|
|||||||
}
|
}
|
||||||
j.mergeMeta(map[string]any{"module_ids": moduleIDs, "modules_refreshed": len(moduleIDs)})
|
j.mergeMeta(map[string]any{"module_ids": moduleIDs, "modules_refreshed": len(moduleIDs)})
|
||||||
w.finishModuleRefreshSuccess(j, trigger)
|
w.finishModuleRefreshSuccess(j, trigger)
|
||||||
|
coalesceFinalized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func moduleIDsFromJobMeta(meta map[string]any) []string {
|
func moduleIDsFromJobMeta(meta map[string]any) []string {
|
||||||
@@ -346,6 +376,9 @@ func moduleIDsFromJobMeta(meta map[string]any) []string {
|
|||||||
|
|
||||||
func (w *Worker) finishModuleRefreshSuccess(j *Job, triggerModuleID string) {
|
func (w *Worker) finishModuleRefreshSuccess(j *Job, triggerModuleID string) {
|
||||||
if w == nil || w.Store == nil {
|
if w == nil || w.Store == nil {
|
||||||
|
if w != nil && w.Registry != nil {
|
||||||
|
w.Registry.finalizeRefreshCoalesce(j.TenantID)
|
||||||
|
}
|
||||||
j.Succeed()
|
j.Succeed()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -354,11 +387,15 @@ func (w *Worker) finishModuleRefreshSuccess(j *Job, triggerModuleID string) {
|
|||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
ctx, cancel := j.workContext()
|
ctx, cancel := j.workContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
deferDeploy := false
|
// Determine whether this is the last outstanding refresh for the tenant. The counter is
|
||||||
|
// incremented in Enqueue (under r.mu) and decremented here, so the "last one" decision is
|
||||||
|
// deterministic regardless of ingest timing — unlike the previous status-polling approach
|
||||||
|
// (CountOtherActiveRefresh) which could race under -race.
|
||||||
|
isLastRefresh := true
|
||||||
if w.Registry != nil {
|
if w.Registry != nil {
|
||||||
deferDeploy = w.Registry.CountOtherActiveRefresh(j.TenantID, j.ID) > 0
|
isLastRefresh = w.Registry.finalizeRefreshCoalesce(j.TenantID)
|
||||||
}
|
}
|
||||||
if deferDeploy {
|
if !isLastRefresh {
|
||||||
j.mergeMeta(map[string]any{
|
j.mergeMeta(map[string]any{
|
||||||
"deploy_apply_deferred": true,
|
"deploy_apply_deferred": true,
|
||||||
"deploy_apply_defer_reason": "parallel_module_refresh",
|
"deploy_apply_defer_reason": "parallel_module_refresh",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "evobgp-release",
|
"name": "evobgp-release",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"packageManager": "[email protected]",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "pnpm --filter @evobgp/web dev",
|
"dev": "pnpm --filter @evobgp/web dev",
|
||||||
"build": "pnpm --filter @evobgp/web build",
|
"build": "pnpm --filter @evobgp/web build",
|
||||||
|
|||||||
@@ -111,11 +111,15 @@ function SelectLabel({
|
|||||||
function SelectItem({
|
function SelectItem({
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
|
label,
|
||||||
...props
|
...props
|
||||||
}: SelectPrimitive.Item.Props) {
|
}: SelectPrimitive.Item.Props) {
|
||||||
|
const resolvedLabel = label ?? (typeof children === "string" ? children : undefined)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SelectPrimitive.Item
|
<SelectPrimitive.Item
|
||||||
data-slot="select-item"
|
data-slot="select-item"
|
||||||
|
label={resolvedLabel}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
className
|
className
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
packages:
|
packages:
|
||||||
- 'apps/*'
|
- 'apps/*'
|
||||||
- 'packages/*'
|
- 'packages/*'
|
||||||
|
|
||||||
|
onlyBuiltDependencies:
|
||||||
|
- esbuild
|
||||||
|
|||||||
Reference in New Issue
Block a user