33 lines
862 B
TypeScript
33 lines
862 B
TypeScript
export type LayoutReplaceBatchStateItem = {
|
|
status: string;
|
|
taskId: string;
|
|
};
|
|
|
|
export function deriveLayoutReplaceBatchAdvance(
|
|
items: LayoutReplaceBatchStateItem[]
|
|
) {
|
|
const succeededCount = items.filter((item) => item.status === "succeeded").length;
|
|
const failedCount = items.filter((item) => item.status === "failed").length;
|
|
const terminalCount = succeededCount + failedCount;
|
|
const isComplete = items.length > 0 && terminalCount >= items.length;
|
|
const nextTaskId = isComplete
|
|
? null
|
|
: items.find((item) => item.status === "queued")?.taskId || null;
|
|
const status = isComplete
|
|
? failedCount === 0
|
|
? "succeeded"
|
|
: succeededCount === 0
|
|
? "failed"
|
|
: "partial_failed"
|
|
: "running";
|
|
|
|
return {
|
|
failedCount,
|
|
isComplete,
|
|
nextTaskId,
|
|
status,
|
|
succeededCount,
|
|
terminalCount,
|
|
};
|
|
}
|