diff --git a/src/api/__tests__/classes/classes.test.ts b/src/api/__tests__/classes/classes.test.ts index dbe84b9..41999e6 100644 --- a/src/api/__tests__/classes/classes.test.ts +++ b/src/api/__tests__/classes/classes.test.ts @@ -144,7 +144,7 @@ describe("classes API", () => { }); it("postClassBlueprint POSTs /classes/blueprints with the body", async () => { - mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, skipped: [] }); + mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, matched: 2, skipped: [] }); const body = { grade: "9", course_ids: ["co1", "co2"] }; await postClassBlueprint(body); const [url, init] = lastFetchCall(); @@ -168,7 +168,7 @@ describe("classes API", () => { }); it("patchClassBlueprintByGrade PATCHes the whole course set", async () => { - mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, skipped: [] }); + mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, matched: 2, skipped: [] }); const body = { course_ids: ["co1"] }; await patchClassBlueprintByGrade("9", body); const [url, init] = lastFetchCall(); diff --git a/src/api/client/types.ts b/src/api/client/types.ts index f51578c..1e928bd 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -448,7 +448,10 @@ export type BlueprintSkip = { reason: string; }; -export type BlueprintResult = { blueprint: ClassBlueprint; skipped: BlueprintSkip[] }; +// `matched` is how many sections the pump reached. 0 means no section carries +// the grade label — the template was saved and stocked nothing, which an empty +// `skipped` alone cannot tell apart from "every section took the whole list". +export type BlueprintResult = { blueprint: ClassBlueprint; matched: number; skipped: BlueprintSkip[] }; export type BlueprintApplyResult = { skipped: BlueprintSkip[] }; diff --git a/src/components/classes/blueprints-tab.tsx b/src/components/classes/blueprints-tab.tsx index b88325a..9b20a0e 100644 --- a/src/components/classes/blueprints-tab.tsx +++ b/src/components/classes/blueprints-tab.tsx @@ -4,7 +4,7 @@ import type { ColumnDef } from "@tanstack/solid-table"; import { deleteClassBlueprintByGrade, getClassBlueprints, getClassBlueprintStatus } from "@/api/classes"; import { getCourses } from "@/api/courses"; import { getLimits } from "@/api/limits"; -import { formatApiError, type BlueprintSectionStatus, type BlueprintSkip, type BlueprintStatus, type ClassBlueprint } from "@/api/client"; +import { formatApiError, type BlueprintResult, type BlueprintSectionStatus, type BlueprintSkip, type BlueprintStatus, type ClassBlueprint } from "@/api/client"; import { BlueprintPanel } from "@/components/classes/blueprint-panel"; import { BlueprintSkippedReport } from "@/components/classes/blueprint-skipped-report"; import { Alert } from "@/components/ui/alert"; @@ -31,6 +31,7 @@ export function BlueprintsTab(props: { const [editing, setEditing] = createSignal(null); const [deleting, setDeleting] = createSignal(null); const [skipped, setSkipped] = createSignal([]); + const [unmatchedGrade, setUnmatchedGrade] = createSignal(null); const [reportOpen, setReportOpen] = createSignal(false); const [status, setStatus] = createSignal(null); @@ -107,12 +108,19 @@ export function BlueprintsTab(props: { // A saved blueprint is not an error even when some pairs did not attach: the // template was written either way, so the toast fires and the shortfall is a // separate, dismissible report. - const handleSaved = async (rows: BlueprintSkip[]) => { + const handleSaved = async (result: BlueprintResult) => { setPanelOpen(false); setEditing(null); await refetch(); - setSkipped(rows); - setFlash(t("classBlueprints.saved")); + setSkipped(result.skipped); + // A grade label nobody carries is saved just the same, so it must not + // read as "applied" — that is the one outcome the admin needs to fix. + if (result.matched === 0) { + setUnmatchedGrade(result.blueprint.grade); + return; + } + setUnmatchedGrade(null); + setFlash(t("classBlueprints.savedMatched", { count: result.matched })); }; const remove = async () => { @@ -160,6 +168,13 @@ export function BlueprintsTab(props: { {error()} + + {(grade) => ( + + {t("classBlueprints.noMatch", { grade: grade() })} + + )} + 0}> {t("classBlueprints.skippedSummary", { count: skipped().length })} @@ -207,7 +222,7 @@ export function BlueprintsTab(props: { courses={courses.latest ?? []} maxCourses={limits.latest?.course.max_class_courses ?? 50} maxGradeLen={limits.latest?.course.max_class_grade_len ?? 20} - onSaved={(result) => void handleSaved(result.skipped)} + onSaved={(result) => void handleSaved(result)} />