perf(short-drama-agent-front): 优化记录加载与工作区体验
This commit is contained in:
1 parent
d0264c08ce
commit
db9aea1694
111 files changed
+1680
-1290
No files matched your search
@@ -1,11 +1,11 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, ref, type Ref } from 'vue'
|
||||
import { vi } from 'vitest'
|
||||
import type { ProjectDetail, ProjectStageReadiness } from '../features/projects/types'
|
||||
import type { Checkpoint } from '../features/workflows/types'
|
||||
import type { useProjectData } from '../features/projects/context'
|
||||
import type { Checkpoint, CheckpointSummary } from '../features/workflows/types'
|
||||
import type { CheckpointWorkflow, useProjectData } from '../features/projects/context'
|
||||
|
||||
/** 模拟正式项目上下文,测试不连接真实模型或数据库。 */
|
||||
export function testProjectContext(id = 'capability-test'): ReturnType<typeof useProjectData> {
|
||||
export function testProjectContext(id = 'capability-test') {
|
||||
const project: ProjectDetail = {
|
||||
id,
|
||||
title: '测试剧本',
|
||||
@@ -33,16 +33,68 @@ export function testProjectContext(id = 'capability-test'): ReturnType<typeof us
|
||||
subjectAssets: { ready: true, reason: null },
|
||||
storyboard: { ready: true, reason: null }
|
||||
}
|
||||
const data = ref({ project, checkpoints: [] as Checkpoint[], stageReadiness })
|
||||
return {
|
||||
data,
|
||||
project: computed(() => data.value.project),
|
||||
checkpoints: computed(() => data.value.checkpoints),
|
||||
stageReadiness: computed(() => data.value.stageReadiness),
|
||||
loading: ref(false),
|
||||
error: ref(''),
|
||||
updatedAt: ref(''),
|
||||
refresh: vi.fn<() => Promise<void>>().mockResolvedValue(),
|
||||
refreshStageReadiness: vi.fn<() => Promise<void>>().mockResolvedValue()
|
||||
}
|
||||
return testProjectContextFrom(ref({ project, checkpoints: [] as Checkpoint[], stageReadiness }))
|
||||
}
|
||||
|
||||
/**
|
||||
* 按正式契约从历史生成每个工作流的最新摘要。
|
||||
* @param records 测试历史记录
|
||||
* @returns 不含正文的工作流摘要
|
||||
*/
|
||||
export function testCheckpointSummaries(records: Checkpoint[]): CheckpointSummary[] {
|
||||
const latest = new Map<string, Checkpoint>()
|
||||
for (const record of records.toSorted((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt)))
|
||||
latest.set(record.workflowName, record)
|
||||
return Array.from(latest.values(), record => ({
|
||||
checkpointId: record.checkpointId,
|
||||
workflowName: record.workflowName,
|
||||
createdAt: record.createdAt,
|
||||
updatedAt: record.updatedAt ?? record.createdAt,
|
||||
state: record.state.workflowExecution
|
||||
? { workflowExecution: { status: record.state.workflowExecution.status } }
|
||||
: {}
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用已加载的测试项目构造布局上下文。
|
||||
* @param data 测试中可修改的正式项目和保存记录
|
||||
* @returns 带查询状态的页面上下文
|
||||
*/
|
||||
export function testProjectContextFrom(
|
||||
data: Ref<{
|
||||
project: ProjectDetail
|
||||
checkpoints: Checkpoint[]
|
||||
stageReadiness: ProjectStageReadiness
|
||||
}>
|
||||
) {
|
||||
const refresh = vi.fn<() => Promise<void>>().mockResolvedValue()
|
||||
const refreshProject = vi.fn<() => Promise<void>>().mockResolvedValue()
|
||||
const refreshStageReadiness = vi.fn<() => Promise<void>>().mockResolvedValue()
|
||||
const project = computed(() => data.value.project)
|
||||
const stageReadiness = computed(() => data.value.stageReadiness)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const queryState = { loading, error, updatedAt: ref(''), refresh }
|
||||
const checkpoints = computed(() => data.value.checkpoints)
|
||||
const summaryQuery = { ...queryState, data: computed(() => testCheckpointSummaries(checkpoints.value)) }
|
||||
const context = {
|
||||
project,
|
||||
projectQuery: { ...queryState, data: project },
|
||||
stageReadiness,
|
||||
readinessQuery: { ...queryState, data: stageReadiness },
|
||||
summaryQuery,
|
||||
summaryBlocked: computed(() => loading.value || !!error.value),
|
||||
loading: computed(() => loading.value),
|
||||
error: computed(() => error.value),
|
||||
refresh,
|
||||
refreshProject,
|
||||
refreshStageReadiness,
|
||||
useWorkflowCheckpoints: (workflow: CheckpointWorkflow) => ({
|
||||
...queryState,
|
||||
data: computed(() => checkpoints.value.filter(item => item.workflowName === workflow))
|
||||
}),
|
||||
refreshWorkflow: vi.fn<() => Promise<void>>(() => refresh())
|
||||
} satisfies ReturnType<typeof useProjectData>
|
||||
return { ...context, data, checkpoints, loading, error }
|
||||
}
|
||||
Reference in new issue
Block a user