// deployment-view/helpers.tsx — 时间线 / 信息面板辅助组件 // Logan.Li import { Fragment } from 'react'; import { formatK8sTime, formatDuration, elapsedSeconds, STATUS_COLORS, } from '../k8s-yaml-utils'; import type { PodItem } from './types'; import type { JsonData } from '@/types/common'; export interface PodStage { label: string; ts?: string; color: string; } // Pod 条件时间线提取 // Logan.Li export function getPodTimeline(pod: PodItem) { const cond: JsonData[] = (pod as JsonData).conditions || (pod as JsonData).pod_conditions || []; const find = (t: string) => cond.find((c: JsonData) => (c.type || c.Type) === t); const ts = (c: JsonData) => c?.lastTransitionTime || c?.LastTransitionTime || c?.last_transition_time; return { scheduled: ts(find('PodScheduled') || {}), initialized: ts(find('Initialized') || {}), containersReady: ts(find('ContainersReady') || {}), ready: ts(find('Ready') || {}), startTime: pod.start_time || (pod as JsonData).startTime, }; } // 启动阶段列表(列表/详情共用) // Logan.Li export function getPodStages(pod: PodItem): PodStage[] { const tl = getPodTimeline(pod); return [ { label: '已调度', ts: tl.scheduled, color: STATUS_COLORS.blue }, { label: '已初始化', ts: tl.initialized, color: STATUS_COLORS.orange }, { label: '容器已就绪', ts: tl.containersReady, color: STATUS_COLORS.green }, { label: '容器组已就绪', ts: tl.ready, color: STATUS_COLORS.green }, ]; } // 信息面板单项 // Logan.Li export function InfoItem({ label, value }: { label: string; value: React.ReactNode }) { return (

{label}

{value}
); } // 列表行紧凑就绪指示(无时间戳,避免视觉疲劳) // Logan.Li export function PodStatusCompact({ pod }: { pod: PodItem }) { const stages = getPodStages(pod); const done = stages.filter(s => s.ts).length; const allReady = done === stages.length; const pending = stages.find(s => !s.ts); return (
{stages.map((s, i) => ( {i < stages.length - 1 && ( )} ))}
{allReady ? '就绪' : pending?.label || `${done}/${stages.length}`}
); } // 详情区完整启动时间线(仅展开或概览面板使用) // Logan.Li export function PodConditionsRow({ pod }: { pod: PodItem }) { const stages = getPodStages(pod); const totalBoot = elapsedSeconds(stages[0]?.ts, stages[stages.length - 1]?.ts); return (
启动时间线 {totalBoot != null && ( 总耗时 {formatDuration(totalBoot)} )}
{stages.map((s, i) => { const prev = stages[i - 1]; const dur = elapsedSeconds(prev?.ts, s.ts); const active = !!s.ts; return (
{i + 1} {s.label}
{s.ts ? formatK8sTime(s.ts) : '—'}
{i < stages.length - 1 && (
{dur != null ? formatDuration(dur) : ''}
)} ); })}
); }