定时任务自动对比复核整改(前端):页头的定时任务链接在窄窗口里不再被挤没、带日历图标、任务删了写纯文本;触发历史的对比入口改叫「与上一次对比」并写出有几个指标有变化

- 运行详情页头:元信息这一行改成可换行,定时任务链接至少留 7 个字宽。以前这一行不换行、只有链接能缩,820 宽的探索
  运行只剩「由…」,768 宽为 0,Tab 停在看不见的链接上,「2 条事件」被压成竖排。链接前加和「定时」标记一样的日历
  图标,平时看得出能点。取回的定时任务列表里没有这个任务(已删除)时写成纯文本「由定时任务「X」发起(已删除)」,
  不再链到「不存在」页;列表取不到时不算删除
- 触发历史:「对比上一次」改成和运行详情「更多」菜单同一个叫法「与上一次对比」(复用 RUN_COMPARE_TEXT.menu),旁边
  写「N 个指标有变化」,触屏和键盘也看得到变化的规模,悬停照旧写各类个数。基准不是紧挨着的上一次(服务端给
  previous: false)时悬停写明是哪一次,也不再带「默认基准:同一定时任务的上一次运行」的来历
- 「通知中的运行链接」改成「通知中的链接」,说明里写清对比页链接也靠这个地址
- check-schedules:对比入口的叫法、计数、previous 为 false 时的悬停和来历;页头链接在 768、820 宽(含「提取为草稿」
  的探索运行、署名的立即运行)写得下「由定时任务」且「条事件」不竖排、Tab 到时看得见;图标;定时任务删除后的纯文本
  和列表取不到时照旧是链接;390 宽深浅色下计数在屏幕里、对比度够
