feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* features/shipping-progress/actionPresentation.ts
|
||||
* 用途:从统一投影解析四页面共用的 ActionPresentation(主/次/溢出)。
|
||||
* 依赖:ShippingProcessingProjection、SHIPPING_PROCESSING_ACTION_INTENTS、types。
|
||||
* 逻辑:优先级 Gate.nextActionCode → availableActions → 终态查看 → none;
|
||||
* 自动处理中(processing/automating)主按钮为空,避免误导性 CTA。
|
||||
*/
|
||||
|
||||
import type {
|
||||
ShippingProcessingActionIntent,
|
||||
ShippingProcessingProjection,
|
||||
} from '@/features/chat/types/shipping.api.types';
|
||||
import type { ActionPresentation, ActionPresentationItem } from './types';
|
||||
|
||||
/** 可映射为统一意图的原始动作码(gate / available_actions)。 */
|
||||
const ACTION_CODE_TO_INTENT: Record<string, ShippingProcessingActionIntent> = {
|
||||
open_order_review: 'open_order_review',
|
||||
open_review: 'open_order_review',
|
||||
edit_formal_task: 'edit_formal_task',
|
||||
open_inventory_source_review: 'open_inventory_source_review',
|
||||
open_inventory_match_review: 'open_inventory_match_review',
|
||||
open_shortage_review: 'open_shortage_review',
|
||||
upload_inventory_file: 'upload_inventory_file',
|
||||
retry: 'retry',
|
||||
retry_parse: 'retry',
|
||||
refresh: 'refresh',
|
||||
regenerate_excel: 'regenerate_excel',
|
||||
download_excel: 'download_excel',
|
||||
open_manual_upload: 'open_manual_upload',
|
||||
wait_manual_upload: 'open_manual_upload',
|
||||
mark_manual_uploaded: 'open_manual_upload',
|
||||
regenerate_manual_upload_todo: 'open_manual_upload',
|
||||
view_result: 'view_result',
|
||||
view_details: 'view_result',
|
||||
view_record: 'view_record',
|
||||
};
|
||||
|
||||
const AUTOMATING_STATUSES = new Set(['processing', 'automating', 'queued']);
|
||||
|
||||
/**
|
||||
* 将原始动作码映射为统一意图;未知码返回 null。
|
||||
*/
|
||||
export function mapActionCodeToIntent(code: string | null | undefined): ShippingProcessingActionIntent | null {
|
||||
const normalized = String(code || '').trim().toLowerCase();
|
||||
if (!normalized) return null;
|
||||
return ACTION_CODE_TO_INTENT[normalized] || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建单个动作项。
|
||||
*/
|
||||
function toItem(code: string, intent: ShippingProcessingActionIntent): ActionPresentationItem {
|
||||
return {
|
||||
intent,
|
||||
actionCode: code,
|
||||
labelKey: `chat.shippingProcessing.action.${intent}`,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析统一动作投影。
|
||||
*
|
||||
* 核心逻辑:
|
||||
* 1. processing/automating/queued → 主按钮为空(自动推进中);
|
||||
* 2. currentGate.nextActionCode 优先;
|
||||
* 3. availableActions 依次填主/次/溢出;
|
||||
* 4. completed/failed/cancelled → view_result / view_record 兜底。
|
||||
*/
|
||||
export function resolveProcessingActionPresentation(
|
||||
projection: ShippingProcessingProjection | null | undefined,
|
||||
): ActionPresentation {
|
||||
const empty: ActionPresentation = { primary: null, secondary: null, overflow: [] };
|
||||
if (!projection) return empty;
|
||||
|
||||
const status = String(projection.status || '').trim().toLowerCase();
|
||||
if (AUTOMATING_STATUSES.has(status) && !projection.currentGate?.nextActionCode) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
const items: ActionPresentationItem[] = [];
|
||||
const seen = new Set<string>();
|
||||
|
||||
const pushCode = (raw: string | null | undefined) => {
|
||||
const code = String(raw || '').trim();
|
||||
if (!code) return;
|
||||
const key = code.toLowerCase();
|
||||
if (seen.has(key)) return;
|
||||
const intent = mapActionCodeToIntent(code);
|
||||
if (!intent || intent === 'none') return;
|
||||
seen.add(key);
|
||||
items.push(toItem(code, intent));
|
||||
};
|
||||
|
||||
pushCode(projection.currentGate?.nextActionCode);
|
||||
for (const action of projection.availableActions || []) {
|
||||
pushCode(action);
|
||||
}
|
||||
|
||||
if (items.length === 0 && (status === 'completed' || status === 'failed' || status === 'cancelled')) {
|
||||
pushCode('view_result');
|
||||
}
|
||||
|
||||
if (AUTOMATING_STATUSES.has(status) && items.length === 0) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
return {
|
||||
primary: items[0] || null,
|
||||
secondary: items[1] || null,
|
||||
overflow: items.slice(2),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user