feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -6,6 +6,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
|
||||
import {
|
||||
resolveFilePrimaryActionPresentation,
|
||||
resolveConversationTaskActionPresentation,
|
||||
resolveProcessingActionPresentation,
|
||||
} from './actionPresentation';
|
||||
@@ -43,6 +44,45 @@ function projection(
|
||||
}
|
||||
|
||||
describe('resolveProcessingActionPresentation', () => {
|
||||
it('hides a file-row primary action when it only duplicates lifecycle navigation', () => {
|
||||
const result = resolveFilePrimaryActionPresentation(projection({
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'order_review', lifecycleStage: 'order_review',
|
||||
lifecycleEntries: [{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||||
blocking_reason: null,
|
||||
primary_action: {
|
||||
code: 'open_order_review', i18nKey: null, parameters: {},
|
||||
executionMode: 'navigate', targetSurface: 'order_lifecycle_workbench',
|
||||
targetLifecycleStage: 'order_review',
|
||||
},
|
||||
secondary_actions: [],
|
||||
},
|
||||
}));
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('keeps an authorized business action as the file-row primary action', () => {
|
||||
const result = resolveFilePrimaryActionPresentation(projection({
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'order_review', lifecycleStage: 'order_review',
|
||||
lifecycleEntries: [{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||||
blocking_reason: null,
|
||||
primary_action: {
|
||||
code: 'create_draft', i18nKey: null, parameters: {},
|
||||
executionMode: 'navigate', targetSurface: 'order_lifecycle_workbench',
|
||||
targetLifecycleStage: 'order_review',
|
||||
},
|
||||
secondary_actions: [],
|
||||
},
|
||||
}));
|
||||
|
||||
expect(result).toMatchObject({
|
||||
actionCode: 'create_draft',
|
||||
labelKey: 'chat.shippingProcessing.action.create_draft',
|
||||
});
|
||||
});
|
||||
|
||||
it('hides an internal edit_draft capability on the review surface', () => {
|
||||
const result = resolveProcessingActionPresentation({
|
||||
workItemType: 'order_intake',
|
||||
@@ -71,9 +111,7 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
},
|
||||
availableActions: ['refresh', 'retry'],
|
||||
}));
|
||||
expect(result.primary?.intent).toBe('refresh');
|
||||
expect(result.secondary?.intent).toBe('retry');
|
||||
expect(result.overflow).toEqual([]);
|
||||
expect(result).toEqual({ primary: null, secondary: null, overflow: [] });
|
||||
});
|
||||
|
||||
it('uses ui_state actions as the only source when the backend supplies it', () => {
|
||||
@@ -112,7 +150,7 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
}), { surface: 'right' });
|
||||
|
||||
expect(result.primary).toMatchObject({
|
||||
intent: 'retry', actionCode: 'retry_order_extraction',
|
||||
intent: 'retry_order_extraction', actionCode: 'retry_order_extraction',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -157,14 +195,35 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
expect(result.primary).toBeNull();
|
||||
});
|
||||
|
||||
it('maps retry_parse to retry intent', () => {
|
||||
it('maps retry_parse to its exact action intent', () => {
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
status: 'failed',
|
||||
stage: 'document_parsing',
|
||||
availableActions: ['retry_parse'],
|
||||
uiState: {
|
||||
status: 'failed', stage: 'document_parsing', blocking_reason: null,
|
||||
primary_action: { code: 'retry_parse', i18nKey: 'action.retry_parse', parameters: {} },
|
||||
secondary_actions: [],
|
||||
},
|
||||
}));
|
||||
expect(result.primary?.intent).toBe('retry');
|
||||
expect(result.primary?.intent).toBe('retry_parse');
|
||||
expect(result.primary?.actionCode).toBe('retry_parse');
|
||||
expect(result.primary?.labelKey).toBe('chat.shippingProcessing.action.reparse');
|
||||
});
|
||||
|
||||
it('uses the same user-facing label for a Case reparse action', () => {
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
status: 'waiting_human',
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'candidate_creating', blocking_reason: null,
|
||||
primary_action: { code: 'reparse', i18nKey: 'shipping.actions.reparse', parameters: {} },
|
||||
secondary_actions: [],
|
||||
},
|
||||
}), { surface: 'right' });
|
||||
|
||||
expect(result.primary).toMatchObject({
|
||||
intent: 'reparse', actionCode: 'reparse',
|
||||
labelKey: 'chat.shippingProcessing.action.reparse',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps inventory preparation retry as the batch-card primary action', () => {
|
||||
@@ -191,7 +250,11 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
|
||||
it('uses the shared inventory presentation for a rematch action', () => {
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
availableActions: ['retry_inventory_matching'],
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'inventory_matching', blocking_reason: null,
|
||||
primary_action: { code: 'retry_inventory_matching', i18nKey: null, parameters: {} },
|
||||
secondary_actions: [],
|
||||
},
|
||||
}), { surface: 'right' });
|
||||
|
||||
expect(result.primary).toMatchObject({
|
||||
@@ -202,7 +265,14 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
|
||||
it('filters open_order_review and refresh on review surface', () => {
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
availableActions: ['open_order_review', 'refresh', 'view_result'],
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'order_review', blocking_reason: null,
|
||||
primary_action: { code: 'view_result', i18nKey: null, parameters: {} },
|
||||
secondary_actions: [
|
||||
{ code: 'open_order_review', enabled: true },
|
||||
{ code: 'refresh', enabled: true },
|
||||
],
|
||||
},
|
||||
}), { surface: 'review', actionsExecutable: true });
|
||||
expect(result.primary?.intent).toBe('view_result');
|
||||
expect(result.overflow.some((i) => i.intent === 'open_order_review')).toBe(false);
|
||||
@@ -211,10 +281,18 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
|
||||
it('available_actions 乱序 / 大小写空格 / 重复不影响输出按钮顺序', () => {
|
||||
const order1 = resolveProcessingActionPresentation(projection({
|
||||
availableActions: [' Refresh ', 'view_details', 'retry_parse', 'view_details'],
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'document_parsing', blocking_reason: null,
|
||||
primary_action: { code: 'retry_parse', i18nKey: null, parameters: {} },
|
||||
secondary_actions: [{ code: 'view_details', enabled: true }, { code: 'refresh', enabled: true }],
|
||||
},
|
||||
}), { surface: 'chat', actionsExecutable: true });
|
||||
const order2 = resolveProcessingActionPresentation(projection({
|
||||
availableActions: ['retry_parse', 'VIEW_DETAILS', 'refresh'],
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'document_parsing', blocking_reason: null,
|
||||
primary_action: { code: 'retry_parse', i18nKey: null, parameters: {} },
|
||||
secondary_actions: [{ code: 'VIEW_DETAILS', enabled: true }, { code: 'refresh', enabled: true }],
|
||||
},
|
||||
}), { surface: 'chat', actionsExecutable: true });
|
||||
// presentation 主/次/溢出的 intent 序列必须相同,不受后端原始顺序影响。
|
||||
const intentChain = (r: typeof order1) => [
|
||||
@@ -227,7 +305,11 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
|
||||
it('keeps the primary order-review action semantic when it navigates to the lifecycle workbench', () => {
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
availableActions: ['open_order_review'],
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'order_review', blocking_reason: null,
|
||||
primary_action: { code: 'open_order_review', i18nKey: 'chat.shippingProcessing.action.open_order_review', parameters: {} },
|
||||
secondary_actions: [],
|
||||
},
|
||||
}), { surface: 'chat' });
|
||||
// 工作台是执行位置;第一行必须说明当前要做的业务动作,而不是复用第二行阶段入口的总称。
|
||||
expect(result.primary?.labelKey).toBe('chat.shippingProcessing.action.open_order_review');
|
||||
@@ -236,7 +318,11 @@ describe('resolveProcessingActionPresentation', () => {
|
||||
it('does not reinterpret a backend view action as lifecycle authorization', () => {
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
status: 'waiting_human',
|
||||
availableActions: ['view'],
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'order_review', blocking_reason: null,
|
||||
primary_action: { code: 'view', i18nKey: null, parameters: {} },
|
||||
secondary_actions: [],
|
||||
},
|
||||
}), { surface: 'chat' });
|
||||
|
||||
// 生命周期入口必须由后端显式返回 open_order_review;view 只能保持查看语义。
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* features/shipping-progress/actionPresentation.ts
|
||||
* 用途:从统一投影 / 会话 OT 任务解析四页面共用的 ActionPresentation(主/次/溢出)。
|
||||
* 依赖:ShippingProcessingProjection、ConversationProcessingUserTask、workbenchActionRegistry、types。
|
||||
* 逻辑:新版优先 ui_state.primary_action / secondary_actions;旧响应才兼容 primaryAction / availableActions;
|
||||
* 逻辑:只消费后端 ui_state.primary_action / secondary_actions;
|
||||
* cancel_* 与 view_details 永不作主 CTA;无业务入口时 focus_task 兜底并映射「查看进度」;
|
||||
* 自动处理中(processing/automating)主按钮为空;review 面经注册表 fail-closed 过滤。
|
||||
*/
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
warnUnregisteredWorkbenchAction,
|
||||
} from './workbenchActionRegistry';
|
||||
|
||||
/** 可映射为统一意图的原始动作码(gate / available_actions)。 */
|
||||
/** 可映射为统一意图的后端已授权动作码。 */
|
||||
const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
open_order_review: 'open_order_review',
|
||||
open_review: 'open_order_review',
|
||||
@@ -34,22 +34,36 @@ const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
adjudicate_duplicate: 'adjudicate_duplicate',
|
||||
open_inventory_match_review: 'open_inventory_match_review',
|
||||
open_shortage_review: 'open_shortage_review',
|
||||
retry_inventory_preparation: 'retry',
|
||||
retry_inventory_matching: 'open_inventory_match_review',
|
||||
retry: 'retry',
|
||||
retry_inventory_preparation: 'retry_inventory_preparation',
|
||||
retry_inventory_matching: 'retry_inventory_matching',
|
||||
reparse_batch: 'reparse_batch',
|
||||
retry_parse: 'retry',
|
||||
retry_failed_documents: 'retry',
|
||||
retry_failed_attachments: 'retry',
|
||||
retry_freight_upload_rpa: 'retry',
|
||||
retry_order_extraction: 'retry',
|
||||
retry_layout_parsing: 'retry',
|
||||
retry_parse: 'retry_parse',
|
||||
retry_failed_documents: 'retry_failed_documents',
|
||||
retry_failed_attachments: 'retry_failed_attachments',
|
||||
retry_freight_upload_rpa: 'retry_freight_upload_rpa',
|
||||
retry_order_extraction: 'retry_order_extraction',
|
||||
retry_layout_parsing: 'retry_layout_parsing',
|
||||
rematerialize_document: 'rematerialize_document',
|
||||
reroute_document_profile: 'reroute_document_profile',
|
||||
revalidate_reservation: 'revalidate_reservation',
|
||||
retry_customer_resolution: 'retry_customer_resolution',
|
||||
retry_duplicate_detection: 'retry_duplicate_detection',
|
||||
retry_with_latest_rules: 'retry_with_latest_rules',
|
||||
recheck_freeze_readiness: 'recheck_freeze_readiness',
|
||||
retry_task_creation: 'retry_task_creation',
|
||||
retry_inventory_field_mapping: 'retry_inventory_field_mapping',
|
||||
recheck_inventory_sufficiency: 'recheck_inventory_sufficiency',
|
||||
recheck_excel_readiness: 'recheck_excel_readiness',
|
||||
poll_inventory_preparation: 'refresh',
|
||||
poll_freight_upload_rpa: 'refresh',
|
||||
edit_order_fields: 'open_order_review',
|
||||
edit_reservation: 'open_order_review',
|
||||
// 订单识别复核卡后端动作码:统一复用右侧「进入订单处理/重试解析/查看结果」执行器。
|
||||
edit_draft: 'open_order_review',
|
||||
reconcile_and_progress: 'open_order_review',
|
||||
create_draft: 'open_order_review',
|
||||
retry_stp_auto_create: 'retry',
|
||||
reparse: 'retry',
|
||||
retry_stp_auto_create: 'retry_stp_auto_create',
|
||||
reparse: 'reparse',
|
||||
view: 'view_result',
|
||||
refresh: 'refresh',
|
||||
regenerate_excel_artifact: 'regenerate_excel',
|
||||
@@ -69,8 +83,28 @@ const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
};
|
||||
|
||||
const AUTOMATING_STATUSES = new Set(['processing', 'automating', 'queued']);
|
||||
/** 需要在聊天/右侧展示精确恢复动作文案的正式 action_code。 */
|
||||
const RECOVERY_ACTION_CODES = new Set([
|
||||
'retry_inventory_preparation', 'retry_inventory_matching', 'retry_parse',
|
||||
'retry_failed_documents', 'retry_failed_attachments', 'retry_freight_upload_rpa',
|
||||
'retry_order_extraction', 'retry_layout_parsing', 'rematerialize_document',
|
||||
'reroute_document_profile', 'revalidate_reservation', 'retry_customer_resolution',
|
||||
'retry_duplicate_detection', 'retry_with_latest_rules', 'recheck_freeze_readiness',
|
||||
'retry_task_creation', 'retry_inventory_field_mapping', 'recheck_inventory_sufficiency',
|
||||
'recheck_excel_readiness', 'retry_stp_auto_create', 'reparse',
|
||||
]);
|
||||
/** 永不升为主 CTA 的动作码(仍可作次要/溢出)。 */
|
||||
const NEVER_PRIMARY_CODES = new Set(['cancel_task', 'cancel_run', 'view_details']);
|
||||
/** 五阶段已单独提供入口的纯查看/导航动作,不应再占用文件行主 CTA。 */
|
||||
const FILE_ROW_NAVIGATION_CODES = new Set([
|
||||
'open_order_review',
|
||||
'open_review',
|
||||
'open_order_processing',
|
||||
'enter_manual_review',
|
||||
'view',
|
||||
'view_result',
|
||||
'view_record',
|
||||
]);
|
||||
/**
|
||||
* 仅供执行编排或历史审计使用的库存恢复动作;不得重新暴露为正式用户 CTA。
|
||||
* 它们会绕过当前库存步骤的标准语义,用户入口必须使用 retry_inventory_preparation
|
||||
@@ -117,7 +151,7 @@ export function isInternalInventoryAction(code: string | null | undefined): bool
|
||||
/**
|
||||
* 将原始动作码映射为统一意图;未知码返回 null。
|
||||
*
|
||||
* @param code - Gate / available_actions 原始码
|
||||
* @param code - 后端已授权动作码
|
||||
*/
|
||||
export function mapActionCodeToIntent(code: string | null | undefined): ShippingProcessingActionIntent | null {
|
||||
const normalized = String(code || '').trim().toLowerCase();
|
||||
@@ -142,14 +176,21 @@ function toItem(
|
||||
// 只读导航动作码而误显示为订单处理。该分支不改变权限或路由目标。
|
||||
if (targetLifecycleStage === 'intake_parse') {
|
||||
labelKey = 'chat.shippingProcessing.action.open_intake_parse';
|
||||
} else if (normalized === 'create_draft' || normalized === 'edit_draft' || normalized === 'validate') {
|
||||
labelKey = `chat.shippingProcessing.action.${normalized}`;
|
||||
} else if (inventoryActionLabelKey(normalized)) {
|
||||
labelKey = inventoryActionLabelKey(normalized)!;
|
||||
} else if (normalized === 'retry_freight_upload_rpa') {
|
||||
labelKey = 'chat.shippingNoticeRetryUploadAction';
|
||||
} else if (normalized === 'reparse_batch') {
|
||||
labelKey = 'chat.shippingProcessing.action.reparse_batch';
|
||||
} else if (intent === 'retry' && chatOrRight) {
|
||||
labelKey = 'chat.shippingProcessing.action.retry_parse';
|
||||
} else if (normalized === 'reparse' || normalized === 'retry_parse') {
|
||||
// 两者都是对当前文件重新执行解析;不同 action_code 只区分后端目标,
|
||||
// 用户界面统一使用同一业务名称,避免把同一能力误解为不同操作。
|
||||
labelKey = 'chat.shippingProcessing.action.reparse';
|
||||
} else if (RECOVERY_ACTION_CODES.has(normalized) && chatOrRight) {
|
||||
// 重试必须保留 Gate/对象边界,不能退化为泛化动作名称。
|
||||
labelKey = `workspace.shippingNotice.processGate.actionCodes.${normalized}`;
|
||||
} else if (normalized === 'focus_task' && chatOrRight) {
|
||||
labelKey = 'chat.shippingProcessing.action.view_progress';
|
||||
} else if (normalized === 'cancel_task' || normalized === 'cancel_run') {
|
||||
@@ -209,11 +250,9 @@ export interface ResolveProcessingActionPresentationOptions {
|
||||
*
|
||||
* 核心逻辑:
|
||||
* 1. 有 ui_state 时只渲染其已授权主/次动作;
|
||||
* 2. 旧响应 processing/automating/queued → 主按钮为空(自动推进中);
|
||||
* 3. 旧响应由 primaryAction / availableActions 填主/次/溢出;
|
||||
* 4. completed/failed/cancelled → view_result / view_record 兜底;
|
||||
* 5. surface=review 时经注册表 fail-closed(未知隐藏 + 告警;隐藏 refresh/自跳转);
|
||||
* 6. cancel / view_details 强制降为次要或溢出。
|
||||
* 2. processing/automating/queued 且无 ui_state 动作时主按钮为空;
|
||||
* 3. surface=review 时经注册表 fail-closed(未知隐藏 + 告警;隐藏 refresh/自跳转);
|
||||
* 4. cancel / view_details 强制降为次要或溢出。
|
||||
*
|
||||
* @param projection - 统一处理投影
|
||||
* @param options - surface / actionsExecutable / panels
|
||||
@@ -229,8 +268,8 @@ export function resolveProcessingActionPresentation(
|
||||
const actionsExecutable = options?.actionsExecutable !== false;
|
||||
const panels = options?.panels ?? null;
|
||||
const authoritativeUiState = projection.uiState;
|
||||
const status = String(authoritativeUiState?.status || projection.userStatus || projection.status || '').trim().toLowerCase();
|
||||
if (!authoritativeUiState && AUTOMATING_STATUSES.has(status) && !projection.currentGate?.nextActionCode) {
|
||||
const status = String(authoritativeUiState?.status || '').trim().toLowerCase();
|
||||
if (!authoritativeUiState || AUTOMATING_STATUSES.has(status) && !authoritativeUiState.primary_action) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
@@ -242,7 +281,7 @@ export function resolveProcessingActionPresentation(
|
||||
targetLifecycleStage?: string | null,
|
||||
) => {
|
||||
const code = String(raw || '').trim();
|
||||
if (!code) return;
|
||||
if (!code || code.toLowerCase() === 'retry') return;
|
||||
const key = code.toLowerCase();
|
||||
if (isInternalInventoryAction(key)) return;
|
||||
// 仅用于管理员恢复缺失待办记录,不作为普通用户履约动作展示。
|
||||
@@ -291,14 +330,11 @@ export function resolveProcessingActionPresentation(
|
||||
));
|
||||
};
|
||||
|
||||
// [AUTHORITY] 新版只消费同一份 ui_state;currentGate 只保留诊断,禁止产生或替换按钮。
|
||||
// 旧服务端未下发 ui_state 时才兼容 primaryAction / availableActions。
|
||||
pushCode(authoritativeUiState
|
||||
? authoritativeUiState.primary_action?.code
|
||||
: projection.primaryAction?.code);
|
||||
const actionCodes = authoritativeUiState
|
||||
? authoritativeUiState.secondary_actions.filter((action) => action.enabled).map((action) => action.code)
|
||||
: normalizeActionCodes(projection.availableActions || []);
|
||||
// [AUTHORITY] ui_state 是唯一按钮合同;缺失即 fail-closed。
|
||||
pushCode(authoritativeUiState.primary_action?.code);
|
||||
const actionCodes = authoritativeUiState.secondary_actions
|
||||
.filter((action) => action.enabled)
|
||||
.map((action) => action.code);
|
||||
for (const action of actionCodes) {
|
||||
const secondary = authoritativeUiState?.secondary_actions.find((item) => item.code === action);
|
||||
pushCode(action, secondary?.targetLifecycleStage);
|
||||
@@ -307,9 +343,29 @@ export function resolveProcessingActionPresentation(
|
||||
return partitionActionItems(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析批次中心文件行的主动作。
|
||||
*
|
||||
* 核心逻辑:五阶段按钮是唯一的纯导航入口;文件行只保留后端授权的业务动作,
|
||||
* 不根据状态推导或新增动作,也不改变通用任务卡的动作展示。
|
||||
*/
|
||||
export function resolveFilePrimaryActionPresentation(
|
||||
projection: ShippingProcessingProjection | null | undefined,
|
||||
): ActionPresentationItem | null {
|
||||
const primaryAction = projection?.uiState?.primary_action;
|
||||
const code = String(primaryAction?.code || '').trim().toLowerCase();
|
||||
if (
|
||||
primaryAction?.executionMode === 'navigate'
|
||||
&& FILE_ROW_NAVIGATION_CODES.has(code)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return resolveProcessingActionPresentation(projection, { surface: 'right' }).primary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从会话 OT 任务投影解析 ActionPresentation(无 workItem 时的统一适配器)。
|
||||
* 核心逻辑:primary_action 优先;available_actions 补充;无正式入口时 focus_task→查看进度;
|
||||
* 核心逻辑:仅消费 ui_state 的 primary_action / secondary_actions;
|
||||
* cancel/view_details 永不作主 CTA。
|
||||
* @param task - 会话用户可见任务
|
||||
* @param options.surface - 展示面(默认 right)
|
||||
@@ -322,9 +378,8 @@ export function resolveConversationTaskActionPresentation(
|
||||
if (!task) return empty;
|
||||
|
||||
const surface = options?.surface || 'right';
|
||||
const userStatus = String(task.uiState?.status ?? task.userStatus ?? '').trim().toLowerCase();
|
||||
const legacyStatus = String(task.status_label ?? '').trim().toLowerCase();
|
||||
const status = userStatus || legacyStatus;
|
||||
const userStatus = String(task.uiState?.status ?? '').trim().toLowerCase();
|
||||
const status = userStatus;
|
||||
const isProcessing = task.group === 'processing' || AUTOMATING_STATUSES.has(status);
|
||||
if (task.group === 'history' || status === 'cancelled') {
|
||||
return empty;
|
||||
@@ -337,7 +392,7 @@ export function resolveConversationTaskActionPresentation(
|
||||
targetLifecycleStage?: string | null,
|
||||
) => {
|
||||
const code = String(raw || '').trim();
|
||||
if (!code) return;
|
||||
if (!code || code.toLowerCase() === 'retry') return;
|
||||
const key = code.toLowerCase();
|
||||
if (isInternalInventoryAction(key)) return;
|
||||
if (seen.has(key)) return;
|
||||
@@ -348,17 +403,10 @@ export function resolveConversationTaskActionPresentation(
|
||||
items.push(toItem(code, intent, surface, targetLifecycleStage));
|
||||
};
|
||||
|
||||
pushCode(
|
||||
task.uiState
|
||||
? task.uiState.primary_action?.code
|
||||
: (task.primaryAction?.code || task.primary_action),
|
||||
task.uiState?.primary_action?.targetLifecycleStage,
|
||||
);
|
||||
// [ORDER-STABLE] 对 available_actions 标准化排序,确保后端顺序变化不影响按钮渲染顺序。
|
||||
if (!task.uiState) return empty;
|
||||
pushCode(task.uiState.primary_action?.code, task.uiState.primary_action?.targetLifecycleStage);
|
||||
const normalizedTaskActions = normalizeActionCodes(
|
||||
task.uiState?.secondary_actions?.filter((item) => item.enabled).map((item) => item.code)
|
||||
|| task.available_actions
|
||||
|| [],
|
||||
task.uiState.secondary_actions.filter((item) => item.enabled).map((item) => item.code),
|
||||
);
|
||||
for (const action of normalizedTaskActions) {
|
||||
const secondary = task.uiState?.secondary_actions.find((item) => item.code === action);
|
||||
|
||||
@@ -101,7 +101,11 @@ describe('workbenchActionRegistry', () => {
|
||||
it('warns and omits unregistered action codes from review presentation', () => {
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
availableActions: ['totally_unknown_action', 'view_result'],
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'waiting_review', blocking_reason: null,
|
||||
primary_action: { code: 'totally_unknown_action', label_key: 'x' },
|
||||
secondary_actions: [{ code: 'view_result', enabled: true }],
|
||||
},
|
||||
}), { surface: 'review', actionsExecutable: true });
|
||||
expect(result.primary?.intent).toBe('view_result');
|
||||
expect(warn).toHaveBeenCalled();
|
||||
@@ -124,7 +128,7 @@ describe('workbenchActionRegistry', () => {
|
||||
},
|
||||
availableActions: ['refresh'],
|
||||
}), { surface: 'review', actionsExecutable: true });
|
||||
expect(result.primary?.intent).toBe('open_inventory_match_review');
|
||||
expect(result.primary?.intent).toBe('retry_inventory_matching');
|
||||
expect(result.primary?.actionCode).toBe('retry_inventory_matching');
|
||||
expect(result.secondary).toBeNull();
|
||||
});
|
||||
@@ -169,7 +173,7 @@ describe('workbenchActionRegistry', () => {
|
||||
}), { surface: 'review', actionsExecutable: true });
|
||||
|
||||
expect(result.primary?.actionCode).toBe('retry_freight_upload_rpa');
|
||||
expect(result.primary?.intent).toBe('retry');
|
||||
expect(result.primary?.intent).toBe('retry_freight_upload_rpa');
|
||||
expect(result.secondary?.actionCode).toBe('download_excel');
|
||||
expect(result.overflow.map((item) => item.actionCode)).not.toContain('mark_manual_uploaded');
|
||||
});
|
||||
@@ -177,6 +181,11 @@ describe('workbenchActionRegistry', () => {
|
||||
it('does not turn the admin todo-regeneration recovery action into manual upload', () => {
|
||||
const result = resolveProcessingActionPresentation(projection({
|
||||
stage: 'freight_uploading',
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'freight_uploading', blocking_reason: null,
|
||||
primary_action: { code: 'regenerate_manual_upload_todo', label_key: 'x' },
|
||||
secondary_actions: [{ code: 'download_excel', enabled: true }],
|
||||
},
|
||||
currentGate: {
|
||||
gateCode: 'manual_upload_handoff',
|
||||
status: 'blocked',
|
||||
@@ -184,7 +193,6 @@ describe('workbenchActionRegistry', () => {
|
||||
blockingReasonCode: 'manual_upload_todo_missing',
|
||||
attemptNo: 1,
|
||||
},
|
||||
availableActions: ['download_excel'],
|
||||
}), { surface: 'review', actionsExecutable: true });
|
||||
|
||||
expect(result.primary?.actionCode).toBe('download_excel');
|
||||
|
||||
@@ -18,7 +18,7 @@ export type WorkbenchActionExecutorKind =
|
||||
| 'focus_profile_panel'
|
||||
| 'focus_inventory_issues'
|
||||
| 'download'
|
||||
| 'retry'
|
||||
| 'submit_gate_action'
|
||||
| 'view_result'
|
||||
| 'view_record'
|
||||
| 'refresh_strip_only'
|
||||
@@ -139,7 +139,7 @@ export const WORKBENCH_ACTION_REGISTRY: Record<string, WorkbenchActionRegistryEn
|
||||
scrollTestId: 'review-formal-task-todo-panel',
|
||||
},
|
||||
retry_inventory_matching: {
|
||||
intent: 'open_inventory_match_review',
|
||||
intent: 'retry_inventory_matching',
|
||||
reviewBehavior: 'todo_panel',
|
||||
todoActionCode: 'retry_inventory_matching',
|
||||
requiresFormalTask: true,
|
||||
@@ -148,7 +148,7 @@ export const WORKBENCH_ACTION_REGISTRY: Record<string, WorkbenchActionRegistryEn
|
||||
scrollTestId: 'review-formal-task-todo-panel',
|
||||
},
|
||||
retry_inventory_preparation: {
|
||||
intent: 'retry',
|
||||
intent: 'retry_inventory_preparation',
|
||||
reviewBehavior: 'todo_panel',
|
||||
todoActionCode: 'retry_inventory_preparation',
|
||||
requiresFormalTask: true,
|
||||
@@ -216,7 +216,7 @@ export const WORKBENCH_ACTION_REGISTRY: Record<string, WorkbenchActionRegistryEn
|
||||
scrollTestId: 'review-formal-task-todo-panel',
|
||||
},
|
||||
retry_freight_upload_rpa: {
|
||||
intent: 'retry',
|
||||
intent: 'retry_freight_upload_rpa',
|
||||
reviewBehavior: 'todo_panel',
|
||||
todoActionCode: 'retry_freight_upload_rpa',
|
||||
requiresFormalTask: true,
|
||||
@@ -224,33 +224,27 @@ export const WORKBENCH_ACTION_REGISTRY: Record<string, WorkbenchActionRegistryEn
|
||||
stageFamily: 'post_create',
|
||||
scrollTestId: 'review-formal-task-todo-panel',
|
||||
},
|
||||
retry: {
|
||||
intent: 'retry',
|
||||
reviewBehavior: 'retry',
|
||||
isWrite: true,
|
||||
stageFamily: 'any',
|
||||
},
|
||||
reparse_batch: {
|
||||
intent: 'reparse_batch',
|
||||
reviewBehavior: 'retry',
|
||||
reviewBehavior: 'submit_gate_action',
|
||||
isWrite: true,
|
||||
stageFamily: 'any',
|
||||
},
|
||||
retry_parse: {
|
||||
intent: 'retry',
|
||||
reviewBehavior: 'retry',
|
||||
intent: 'retry_parse',
|
||||
reviewBehavior: 'submit_gate_action',
|
||||
isWrite: true,
|
||||
stageFamily: 'pre_create',
|
||||
},
|
||||
retry_failed_documents: {
|
||||
intent: 'retry',
|
||||
reviewBehavior: 'retry',
|
||||
intent: 'retry_failed_documents',
|
||||
reviewBehavior: 'submit_gate_action',
|
||||
isWrite: true,
|
||||
stageFamily: 'pre_create',
|
||||
},
|
||||
retry_failed_attachments: {
|
||||
intent: 'retry',
|
||||
reviewBehavior: 'retry',
|
||||
intent: 'retry_failed_attachments',
|
||||
reviewBehavior: 'submit_gate_action',
|
||||
isWrite: true,
|
||||
stageFamily: 'pre_create',
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user