This commit is contained in:
ThearchyHelios
2026-10-06 08:49:10 +08:00
parent 45fe01effe
commit 5e8d2c9c36
7 changed files with 268 additions and 69 deletions
+36 -10
View File
@@ -2968,14 +2968,14 @@ export const SCHEDULE_TEXT = {
testResult: (head: string, status: number | null, detail: string) =>
`${head}${status != null ? `(HTTP ${status})` : ''}${detail ? `:${detail}` : ''}`,
// ---- 通知里的运行链接(设置 notify 组,所有定时任务共用)
linkBase: '通知中的运行链接',
// ---- 通知里的链接:运行、对比页都按这个地址拼(设置 notify 组,所有定时任务共用)
linkBase: '通知中的链接',
linkBaseValue: (url: string) => `按 ${url} 拼接`,
linkBaseUnset: '未设置服务访问地址,通知中不附带运行链接',
linkBaseUnset: '未设置服务访问地址,通知中不附带运行和对比页链接',
linkBaseEdit: '修改',
linkBaseSet: '设置',
linkBaseLabel: '服务访问地址',
linkBaseHint: '收件人打开运行链接用的地址,例如 https://agentlab.example.com。所有定时任务共用',
linkBaseHint: '收件人打开运行、对比页链接用的地址,例如 https://agentlab.example.com。所有定时任务共用',
linkBasePlaceholder: 'https://agentlab.example.com',
linkBaseInvalid: '请输入以 http:// 或 https:// 开头的地址',
linkBaseSaved: '已保存服务访问地址',
@@ -3050,21 +3050,40 @@ export const SCHEDULE_TEXT = {
allLoaded: '已全部加载',
shown: (n: number) => `已显示 ${n} 条`,
// ---- 触发历史里的对比:运行结束后服务端自动和同一定时任务的上一次比一次
compareLink: '对比上一次',
// ---- 触发历史里的对比:运行成功结束后,服务端自动和同一定时任务上一次成功的运行比一次
/**
* 和运行详情「更多」菜单里的入口是同一件事,用同一个叫法。RUN_COMPARE_TEXT 定义在本对象之后,模块初始化时还取不到,
* 写成 getter 用到时再取
*/
get compareLink() { return RUN_COMPARE_TEXT.menu },
/**
* 悬停写各类指标的个数,和 Webhook 通知里那一行同一个写法(服务端 scheduler/auto_compare.py 的 summary_text):
* 变化三分法的三类总写上,0 个也写;其余各类有才写,次序同对比页;两边都没有指标时不写一串 0 个。只有个数,
* 不写数值。各类的叫法用对比页那一套(RUN_COMPARE_TEXT.classLabel)
* 不写数值。各类的叫法用对比页那一套(RUN_COMPARE_TEXT.classLabel)。base 是基准的短编号,基准不是紧挨着的
* 上一次(上一次失败了、取消了)时给,写明比的是哪一次,同通知
*/
compareTitle: (summary: Partial<Record<string, number>>) => {
compareTitle: (summary: Partial<Record<string, number>>, base?: string | null) => {
const n = (key: string) => (typeof summary[key] === 'number' ? summary[key] as number : 0)
const core = ['data_only', 'caliber_and_data', 'sql_changed']
const rest = ['params_only', 'added', 'removed', 'incomparable', 'unchanged']
if (![...core, ...rest].some((key) => n(key) > 0)) return '与上一次相比:两次运行都没有指标'
const head = base ? `与上一次成功的运行(${base})相比` : '与上一次相比'
if (![...core, ...rest].some((key) => n(key) > 0)) return `${head}:两次运行都没有指标`
const parts = [...core, ...rest.filter((key) => n(key) > 0)]
.map((key) => `${RUN_COMPARE_TEXT.classLabel[key] ?? key} ${n(key)} 个`)
return `与上一次相比:${parts.join('、')}`
return `${head}:${parts.join('、')}`
},
/**
* 链接旁看得见的简短计数:触屏没有悬停,键盘聚焦时也不显示 title,只靠悬停看不出变化的规模。有变化的几类(只数据变、
* 口径与数据都变、SQL 结构变、只参数变、新增、移除)合起来写一个数;都没变化时说有几个无法比较,或者都未变;两边都
* 没有指标时不写(悬停里有)
*/
compareCount: (summary: Partial<Record<string, number>>) => {
const n = (key: string) => (typeof summary[key] === 'number' ? summary[key] as number : 0)
const changed = ['data_only', 'caliber_and_data', 'sql_changed', 'params_only', 'added', 'removed']
.reduce((sum, key) => sum + n(key), 0)
if (changed) return `${changed} 个指标有变化`
if (n('incomparable')) return `${n('incomparable')} 个指标无法比较`
return n('unchanged') ? '指标都未变' : null
},
// ---- 运行详情页头的来源
@@ -3080,6 +3099,13 @@ export const SCHEDULE_TEXT = {
/** 悬停写全名(页头窄时链接会截断)和点开去哪 */
runSourceTitle: (name?: string | null) =>
(name ? `定时任务「${name}」:查看设置和触发历史` : '查看这个定时任务的设置和触发历史'),
/**
* 定时任务已经删除(取回的定时任务列表里没有它):不再链过去——只会落到「不存在」页,页上的返回又回到定时任务列表。
* 和同一行的「工作流已删除」一样写成纯文本
*/
runSourceGone: (name?: string | null) => (name ? `由定时任务「${name}」发起(已删除)` : '由已删除的定时任务发起'),
runSourceManualGone: (name?: string | null) => (name ? `来自定时任务「${name}」(已删除)` : '来自已删除的定时任务'),
runSourceGoneTitle: '这个定时任务已删除,它发起的运行记录仍然保留',
// ---- 记录页的定时标记
runTag: '定时',
+2 -1
View File
@@ -555,7 +555,8 @@ export function RunDetailView({ runId, onChange, onDeleted }: {
<ClassChip runClass={run.run_class} version={run.version} always />
<TierChip tier={(run.output as any)?._issuance?.tier} />
</div>
<div className="mt-0.5 flex min-w-0 items-center gap-1 text-2xs text-faint">
{/* 窄时换行:不换行时这一行只有定时任务链接能缩,会被挤成 0 宽,其余各项被压成竖排 */}
<div className="mt-0.5 flex min-w-0 flex-wrap items-center gap-x-1 gap-y-0.5 text-2xs text-faint">
<span className="mono">{shortId(run.id)}</span>
<span>·</span>
<time className="tnum" title={`发起于 ${formatDateTime(run.created_at ?? null)}`}>
+18 -8
View File
@@ -3,7 +3,7 @@ import { Link } from 'react-router-dom'
import { ChevronRight, GitCompareArrows, History, RotateCw } from 'lucide-react'
import { api } from '../../api/client'
import { EmptyState, ErrorState, Skeleton, Spinner, StatusPill, toast, useTicker } from '../../components/ui'
import { formatDateTime, parseServerTime } from '../../lib/format'
import { formatDateTime, parseServerTime, shortId } from '../../lib/format'
import { SCHEDULE_TEXT as T } from '../../lib/terms'
import type { Schedule, ScheduleFire, ScheduleFireCompare } from '../../types'
import { comparePath, type CompareVia } from '../runs/compare/entry'
@@ -13,8 +13,8 @@ const PAGE = 20
/**
* 触发历史:每次触发一行,新的在前,20 条一页、「加载更多」往后接。计划时间按定时任务的时区写;跳过、发起失败
* 写原因;发起了的链到那次运行、写运行现在的状态;运行结束后服务端和同一任务的上一次比过的,另给「对比上一次」;
* 发出去的通知逐条写结果。refreshKey 变了(立即运行之后)从头重取
* 写原因;发起了的链到那次运行、写运行现在的状态;运行成功结束后服务端和同一任务上一次成功的运行比过的,另给
* 「与上一次对比」;发出去的通知逐条写结果。refreshKey 变了(立即运行之后)从头重取
*/
export function FireHistory({ schedule, refreshKey }: { schedule: Schedule; refreshKey: number }) {
const [items, setItems] = useState<ScheduleFire[] | null>(null)
@@ -142,21 +142,31 @@ function FireRow({ fire: f, tz, now }: { fire: ScheduleFire; tz: string; now: nu
}
/**
* 「对比上一次」:去对比页,本次是这次触发的运行、基准是服务端自动对比时取的同一任务的上一次。悬停写各类指标的个数
* (和通知里那一行同一个写法),读屏把它当说明念。带上来历,对比页据此写「默认基准:同一定时任务的上一次运行」
* 「与上一次对比」:去对比页,本次是这次触发的运行、基准是服务端自动对比时取的同一任务上一次成功的运行。旁边写有几个
* 指标有变化(触屏没有悬停,键盘聚焦也不显示悬停),悬停写各类指标的个数(和通知里那一行同一个写法),读屏把它当
* 说明念。基准就是紧挨着的上一次时带上来历,对比页据此写「默认基准:同一定时任务的上一次运行」;不是(上一次失败了、
* 取消了)时不带,免得说错,悬停写明比的是哪一次
*/
function CompareLink({ runId, compare }: { runId: string; compare: ScheduleFireCompare }) {
const via: CompareVia = { base: compare.base_run_id, reason: 'same_schedule' }
const previous = compare.previous !== false
const via: CompareVia | undefined = previous ? { base: compare.base_run_id, reason: 'same_schedule' } : undefined
const count = T.compareCount(compare.summary)
return (
<Link
to={comparePath(runId, compare.base_run_id)}
state={via}
title={T.compareTitle(compare.summary)}
title={T.compareTitle(compare.summary, previous ? null : shortId(compare.base_run_id))}
data-fire-compare={compare.base_run_id}
className="inline-flex shrink-0 items-center gap-1 rounded-sm text-2xs text-dim outline-none hover:text-fg hover:underline focus-visible:ring-2 focus-visible:ring-[var(--accent)]"
>
<GitCompareArrows size={11} aria-hidden />
{T.compareLink}
<span data-fire-compare-label="">{T.compareLink}</span>
{count && (
<>
<span aria-hidden>·</span>
<span className="tnum" data-fire-compare-count="">{count}</span>
</>
)}
</Link>
)
}
@@ -9,7 +9,7 @@ import type { ScheduleEvent, ScheduleWebhook, ScheduleWebhookTest } from '../../
import { SCHEDULE_EVENTS, WEBHOOK_FORMATS, isHttpUrl, webhookTestText, type FormField, type WebhookForm } from './model'
/**
* Webhook 通知:格式、地址、签名密钥、订阅事件、发送测试消息,外加通知里运行链接用的服务访问地址。
* Webhook 通知:格式、地址、签名密钥、订阅事件、发送测试消息,外加通知里运行、对比页链接用的服务访问地址。
*
* 地址和密钥保存之后服务端不再返回明文:地址只显示主机和末 4 位(url_hint),可以替换或删除;密钥只说「已设置」,
* 可以替换或清除。没点替换时请求里不带它们,改别的字段不会把地址清掉。测试消息用的是已保存的设置,
@@ -195,7 +195,7 @@ function SecretField({ value: w, saved, onChange, error }: {
}
/**
* 通知里运行链接用的服务访问地址:设置里 notify 一组的 public_base_url,所有定时任务共用。这里给出当前值和修改入口,
* 通知里运行、对比页链接用的服务访问地址:设置里 notify 一组的 public_base_url,所有定时任务共用。这里给出当前值和修改入口,
* 写的时候先重读一遍 notify 组、只换这一项,不把同组别的设置冲掉
*/
function LinkBase() {
+48 -11
View File
@@ -223,6 +223,11 @@ export const isUnsupported = (e: unknown) => e instanceof ApiError && e.status =
* 不认识的 id 再取一次列表(一分钟内最多一次)。取不到(老服务端、暂时连不上)不要紧,标记照样显示,只是不写名字
*/
const names = new Map<string, string>()
/**
* 已删除的定时任务:取回的列表里没有的(列表是全部定时任务,服务端不分页),或者刚在本页删掉的。运行详情页头据此不再
* 链过去。列表没取到时谁都不算删除:只是不知道
*/
const missing = new Set<string>()
let fetchedAt = 0
let inflight: Promise<void> | null = null
let namesVersion = 0
@@ -236,16 +241,30 @@ const emitNames = () => {
/** 记下读到的定时任务名字(gone 里的是刚删掉的) */
export function rememberScheduleNames(items: Pick<Schedule, 'id' | 'name'>[], gone: string[] = []) {
for (const s of items) names.set(s.id, s.name)
for (const id of gone) names.delete(id)
for (const s of items) {
names.set(s.id, s.name)
missing.delete(s.id)
}
for (const id of gone) {
names.delete(id)
missing.add(id)
}
emitNames()
}
function ensureNames(ids: string[]) {
if (inflight || !ids.some((id) => !names.has(id)) || Date.now() - fetchedAt < NAMES_RETRY_MS) return
if (inflight || !ids.some((id) => !names.has(id) && !missing.has(id)) || Date.now() - fetchedAt < NAMES_RETRY_MS) return
inflight = api.schedules.list({ timeoutMs: 10_000 })
.then((r) => { for (const s of r.items ?? []) names.set(s.id, s.name) })
.catch(() => { /* 取不到就不写名字 */ })
.then((r) => {
const items = r.items ?? []
for (const s of items) {
names.set(s.id, s.name)
missing.delete(s.id)
}
const listed = new Set(items.map((s) => s.id))
for (const id of ids) if (!listed.has(id)) missing.add(id)
})
.catch(() => { /* 取不到就不写名字,也不算删除 */ })
.finally(() => {
inflight = null
fetchedAt = Date.now()
@@ -253,6 +272,9 @@ function ensureNames(ids: string[]) {
})
}
/** 这个定时任务已删除(取回的列表里没有它、或者刚在本页删掉)。和 useScheduleNames 一起用:取回来后会重渲染 */
export const scheduleGone = (id: string) => missing.has(id)
/** 这些定时任务的名字(id → 名字)。没记过的去取一次,取回来后重渲染 */
export function useScheduleNames(ids: (string | null | undefined)[]): ReadonlyMap<string, string> {
useSyncExternalStore(
@@ -302,29 +324,44 @@ export function ScheduleTag({ scheduleId, name }: { scheduleId: string; name?: s
*
* 到点发起的运行(以及没有署名的立即运行)记在「定时任务:X」名下:原来那句「定时任务:X 发起」整句换成这条链接,
* 不写两遍。有人署名点「立即运行」的,署名照写,后面接「来自定时任务「X」」。名字取定时任务现在的名字(改过名的写
* 新名字),取不到时用署名里记的那个,再没有就不写名字。页头窄时链接截断,全名在悬停里
* 新名字),取不到时用署名里记的那个,再没有就不写名字。
*
* 前面带和「定时」标记一样的日历图标:页头这一行都是灰字,不带记号看不出这一段能点。页头窄时这一行换行,链接至少留
* 几个字宽(以前这一行不换行,只有链接能缩,窄窗口里被挤成 0 宽,Tab 停在一个看不见的链接上),再长截断,全名在悬停里。
* 定时任务已经删除的写成纯文本(链过去只有「不存在」页),同一行的「工作流已删除」也是这样
*/
export function RunScheduleSource({ scheduleId, startedBy }: { scheduleId: string; startedBy?: string | null }) {
const names = useScheduleNames([scheduleId])
const recorded = startedBy?.startsWith(T.actorPrefix) ? startedBy.slice(T.actorPrefix.length).trim() : null
const auto = !startedBy || recorded != null
const name = names.get(scheduleId) || recorded || null
const link = (
const body = (text: string) => (
<>
<CalendarClock size={10} aria-hidden className="shrink-0" />
<span className="min-w-0 truncate">{text}</span>
</>
)
const source = scheduleGone(scheduleId) ? (
<span title={T.runSourceGoneTitle} data-run-schedule-gone={scheduleId}
className="inline-flex min-w-[7em] max-w-full items-center gap-1">
{body(auto ? T.runSourceGone(name) : T.runSourceManualGone(name))}
</span>
) : (
<Link
to={`/schedules/${encodeURIComponent(scheduleId)}`}
title={T.runSourceTitle(name)}
data-run-schedule-link={scheduleId}
className="min-w-0 truncate rounded-sm text-dim outline-none hover:text-fg hover:underline focus-visible:ring-2 focus-visible:ring-[var(--accent)]"
className="inline-flex min-w-[7em] max-w-full items-center gap-1 rounded-sm text-dim outline-none hover:text-fg hover:underline focus-visible:ring-2 focus-visible:ring-[var(--accent)]"
>
{auto ? T.runSource(name) : T.runSourceManual(name)}
{body(auto ? T.runSource(name) : T.runSourceManual(name))}
</Link>
)
if (auto || !startedBy) return link
if (auto || !startedBy) return source
return (
<>
<span className="shrink-0">{T.runStarter(startedBy)}</span>
<span>·</span>
{link}
{source}
</>
)
}
+9 -3
View File
@@ -3208,12 +3208,17 @@ export interface ScheduleFireNotice {
}
/**
* 运行结束后和同一定时任务上一次运行的自动对比:基准是哪一次、各类指标的个数(同对比接口的 summary)。只有个数,
* 具体的数在对比页上
* 运行成功结束后和同一定时任务上一次成功的运行的自动对比:基准是哪一次、各类指标的个数(同对比接口的 summary)。
* 只有个数,具体的数在对比页上
*/
export interface ScheduleFireCompare {
base_run_id: string
summary: RunCompareSummary
/**
* 基准是不是紧挨着的上一次。上一次失败了、取消了时,基准是再往前成功的那一次,为 false:界面写明比的是哪一次。
* 老服务端不给,按 true 看
*/
previous?: boolean
}
/** 一次触发(触发历史的一行) */
@@ -3230,7 +3235,8 @@ export interface ScheduleFire {
reason: string | null
notified: ScheduleFireNotice[]
/**
* 和同一定时任务上一次的对比。没有上一次、还没算、比不了、运行又在执行(不在终态)时为 null;老服务端不给
* 和同一定时任务上一次成功的运行的对比。运行没有成功结束、没有可比的、还没算、比不了、任何一边又在执行(不在终态)
* 或重新封存过时为 null;老服务端不给
*/
compare?: ScheduleFireCompare | null
created_at: string