import { useCallback, useEffect, useRef, useState } from 'react' import { Link } from 'react-router-dom' import { GitBranch } from 'lucide-react' import clsx from 'clsx' import { api } from '../api/client' import { humanizeError } from '../lib/errors' import { CATALOG_IMPACT_TEXT as T, WORKFLOW_STATUS_LABEL } from '../lib/terms' import type { CatalogImpact, CatalogImpactNode, CatalogImpactTemplate } from '../types' import { Skeleton } from './ui' // =========================================================================== // 影响面:哪些已发布、受管的模板引用这张表(GET /catalog/{table}/impact)。数据目录的表详情里一栏,助手的 // 「建议更新数据目录」卡片保存之后也列一遍——改了目录,人要知道哪些正式出具的数可能跟着变。 // // 「直接引用」和「可能涉及」分开写:前者 SQL 里写着这张表,后者是 Agent 运行时自己写 SQL,静态看不出。 // 合并查询写明经由哪个输入。模板名点进去是画布(定位到那个节点)。 // =========================================================================== const SHOWN = 5 export function CatalogImpactList({ sourceId, table, refreshKey, compact = false, onLoad }: { sourceId: string table: string /** 变了就重新统计(表详情传目录版本:保存之后刷新) */ refreshKey?: number | string /** 卡片里的紧凑版:只列前几个模板,节点收成一行 */ compact?: boolean /** 统计好了:数据目录页据此在保存之后说「N 个已发布模板引用这张表」 */ onLoad?: (d: CatalogImpact) => void }) { const [data, setData] = useState(null) const [error, setError] = useState(null) const [all, setAll] = useState(false) const seq = useRef(0) const onLoadRef = useRef(onLoad) onLoadRef.current = onLoad const load = useCallback(() => { const mine = ++seq.current setError(null) api.dataCatalog.impact(sourceId, table) .then((d) => { if (mine === seq.current) { setData(d); onLoadRef.current?.(d) } }) .catch((e) => { if (mine === seq.current) setError(e) }) }, [sourceId, table]) useEffect(() => { setData(null) setAll(false) load() }, [load, refreshKey]) if (error && !data) { return (

{T.error}:{humanizeError(error).title}

) } if (!data) return
const list = data.templates if (!list.length) { return (

{compact ? T.afterSaveNone : T.none}

) } const shown = all || !compact ? list : list.slice(0, SHOWN) return (
{compact &&

{T.afterSave(list.length)}

}
    {shown.map((t) => )}
{compact && list.length > shown.length && ( )}
) } /** * 「直接引用」用强调色:它说的是引用关系的强弱,不是警示——琥珀色在全站是「等待、要人处理」,用在这里像是出了问题。 * 「可能涉及」用次要文字色 */ function ImpactBadge({ impact }: { impact: 'direct' | 'possible' }) { return ( {T.impact[impact]} ) } function nodeText(n: CatalogImpactNode): string { const who = n.member ? `「${n.label}」${T.member(n.member)}` : `「${n.label}」` const via = n.via?.length ? `(${T.via(n.via.map((v) => `「${v.label}」`).join('、'))})` : '' return `${who}${via}` } function TemplateRow({ t, compact }: { t: CatalogImpactTemplate; compact: boolean }) { const first = t.nodes.find((n) => n.impact === t.impact) ?? t.nodes[0] const href = `/studio/${encodeURIComponent(t.workflow_id)}${first ? `?focus=${encodeURIComponent(first.node_id)}` : ''}` return (
  • {t.name} {T.version(t.version)} {WORKFLOW_STATUS_LABEL[t.level] ?? t.level}
    {!compact && (
      {t.nodes.map((n) => (
    • {nodeText(n)} {T.impact[n.impact]}
    • ))}
    )}
  • ) }