Commit ef2f3d16 authored by edy's avatar edy

fix(ui): default automation tasks to general assistant

parent c8f6b1df
Pipeline #18476 failed
......@@ -46,12 +46,12 @@ function toDateTimeLocalValue(date: Date) {
return `${year}-${month}-${day}T${hour}:${minute}`
}
function createDefaultForm(projects: ProjectSummary[]): AutomationTaskFormState {
function createDefaultForm(): AutomationTaskFormState {
const nextHour = new Date(Date.now() + 60 * 60 * 1000)
return {
title: "",
prompt: "",
expertId: projects[0]?.id ?? "",
expertId: "",
enabled: true,
scheduleKind: "daily",
runAt: toDateTimeLocalValue(nextHour),
......@@ -61,7 +61,7 @@ function createDefaultForm(projects: ProjectSummary[]): AutomationTaskFormState
}
function formFromTask(task: AutomationTask): AutomationTaskFormState {
const base = createDefaultForm([])
const base = createDefaultForm()
const schedule = task.schedule
return {
id: task.id,
......@@ -193,10 +193,6 @@ export function AutomationTasksView({ projects }: AutomationTasksViewProps) {
}))
], [projects])
const selectedTask = useMemo(
() => tasks.find((task) => task.id === selectedTaskId) ?? tasks[0],
[selectedTaskId, tasks]
)
const filteredTasks = useMemo(() => tasks.filter((task) => {
if (filterMode === "enabled") {
return task.enabled
......@@ -206,6 +202,10 @@ export function AutomationTasksView({ projects }: AutomationTasksViewProps) {
}
return true
}), [filterMode, tasks])
const selectedTask = useMemo(
() => filteredTasks.find((task) => task.id === selectedTaskId) ?? filteredTasks[0],
[selectedTaskId, filteredTasks]
)
useEffect(() => {
selectedTaskIdRef.current = selectedTask?.id ?? ""
......@@ -252,7 +252,7 @@ export function AutomationTasksView({ projects }: AutomationTasksViewProps) {
}, [loadSelectedTaskRuns])
const startCreate = () => {
setForm(createDefaultForm(projects))
setForm(createDefaultForm())
}
const startEdit = (task: AutomationTask) => {
......
......@@ -61,6 +61,14 @@ test("automation task edit can clear the selected expert", () => {
assert.match(automationViewSource, /const expertName = form\.expertId \? selectedExpert\?\.label : \(form\.id \? null : undefined\)/)
})
test("automation task default expert is labeled as the general assistant", () => {
assert.match(automationViewSource, /expertId: "",/)
assert.match(automationViewSource, /\{ id: "", label: "通用助手" \}/)
assert.match(automationViewSource, /<span className="automation-kicker">\{selectedTask\.expertName \|\| "通用助手"\}<\/span>/)
assert.doesNotMatch(automationViewSource, /千匠问天/)
assert.doesNotMatch(mockApiSource, /expertName:\s*"千匠问天"/)
})
test("automation run replies use shared markdown rendering", () => {
assert.match(automationViewSource, /renderChatMessageContent/)
assert.match(automationViewSource, /markdown-body automation-run-markdown/)
......@@ -127,6 +135,12 @@ test("run-now button derives selected task running state from optimistic state o
assert.match(automationViewSource, /disabled=\{saving \|\| isRunningSelectedTask\}/)
})
test("automation detail selection follows the filtered task list", () => {
assert.match(automationViewSource, /const selectedTask = useMemo\(\s*\(\) => filteredTasks\.find\(\(task\) => task\.id === selectedTaskId\) \?\? filteredTasks\[0\]/s)
assert.match(automationViewSource, /\[selectedTaskId, filteredTasks\]/)
assert.doesNotMatch(automationViewSource, /tasks\.find\(\(task\) => task\.id === selectedTaskId\) \?\? tasks\[0\]/)
})
test("automation task runs poll while a selected task has optimistic state or active run records", () => {
assert.match(automationViewSource, /const loadSelectedTaskRuns = useCallback/)
assert.match(automationViewSource, /const selectedTaskIdRef = useRef\(""\)/)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment