修复:清理导入历史失败提示并识别旧文件年份
This commit is contained in:
@@ -25,19 +25,24 @@ export function useDataWorkflowOperation(slot: string, onComplete?: (value: Data
|
||||
const terminalHandledRef = useRef(new Set<string>());
|
||||
const generationRef = useRef(0);
|
||||
const mountedRef = useRef(false);
|
||||
const restoredIdRef = useRef('');
|
||||
useEffect(() => { callbackRef.current = onComplete; }, [onComplete]);
|
||||
useEffect(() => {
|
||||
mountedRef.current = true;
|
||||
let pending: StoredOperation | null = null;
|
||||
try { pending = JSON.parse(localStorage.getItem(storageKey(slot)) || 'null') as StoredOperation | null; } catch { pending = null; }
|
||||
if (pending?.operationId) setOperationId(pending.operationId);
|
||||
if (pending?.operationId) { restoredIdRef.current = pending.operationId; setOperationId(pending.operationId); }
|
||||
return () => { mountedRef.current = false; generationRef.current++; };
|
||||
}, [slot]);
|
||||
|
||||
const savePendingId = useCallback((value: StoredOperation | null) => {
|
||||
const savePendingId = useCallback((value: StoredOperation | null, expectedId?: string) => {
|
||||
try {
|
||||
if (value) localStorage.setItem(storageKey(slot), JSON.stringify(value));
|
||||
else localStorage.removeItem(storageKey(slot));
|
||||
else {
|
||||
// 另一个标签页可能已经启动新任务,旧任务结束不能清掉它的恢复入口。
|
||||
const stored = JSON.parse(localStorage.getItem(storageKey(slot)) || 'null') as StoredOperation | null;
|
||||
if (!expectedId || stored?.operationId === expectedId) localStorage.removeItem(storageKey(slot));
|
||||
}
|
||||
} catch { /* storage may be unavailable in a restricted browser context */ }
|
||||
}, [slot]);
|
||||
|
||||
@@ -48,15 +53,16 @@ export function useDataWorkflowOperation(slot: string, onComplete?: (value: Data
|
||||
try {
|
||||
const current = await api.dataWorkflowOperation(id);
|
||||
if (!mountedRef.current || generation !== generationRef.current) return;
|
||||
setOperation(current);
|
||||
setOperation(restoredIdRef.current === id ? { ...current, restoredFromPreviousVisit: true } : current);
|
||||
setError('');
|
||||
const status = String(current.status || '').toUpperCase();
|
||||
if (status === 'COMPLETED' || status === 'FAILED') {
|
||||
terminalHandledRef.current.add(id);
|
||||
generationRef.current++;
|
||||
setOperationId('');
|
||||
// 只有未完成任务需要跨刷新恢复;失败详情仍留在本页和服务端历史记录。
|
||||
savePendingId(null, id);
|
||||
if (status === 'COMPLETED') {
|
||||
savePendingId(null);
|
||||
window.dispatchEvent(new CustomEvent(WORKSPACE_INVALIDATED, { detail: { resources: ['sources', 'workflow', 'tasks', 'releases', 'metrics', 'trend', 'records', 'options', 'catalog', 'configuration'] } }));
|
||||
callbackRef.current?.(current);
|
||||
} else setError(operationError(current));
|
||||
@@ -76,6 +82,12 @@ export function useDataWorkflowOperation(slot: string, onComplete?: (value: Data
|
||||
if (startPromiseRef.current) return startPromiseRef.current;
|
||||
if (isPending(operation)) return operation;
|
||||
const attempt = (async () => {
|
||||
const previousId = operation?.operationId || restoredIdRef.current;
|
||||
if (previousId) savePendingId(null, previousId);
|
||||
generationRef.current++;
|
||||
restoredIdRef.current = '';
|
||||
setOperation(null);
|
||||
setOperationId('');
|
||||
setStarting(true);
|
||||
setError('');
|
||||
try {
|
||||
@@ -109,7 +121,8 @@ export function useDataWorkflowOperation(slot: string, onComplete?: (value: Data
|
||||
|
||||
const clear = useCallback(() => {
|
||||
generationRef.current++;
|
||||
setOperation(null); setOperationId(''); setError(''); savePendingId(null);
|
||||
}, [savePendingId]);
|
||||
restoredIdRef.current = '';
|
||||
setOperation(null); setOperationId(''); setError(''); savePendingId(null, operation?.operationId);
|
||||
}, [savePendingId, operation?.operationId]);
|
||||
return { operation, error, busy: starting || Boolean(isPending(operation)), start, resume, clear };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user