feat!(web): migrate UI from SvelteKit to React + shadcn/ui + ReUI
CI / changes (push) Successful in 17s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 26s
CI / web (push) Successful in 46s
CI / go (push) Successful in 1m1s
CI / bird2 (push) Successful in 17s
CI / release (push) Failing after 2m22s
CI / changes (push) Successful in 17s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 26s
CI / web (push) Successful in 46s
CI / go (push) Successful in 1m1s
CI / bird2 (push) Successful in 17s
CI / release (push) Failing after 2m22s
Web UI полностью переведён с SvelteKit на новый стек: React 19, TanStack Router/Query/Table/Virtual, shadcn/ui (base-nova) и ReUI enterprise-компоненты (data-grid, filters, autocomplete). Новый код разложен по слоям: packages/ui (shadcn-примитивы), apps/web (роуты, shared-обёртки, ReUI-адаптации). BREAKING CHANGE: меняется структура и инструментинг фронтенда. - apps/web/ — новый Vite + React-проект (@evobgp/web), file-based роуты TanStack Router; экраны dashboard, modules, monitoring, network, operations, schedule, settings, tenant-settings, access, directories. - packages/ui/ — shadcn/ui-примитивы (@evobgp/ui) с общими стилями globals.css и cn-утилитой; CLI shadcn запускается из apps/web. - apps/web/src/components/reui/ — enterprise-паттерны ReUI. - pnpm workspace (pnpm-workspace.yaml, pnpm-lock.yaml, tsconfig.base.json) заменяет npm-проект в web/. - web/ переименован в web-legacy-svelte/ (архив-референс для миграции); импорты оттуда запрещены правилом WEB-22. - CI (.gitea/workflows/ci.yaml): job web переведён на Node 22 + pnpm 10 (typecheck/lint/build через pnpm --filter @evobgp/web); пути триггеров обновлены под apps/web|packages/ui. - deploy/docker/evobgp-web/Dockerfile: сборка из корня репозитория, pnpm install --frozen-lockfile, выход dist из apps/web/dist. - .cursor/rules/web-shadcn.mdc, context7-stack.mdc, engineering.mdc, AGENTS.md — обновлены под React-стек (WEB-01..WEB-22, DOC-SYNC-06/07). Проверки WEB-19 локально: typecheck, lint, build — exit 0. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
import { queryOptions } from '@tanstack/react-query'
|
||||
import { apiJSON } from '@/lib/api-client'
|
||||
|
||||
export type AppSettings = Record<string, unknown>
|
||||
|
||||
export const BIRD_SETTING_KEYS = [
|
||||
'bird_router_id',
|
||||
'bird_local_ipv4',
|
||||
'bird_local_ipv6',
|
||||
'bird_local_asn',
|
||||
'bird_bgp_source_ipv4',
|
||||
'bird_bgp_source_ipv6',
|
||||
] as const
|
||||
|
||||
export const REVISION_SETTING_KEYS = ['revision_retention_minutes'] as const
|
||||
|
||||
export const RUNTIME_LOGS_SETTING_KEYS = [
|
||||
'runtime_logs_auto_enabled',
|
||||
'runtime_logs_max_file_mb',
|
||||
'runtime_logs_auto_schedule',
|
||||
'runtime_logs_auto_mode',
|
||||
] as const
|
||||
|
||||
export const KNOWN_SETTING_KEYS = [
|
||||
...BIRD_SETTING_KEYS,
|
||||
...REVISION_SETTING_KEYS,
|
||||
...RUNTIME_LOGS_SETTING_KEYS,
|
||||
] as const
|
||||
|
||||
export type KnownSettingKey = (typeof KNOWN_SETTING_KEYS)[number]
|
||||
export type BirdSettingKey = (typeof BIRD_SETTING_KEYS)[number]
|
||||
export type RevisionSettingKey = (typeof REVISION_SETTING_KEYS)[number]
|
||||
export type RuntimeLogsSettingKey = (typeof RUNTIME_LOGS_SETTING_KEYS)[number]
|
||||
|
||||
export const NUMERIC_SETTING_KEYS = new Set<KnownSettingKey>([
|
||||
'bird_local_asn',
|
||||
'revision_retention_minutes',
|
||||
'runtime_logs_max_file_mb',
|
||||
])
|
||||
|
||||
export const BOOLEAN_SETTING_KEYS = new Set<KnownSettingKey>(['runtime_logs_auto_enabled'])
|
||||
|
||||
export const settingsKeys = {
|
||||
all: ['settings'] as const,
|
||||
}
|
||||
|
||||
export function settingsQueryOptions() {
|
||||
return queryOptions<AppSettings>({
|
||||
queryKey: settingsKeys.all,
|
||||
queryFn: () => apiJSON<AppSettings>('/v1/settings'),
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
export function parseKnownValue(key: KnownSettingKey, value: unknown): string {
|
||||
if (NUMERIC_SETTING_KEYS.has(key)) {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return String(value)
|
||||
if (typeof value === 'string') return value
|
||||
return ''
|
||||
}
|
||||
if (typeof value === 'string') return value
|
||||
return ''
|
||||
}
|
||||
|
||||
export interface PartitionedSettings {
|
||||
bird: Partial<Record<BirdSettingKey, string>>
|
||||
revision: Partial<Record<RevisionSettingKey, string>>
|
||||
runtimeLogs: Partial<Record<RuntimeLogsSettingKey, string>>
|
||||
additional: { id: number; key: string; value: string }[]
|
||||
}
|
||||
|
||||
export function partitionSettings(settings: AppSettings): PartitionedSettings {
|
||||
const bird: Partial<Record<BirdSettingKey, string>> = {}
|
||||
const revision: Partial<Record<RevisionSettingKey, string>> = {}
|
||||
const runtimeLogs: Partial<Record<RuntimeLogsSettingKey, string>> = {}
|
||||
const additional: { id: number; key: string; value: string }[] = []
|
||||
let id = 1
|
||||
|
||||
for (const [key, value] of Object.entries(settings)) {
|
||||
if ((BIRD_SETTING_KEYS as readonly string[]).includes(key)) {
|
||||
bird[key as BirdSettingKey] = parseKnownValue(key as KnownSettingKey, value)
|
||||
} else if (key === 'revision_retention_minutes') {
|
||||
revision.revision_retention_minutes = parseKnownValue(
|
||||
key as RevisionSettingKey,
|
||||
value,
|
||||
)
|
||||
} else if ((RUNTIME_LOGS_SETTING_KEYS as readonly string[]).includes(key)) {
|
||||
const rk = key as RuntimeLogsSettingKey
|
||||
if (rk === 'runtime_logs_auto_enabled') {
|
||||
runtimeLogs.runtime_logs_auto_enabled =
|
||||
value === true || value === 1 || value === 'true' || value === '1'
|
||||
? 'true'
|
||||
: 'false'
|
||||
} else if (rk === 'runtime_logs_auto_mode') {
|
||||
const m = String(value ?? '').trim()
|
||||
runtimeLogs.runtime_logs_auto_mode = m === 'delete' ? 'delete' : m === 'truncate' ? 'truncate' : ''
|
||||
} else {
|
||||
runtimeLogs[rk] = parseKnownValue(rk, value)
|
||||
}
|
||||
} else {
|
||||
additional.push({
|
||||
id: id++,
|
||||
key,
|
||||
value: typeof value === 'string' ? value : String(value),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return { bird, revision, runtimeLogs, additional }
|
||||
}
|
||||
|
||||
export function buildPayload(
|
||||
keys: readonly KnownSettingKey[],
|
||||
form: Record<string, string>,
|
||||
): Record<string, string | number | boolean> {
|
||||
const payload: Record<string, string | number | boolean> = {}
|
||||
for (const key of keys) {
|
||||
const value = String(form[key] ?? '').trim()
|
||||
if (BOOLEAN_SETTING_KEYS.has(key)) {
|
||||
payload[key] = value === 'true'
|
||||
continue
|
||||
}
|
||||
if (!value) continue
|
||||
if (NUMERIC_SETTING_KEYS.has(key)) payload[key] = Number(value)
|
||||
else payload[key] = value
|
||||
}
|
||||
return payload
|
||||
}
|
||||
Reference in New Issue
Block a user