fix(evolution): исключить моковые данные из живого каталога
This commit is contained in:
1 parent
118cd31d65
commit
d272ef57f0
17 files changed
+155
-136
No files matched your search
@@ -0,0 +1,29 @@
|
||||
"use client"
|
||||
import Link from "next/link"
|
||||
import {useDataSource} from "@/lib/data-source"
|
||||
import {useEvoBGP} from "@/lib/evobgp-context"
|
||||
import {can} from "@/lib/auth"
|
||||
import {Alert,AlertTitle,AlertDescription} from "@/components/reui/alert"
|
||||
import {Button} from "@/components/ui/button"
|
||||
import {EmptyState} from "@/components/empty-state"
|
||||
import {AlertCircleIcon} from "lucide-react"
|
||||
|
||||
export function useEvoCatalogView(){
|
||||
const {mode,backendStatus}=useDataSource(),evo=useEvoBGP()
|
||||
const allowed=can("mm:settings:admin")
|
||||
const snapshot=mode==="live"&&allowed&&evo.enabled?evo.snapshot:null
|
||||
return {evo,mode,backendStatus,allowed,snapshot,known:mode==="mock"||!!snapshot,loading:mode==="live"&&allowed&&!snapshot&&(evo.settingsLoading||evo.loading)}
|
||||
}
|
||||
export function EvoBgpCatalogStatus(){
|
||||
const {evo,mode,backendStatus,allowed,snapshot}=useEvoCatalogView()
|
||||
if(mode==="mock")return <p role="status" className="text-xs text-muted-foreground">Демонстрационный каталог</p>
|
||||
const reason=!allowed?"Нет доступа к каталогу EvoBGP":!evo.settingsLoaded?evo.settingsLoading?"Загрузка настроек EvoBGP…":"Настройки EvoBGP неизвестны":!evo.enabled?"Интеграция EvoBGP выключена":!snapshot?evo.loading?"Загрузка каталога EvoBGP…":"Каталог EvoBGP не получен":null
|
||||
const error=evo.settingsError||evo.catalogError
|
||||
return <div className="flex min-w-0 flex-col gap-3">
|
||||
{reason?<p role="status" className="text-sm">{reason}</p>:null}
|
||||
{snapshot?<p role="status" className="text-xs text-muted-foreground">Каталог EvoBGP получен: {evo.catalogReceivedAt?new Date(evo.catalogReceivedAt).toLocaleString("ru-RU"):"—"}{evo.loading?" · обновление…":""}</p>:null}
|
||||
{error?<Alert variant="warning"><AlertCircleIcon aria-hidden="true"/><AlertTitle>{snapshot?"Каталог не обновлён; показаны последние данные":"Каталог EvoBGP недоступен"}</AlertTitle><AlertDescription>{[evo.settingsError,evo.catalogError].filter(Boolean).join("; ")}</AlertDescription></Alert>:null}
|
||||
{allowed?<div className="flex flex-wrap gap-2"><Button size="sm" variant="outline" disabled={backendStatus!==true||evo.settingsLoading||evo.loading||evo.operationBusy} onClick={()=>{if(!evo.settingsLoaded||!evo.enabled||evo.settingsError)void evo.loadSettings();else void evo.refresh()}}>Обновить каталог EvoBGP</Button><Link className="text-sm underline underline-offset-4" href="/settings">Настройки → EvoBGP</Link></div>:null}
|
||||
</div>
|
||||
}
|
||||
export function EvoBgpCatalogUnavailable(){return <EmptyState title="Данные каталога не получены" description="Состояние загрузки указано выше. Число записей пока неизвестно." className="py-10"/>}
|
||||
Reference in new issue
Block a user