Discover Ethernet routers under the board, map physical SIM slots, expose vendor controls and real telemetry, and provide packaged VPS speed tests with a live monochrome gauge. Enforce compact typography across Core and Node UI.
58 lines
7.0 KiB
TypeScript
58 lines
7.0 KiB
TypeScript
import {RouterVendorHistory} from './RouterVendorHistory';
|
||
import {RouterRadioHistory,useRadioHistory} from './RouterRadioHistory';
|
||
import {useState,type ReactNode} from 'react';
|
||
import {Button,Description,SegmentedControl,SettingsCard,StatusBadge,Window} from '@nodedc/ui-react';
|
||
import {simChannels,simLabel,incidentLabels,incidentValue,metric,routerFresh,routerLabel,routerName,type RouterDevice,type RouterSnapshot,type RouterTransport} from './contracts';
|
||
import {RouterControls} from './RouterControls';
|
||
import {ClientRouterControls} from './ClientRouterControls';
|
||
import {RouterAccess} from './RouterAccess';
|
||
import {RouterGeneral} from './RouterGeneral';
|
||
import {RouterOverview,useRouterTraffic} from './RouterOverview';
|
||
|
||
function Facts({items}:{items:[string,string][]}){return <dl className="router-facts">{items.map(([label,value])=><div key={label}><dt>{label}</dt><dd>{value||'Нет сведений'}</dd></div>)}</dl>;}
|
||
const sections=[{value:'overview',label:'Обзор'},{value:'control',label:'Управление'},{value:'signal',label:'Радиоканал'},{value:'events',label:'Происшествия'},{value:'general',label:'Общие'}];
|
||
|
||
export function RouterDetails({device,value,transport,onClose,error,speedtest}:{device:RouterDevice;value:RouterSnapshot;transport:RouterTransport;onClose:()=>void;error:string;speedtest?:ReactNode}){
|
||
const [section,setSection]=useState(device.state==='access_required'||device.state==='access_rejected'?'general':'overview');
|
||
const fresh=routerFresh(value,device),ready=fresh&&device.state==='ready';
|
||
const traffic=useRouterTraffic(device,value,ready);
|
||
const radio=useRadioHistory(device,value,ready);
|
||
const [eventSource,setEventSource]=useState('board');
|
||
const incidents=value.events.filter(e=>e.device_id===device.id).slice().reverse();
|
||
function download(){
|
||
const data={schema:'missioncore.router-journal/v1',fresh:value.fresh??true,journal:value.journal,events:incidents};
|
||
const url=URL.createObjectURL(new Blob([JSON.stringify(data,null,2)],{type:'application/json'}));
|
||
const a=document.createElement('a');a.href=url;a.download='router-journal.json';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);
|
||
}
|
||
return <Window open size="lg" title={routerName(device)} subtitle="Сеть аппарата" onClose={onClose} closeOnBackdrop={false}>
|
||
<div className="router-details">
|
||
<StatusBadge tone={ready?'success':'neutral'}>{routerLabel(value,device)}</StatusBadge>
|
||
<Description>{device.observed_at?`Последнее наблюдение: ${new Date(device.observed_at*1000).toLocaleString('ru-RU')}`:'Наблюдений пока нет'}{!ready&&device.modems.length>0?' · Показаны последние полученные значения':''}</Description>
|
||
{error&&<StatusBadge tone="warning">{error}</StatusBadge>}
|
||
<SegmentedControl label="Сведения о роутере" value={section} items={speedtest?[...sections.slice(0,2),{value:'speedtest',label:'Замер скорости'},...sections.slice(2)]:sections} onChange={setSection}/>
|
||
{section==='overview'&&<RouterOverview device={device} ready={ready} points={traffic}/>}
|
||
<div hidden={section!=='control'}>{device.client_api?<ClientRouterControls device={device} value={value} transport={transport} ready={ready} visible={section==='control'}/>:<RouterControls device={device} value={value} transport={transport} ready={ready}/>}</div>
|
||
<div hidden={section!=='speedtest'}>{speedtest}</div>
|
||
{section==='signal'&&<>
|
||
<RouterRadioHistory device={device} samples={radio}/>
|
||
<Description>Показатели относятся к модемам. Данных по отдельным разъёмам антенн роутер не предоставил.</Description>
|
||
{device.modems.length===0?<Description>Для получения радиопоказателей нужен доступ к роутеру.</Description>:simChannels(device).flatMap(channel=>{const m=device.modems.find(m=>m.slot===channel.slot);return m?[<SettingsCard key={m.slot} title={`${channel.label} (${channel.detail})`} description={m.operator||'Оператор не определён'}><Facts items={[
|
||
['Регистрация',device.client_api?.wan.find(w=>w.slot===m.slot)?.registration??''],['Причина недоступности',device.client_api?.wan.find(w=>w.slot===m.slot)?.failure_reason??''],
|
||
['Радиомодуль',m.radio==='NOSIM'?'SIM не обнаружена':m.radio==='OK'?'Готов':m.radio],['Подключение',m.connectivity==='online'?'В сети':m.connectivity==='offline'?'Нет связи':m.connectivity],
|
||
['Сеть',m.technology],['Диапазон',m.band],['Ширина канала',metric(m.bandwidth,'МГц')],['RSRP',metric(m.rsrp,'dBm')],['RSRQ',metric(m.rsrq,'dB')],['SINR',metric(m.sinr,'dB')],['RSSI',metric(m.rssi,'dBm')],['Адрес модема',m.ip],['Базовая станция',m.cell_id],['EARFCN',m.earfcn==null?'Нет сведений':String(m.earfcn)],['TAC',m.tac??''],['PCI',m.pci==null?'Нет сведений':String(m.pci)],
|
||
]}/></SettingsCard>]:[];})}
|
||
</>}
|
||
{section==='events'&&<>
|
||
{device.client_api&&<SegmentedControl label="Источник истории" value={eventSource} items={[{value:'board',label:'Борт'},{value:'router',label:'Роутер'}]} onChange={setEventSource}/>}
|
||
{eventSource==='router'&&device.client_api?<RouterVendorHistory device={device} value={value} transport={transport}/>:<>
|
||
<div className="router-actions"><Button disabled={!incidents.length} onClick={download}>Скачать журнал</Button></div>
|
||
<Description>На борту хранятся до {value.journal?.limit??256} событий за {value.journal?.retention_days??7} дней. Время событий — по часам борта.</Description>
|
||
{!!value.journal?.dropped&&<StatusBadge tone="neutral">Старые события удалены по сроку или лимиту: {value.journal.dropped}</StatusBadge>}
|
||
{value.journal?.error&&<StatusBadge tone="warning">Борт не подтвердил сохранение журнала.</StatusBadge>}
|
||
{incidents.length===0?<Description>Происшествий пока нет.</Description>:<ol className="router-events">{incidents.map(e=><li key={`${e.boot_id}:${e.sequence}`}><time dateTime={new Date(e.at*1000).toISOString()}>{new Date(e.at*1000).toLocaleString('ru-RU')}</time><strong>{incidentLabels[e.code]??'Состояние изменилось'}{e.slot?` · ${simLabel(device,e.slot)}`:''}</strong>{(e.before||e.after)&&<span>{[incidentValue(e.before),incidentValue(e.after)].filter(Boolean).join(' → ')}</span>}</li>)}</ol>}
|
||
</>}</>}
|
||
{section==='general'&&<><RouterGeneral device={device} value={value} transport={transport}/><RouterAccess key={device.id} device={device} value={value} transport={transport} fresh={fresh&&device.state!=='unreachable'&&device.state!=='incompatible'}/></>}
|
||
</div>
|
||
</Window>;
|
||
}
|