Files
govoplan-campaign/webui/src/features/campaigns/review/builtMessageState.ts
T
zemion c51fc180fb
Module Package Release / publish-packages (push) Successful in 12s
Release govoplan-campaign v0.1.28: stabilize saving, review and delivery recovery
2026-09-08 01:32:26 +02:00

52 lines
2.6 KiB
TypeScript

export type BuiltMessageState = "ready" | "needs_review" | "blocked" | "excluded";
export type BuiltMessageStatePresentation = {
state: BuiltMessageState;
explanationLabel: string;
};
function record(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
}
/** One display/filter model; it never authorizes an exception or a delivery. */
export function builtMessageState(
row: Record<string, unknown>,
index: number,
reviewedKeys: ReadonlySet<string>,
inspectionComplete = false
): BuiltMessageStatePresentation {
const validation = String(row.validation_status ?? "").toLowerCase();
if (validation === "excluded" || validation === "inactive") {
return { state: "excluded", explanationLabel: validation === "inactive"
? "i18n:govoplan-campaign.message_state_inactive" : "i18n:govoplan-campaign.message_state_excluded" };
}
const build = String(row.build_status ?? "built").toLowerCase();
if (build !== "built") {
return { state: "blocked", explanationLabel: ["failed", "error"].includes(build)
? "i18n:govoplan-campaign.message_state_build_failed" : "i18n:govoplan-campaign.message_state_not_built" };
}
const issues = Array.isArray(row.issues) ? row.issues.map(record) : [];
if (validation === "blocked" || issues.some((issue) => ["block", "blocked"].includes(String(issue.behavior ?? "").toLowerCase())
|| ["error", "critical", "fatal"].includes(String(issue.severity ?? "").toLowerCase()))) {
return { state: "blocked", explanationLabel: "i18n:govoplan-campaign.message_state_blocked" };
}
if (validation === "warning") {
// An earlier view/open marker does not replace the final warning gate.
return inspectionComplete
? { state: "ready", explanationLabel: "i18n:govoplan-campaign.message_state_warning_accepted" }
: { state: "needs_review", explanationLabel: "i18n:govoplan-campaign.message_state_warning_pending" };
}
if (validation === "needs_review") {
const key = String(row.review_key ?? row.entry_id ?? row.entry_index ?? index);
const accepted = row.reviewed === true || reviewedKeys.has(key);
return accepted
? { state: "ready", explanationLabel: "i18n:govoplan-campaign.message_state_individually_accepted" }
: { state: "needs_review", explanationLabel: "i18n:govoplan-campaign.message_state_individual_pending" };
}
if (validation === "ready") {
return { state: "ready", explanationLabel: "i18n:govoplan-campaign.message_state_automatic" };
}
return { state: "blocked", explanationLabel: "i18n:govoplan-campaign.message_state_unknown" };
}