28 lines
1.5 KiB
TypeScript
28 lines
1.5 KiB
TypeScript
// Change order words shared by the packet page and the boards.
|
|||
|
|
import type { ChangeOrder, PacketRead } from "../api/types";
|
||
|
|
|
||
|
|
export const feedOrigin = (co: ChangeOrder) => co.origin === "visual" || co.origin === "drawing";
|
||
|
|
|
||
|
|
/** The old coSummary(): "M00543 Rev 1 -> Rev 2 + 2 other changes", or the first changes. */
|
||
|
|
export function coSummary(co: ChangeOrder): string {
|
||
|
|
if (feedOrigin(co) && co.review !== "approved") {
|
||
|
|
const v = co.vis ?? {};
|
||
|
|
const ch = v.changes ?? [];
|
||
|
|
if (v.dwg_change) {
|
||
|
|
const from = v.from_dwg && v.to_dwg && v.from_dwg.replace(/\s/g, "").toUpperCase() !== v.to_dwg.replace(/\s/g, "").toUpperCase() ? `${v.from_dwg} -> ` : "";
|
||
|
|
return `${from}${v.to_dwg ?? ""} Rev ${v.from_rev || "?"} -> Rev ${v.to_rev ?? "?"}${ch.length ? ` + ${ch.length} other change${ch.length > 1 ? "s" : ""}` : ""}`;
|
||
|
|
}
|
||
|
|
return ch.slice(0, 2).join("; ") + (ch.length > 2 ? ` (+${ch.length - 2} more)` : "") || co.reason || "change from VISUAL";
|
||
|
|
}
|
||
|
|
const parts = co.items.filter((i) => !i.added).map((i) => `${i.old_dwg || "sheet"} Rev ${i.old_rev || "?"} -> Rev ${i.new_rev || "?"}`);
|
||
|
|
const added = co.items.filter((i) => i.added).length;
|
||
|
|
if (added) parts.push(`${added} sheet${added > 1 ? "s" : ""} added`);
|
||
|
|
return parts.join(", ") || co.reason || "documents changed";
|
||
|
|
}
|
||
|
|
|
||
|
|
/** The pending feed change order Clerical should review, if any. */
|
||
|
|
export function coToReview(p: PacketRead): ChangeOrder | undefined {
|
||
|
|
return (p.change_orders ?? []).find((c) => c.review === "pending" && feedOrigin(c));
|
||
|
|
}
|
||
|
|
|