forge
Explore
Log in

Don't you dare go Hollow

🐛 warn when a blueprint grade matches no section

Browse files at this commit

0630be82e26a20fc13cd3ca851425a8248e5d339Burak BoduroğluParent: 4d56817
  • fix
    • 🐛 warn when a blueprint grade matches no section
Show full message
fix: 🐛 warn when a blueprint grade matches no section
- read `matched` from the blueprint pump response
- matched 0 shows a warning naming the grade instead of "applied to every
  class"; otherwise the toast says how many sections took it
src/api/__tests__/classes/classes.test.tsmodified+2 -2
@@ -144,7 +144,7 @@ describe("classes API", () => {
144 });144 });
145 145
146 it("postClassBlueprint POSTs /classes/blueprints with the body", async () => {146 it("postClassBlueprint POSTs /classes/blueprints with the body", async () => {
147- mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, skipped: [] });147+ mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, matched: 2, skipped: [] });
148 const body = { grade: "9", course_ids: ["co1", "co2"] };148 const body = { grade: "9", course_ids: ["co1", "co2"] };
149 await postClassBlueprint(body);149 await postClassBlueprint(body);
150 const [url, init] = lastFetchCall();150 const [url, init] = lastFetchCall();
@@ -168,7 +168,7 @@ describe("classes API", () => {
168 });168 });
169 169
170 it("patchClassBlueprintByGrade PATCHes the whole course set", async () => {170 it("patchClassBlueprintByGrade PATCHes the whole course set", async () => {
171- mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, skipped: [] });171+ mockFetchSuccess({ blueprint: { grade: "9", courses: [], creator: {} }, matched: 2, skipped: [] });
172 const body = { course_ids: ["co1"] };172 const body = { course_ids: ["co1"] };
173 await patchClassBlueprintByGrade("9", body);173 await patchClassBlueprintByGrade("9", body);
174 const [url, init] = lastFetchCall();174 const [url, init] = lastFetchCall();
src/api/client/types.tsmodified+4 -1
@@ -448,7 +448,10 @@ export type BlueprintSkip = {
448 reason: string;448 reason: string;
449 };449 };
450 450
451-export type BlueprintResult = { blueprint: ClassBlueprint; skipped: BlueprintSkip[] };451+// `matched` is how many sections the pump reached. 0 means no section carries
452+// the grade label — the template was saved and stocked nothing, which an empty
453+// `skipped` alone cannot tell apart from "every section took the whole list".
454+export type BlueprintResult = { blueprint: ClassBlueprint; matched: number; skipped: BlueprintSkip[] };
452 455
453 export type BlueprintApplyResult = { skipped: BlueprintSkip[] };456 export type BlueprintApplyResult = { skipped: BlueprintSkip[] };
454 457
src/components/classes/blueprints-tab.tsxmodified+20 -5
@@ -4,7 +4,7 @@ import type { ColumnDef } from "@tanstack/solid-table";
4 import { deleteClassBlueprintByGrade, getClassBlueprints, getClassBlueprintStatus } from "@/api/classes";4 import { deleteClassBlueprintByGrade, getClassBlueprints, getClassBlueprintStatus } from "@/api/classes";
5 import { getCourses } from "@/api/courses";5 import { getCourses } from "@/api/courses";
6 import { getLimits } from "@/api/limits";6 import { getLimits } from "@/api/limits";
7-import { formatApiError, type BlueprintSectionStatus, type BlueprintSkip, type BlueprintStatus, type ClassBlueprint } from "@/api/client";7+import { formatApiError, type BlueprintResult, type BlueprintSectionStatus, type BlueprintSkip, type BlueprintStatus, type ClassBlueprint } from "@/api/client";
8 import { BlueprintPanel } from "@/components/classes/blueprint-panel";8 import { BlueprintPanel } from "@/components/classes/blueprint-panel";
9 import { BlueprintSkippedReport } from "@/components/classes/blueprint-skipped-report";9 import { BlueprintSkippedReport } from "@/components/classes/blueprint-skipped-report";
10 import { Alert } from "@/components/ui/alert";10 import { Alert } from "@/components/ui/alert";
@@ -31,6 +31,7 @@ export function BlueprintsTab(props: {
31 const [editing, setEditing] = createSignal<ClassBlueprint | null>(null);31 const [editing, setEditing] = createSignal<ClassBlueprint | null>(null);
32 const [deleting, setDeleting] = createSignal<ClassBlueprint | null>(null);32 const [deleting, setDeleting] = createSignal<ClassBlueprint | null>(null);
33 const [skipped, setSkipped] = createSignal<BlueprintSkip[]>([]);33 const [skipped, setSkipped] = createSignal<BlueprintSkip[]>([]);
34+ const [unmatchedGrade, setUnmatchedGrade] = createSignal<string | null>(null);
34 const [reportOpen, setReportOpen] = createSignal(false);35 const [reportOpen, setReportOpen] = createSignal(false);
35 const [status, setStatus] = createSignal<BlueprintStatus | null>(null);36 const [status, setStatus] = createSignal<BlueprintStatus | null>(null);
36 37
@@ -107,12 +108,19 @@ export function BlueprintsTab(props: {
107 // A saved blueprint is not an error even when some pairs did not attach: the108 // A saved blueprint is not an error even when some pairs did not attach: the
108 // template was written either way, so the toast fires and the shortfall is a109 // template was written either way, so the toast fires and the shortfall is a
109 // separate, dismissible report.110 // separate, dismissible report.
110- const handleSaved = async (rows: BlueprintSkip[]) => {111+ const handleSaved = async (result: BlueprintResult) => {
111 setPanelOpen(false);112 setPanelOpen(false);
112 setEditing(null);113 setEditing(null);
113 await refetch();114 await refetch();
114- setSkipped(rows);115+ setSkipped(result.skipped);
115- setFlash(t("classBlueprints.saved"));116+ // A grade label nobody carries is saved just the same, so it must not
117+ // read as "applied" — that is the one outcome the admin needs to fix.
118+ if (result.matched === 0) {
119+ setUnmatchedGrade(result.blueprint.grade);
120+ return;
121+ }
122+ setUnmatchedGrade(null);
123+ setFlash(t("classBlueprints.savedMatched", { count: result.matched }));
116 };124 };
117 125
118 const remove = async () => {126 const remove = async () => {
@@ -160,6 +168,13 @@ export function BlueprintsTab(props: {
160 <Show when={error()}>168 <Show when={error()}>
161 <Alert variant="destructive">{error()}</Alert>169 <Alert variant="destructive">{error()}</Alert>
162 </Show>170 </Show>
171+ <Show when={unmatchedGrade()}>
172+ {(grade) => (
173+ <Alert class="border-amber-500/40 bg-amber-500/10 text-amber-900 dark:text-amber-200">
174+ {t("classBlueprints.noMatch", { grade: grade() })}
175+ </Alert>
176+ )}
177+ </Show>
163 <Show when={skipped().length > 0}>178 <Show when={skipped().length > 0}>
164 <Alert class="flex flex-wrap items-center justify-between gap-3 border-amber-500/40 bg-amber-500/10 text-amber-900 dark:text-amber-200">179 <Alert class="flex flex-wrap items-center justify-between gap-3 border-amber-500/40 bg-amber-500/10 text-amber-900 dark:text-amber-200">
165 <span class="min-w-0 flex-1">{t("classBlueprints.skippedSummary", { count: skipped().length })}</span>180 <span class="min-w-0 flex-1">{t("classBlueprints.skippedSummary", { count: skipped().length })}</span>
@@ -207,7 +222,7 @@ export function BlueprintsTab(props: {
207 courses={courses.latest ?? []}222 courses={courses.latest ?? []}
208 maxCourses={limits.latest?.course.max_class_courses ?? 50}223 maxCourses={limits.latest?.course.max_class_courses ?? 50}
209 maxGradeLen={limits.latest?.course.max_class_grade_len ?? 20}224 maxGradeLen={limits.latest?.course.max_class_grade_len ?? 20}
210- onSaved={(result) => void handleSaved(result.skipped)}225+ onSaved={(result) => void handleSaved(result)}
211 />226 />
212 227
213 <BlueprintSkippedReport228 <BlueprintSkippedReport