🩹 the drawer stops calling an unresolved course school-wide
Browse files at this commit37ac68df92ecf9fa37887cc83d29b1ba799c47c3Parent: deabe8e- fix
- 🩹 the drawer stops calling an unresolved course school-wide
4 changed files +100 -14
- src/components/insights/insight-detail.test.tsx +66 -0
- src/components/insights/insight-detail.tsx +11 -10
- src/components/insights/insight-module-views.tsx +8 -3
- src/i18n/insights-detail.ts +15 -1
src/components/insights/insight-detail.test.tsxmodified+66 -0
| @@ -218,6 +218,34 @@ const insight: StudentInsight = { | |||
| 218 | created_at: NOW, | 218 | created_at: NOW, |
| 219 | expires_at: NOW + WEEK, | 219 | expires_at: NOW + WEEK, |
| 220 | }, | 220 | }, |
| 221 | + { | ||
| 222 | + id: "card-2", | ||
| 223 | + product: "O2", | ||
| 224 | + rule_id: "O2.segment_cognitive_gap", | ||
| 225 | + rule_version: 1, | ||
| 226 | + scope: "bilissel_talep=var", | ||
| 227 | + audience_role: "student", | ||
| 228 | + course: null, | ||
| 229 | + evidence: { | ||
| 230 | + dimension: "dikkat_tuzagi", | ||
| 231 | + label: "var", | ||
| 232 | + fact: "Dikkat tuzağı sorularında doğruluk, öğrencinin genel düzeyinin altında.", | ||
| 233 | + n_answers: 20, | ||
| 234 | + n_correct: 9, | ||
| 235 | + accuracy: 0.45, | ||
| 236 | + overall_accuracy: 0.6, | ||
| 237 | + overall_n_answers: 100, | ||
| 238 | + contrast: -0.15, | ||
| 239 | + reference_mean_contrast: -0.02, | ||
| 240 | + reference_n_students: 180, | ||
| 241 | + relative_contrast: -0.13, | ||
| 242 | + gate_n_answers: 12, | ||
| 243 | + rule: "relative_contrast <= -0.08 ve n_answers >= 12", | ||
| 244 | + }, | ||
| 245 | + confidence: "exploratory", | ||
| 246 | + created_at: NOW, | ||
| 247 | + expires_at: NOW + WEEK, | ||
| 248 | + }, | ||
| 221 | ], | 249 | ], |
| 222 | segments: [ | 250 | segments: [ |
| 223 | { | 251 | { |
| @@ -327,6 +355,44 @@ describe("InsightDetail", () => { | |||
| 327 | expect(disclosure.open).toBe(true); | 355 | expect(disclosure.open).toBe(true); |
| 328 | }); | 356 | }); |
| 329 | 357 | ||
| 358 | + it("claims school-wide only when the payload has no course at all", () => { | ||
| 359 | + const base = insight.attention[0]; | ||
| 360 | + render(() => ( | ||
| 361 | + <PreferencesProvider> | ||
| 362 | + <InsightDetail | ||
| 363 | + insight={{ | ||
| 364 | + ...insight, | ||
| 365 | + attention: [ | ||
| 366 | + { ...base, course: null, fact: "Okul geneli devamsızlık artışı." }, | ||
| 367 | + { ...base, course: "01a0b1b0-9d58-77f7-966f-5bfa87cb7e11", fact: "Dersi çözülemeyen madde." }, | ||
| 368 | + ], | ||
| 369 | + }} | ||
| 370 | + /> | ||
| 371 | + </PreferencesProvider> | ||
| 372 | + )); | ||
| 373 | + const human = screen.getByTestId("insight-human").textContent ?? ""; | ||
| 374 | + | ||
| 375 | + expect(human).toContain("Okul geneli devamsızlık artışı."); | ||
| 376 | + expect(human).toContain("Ders adı çözümlenemedi"); | ||
| 377 | + // Exactly one item may read as school-wide: a course id whose title did not | ||
| 378 | + // resolve is not evidence of a school-wide fact. | ||
| 379 | + expect((human.match(/Okul geneli/g) ?? []).length).toBe(1); | ||
| 380 | + expect(human).not.toContain("01a0b1b0-9d58-77f7-966f-5bfa87cb7e11"); | ||
| 381 | + }); | ||
| 382 | + | ||
| 383 | + it("maps the segment vocabulary everywhere, never the machine name", () => { | ||
| 384 | + renderDrawer(); | ||
| 385 | + const human = screen.getByTestId("insight-human").textContent ?? ""; | ||
| 386 | + | ||
| 387 | + // Segments section and the O2 card's evidence must agree on the label. | ||
| 388 | + expect(human).toContain("Dikkat tuzağı"); | ||
| 389 | + expect(human).toContain("Bilişsel talep: var"); | ||
| 390 | + expect(human).not.toContain("dikkat_tuzagi"); | ||
| 391 | + expect(human).not.toContain("bilissel_talep"); | ||
| 392 | + | ||
| 393 | + expect(screen.getByTestId("insight-technical").textContent).toContain("dikkat_tuzagi"); | ||
| 394 | + }); | ||
| 395 | + | ||
| 330 | it("keeps the cards-only mode free of the drawer's full-view sections", () => { | 396 | it("keeps the cards-only mode free of the drawer's full-view sections", () => { |
| 331 | renderDrawer({ mode: "cards" }); | 397 | renderDrawer({ mode: "cards" }); |
| 332 | const human = screen.getByTestId("insight-human").textContent ?? ""; | 398 | const human = screen.getByTestId("insight-human").textContent ?? ""; |
src/components/insights/insight-detail.tsxmodified+11 -10
| @@ -8,7 +8,7 @@ import { | |||
| 8 | import { Badge } from "@/components/ui/badge"; | 8 | import { Badge } from "@/components/ui/badge"; |
| 9 | import { EmptyInline } from "@/components/ui/empty-inline"; | 9 | import { EmptyInline } from "@/components/ui/empty-inline"; |
| 10 | import { IconAlert, IconChart, IconSparkles } from "@/components/ui/icons"; | 10 | import { IconAlert, IconChart, IconSparkles } from "@/components/ui/icons"; |
| 11 | -import { detailText, type InsightDetailKey } from "@/i18n/insights-detail"; | 11 | +import { detailText, dimensionLabel, type InsightDetailKey } from "@/i18n/insights-detail"; |
| 12 | import { cn } from "@/lib/cn"; | 12 | import { cn } from "@/lib/cn"; |
| 13 | import { formatDateTime } from "@/lib/format"; | 13 | import { formatDateTime } from "@/lib/format"; |
| 14 | import { isRecord } from "@/lib/is-record"; | 14 | import { isRecord } from "@/lib/is-record"; |
| @@ -30,11 +30,6 @@ const TRIGGER_KEYS: Record<string, InsightDetailKey> = { | |||
| 30 | homework: "trigger.homework", | 30 | homework: "trigger.homework", |
| 31 | mark_trend: "trigger.mark_trend", | 31 | mark_trend: "trigger.mark_trend", |
| 32 | }; | 32 | }; |
| 33 | -const DIMENSION_KEYS: Record<string, InsightDetailKey> = { | ||
| 34 | - bilissel_talep: "segments.dimension.bilissel_talep", | ||
| 35 | - dikkat_tuzagi: "segments.dimension.dikkat_tuzagi", | ||
| 36 | - okuma_yuku: "segments.dimension.okuma_yuku", | ||
| 37 | -}; | ||
| 38 | const PRODUCT_KEYS: Record<string, InsightDetailKey> = { | 33 | const PRODUCT_KEYS: Record<string, InsightDetailKey> = { |
| 39 | O1: "product.O1", | 34 | O1: "product.O1", |
| 40 | O2: "product.O2", | 35 | O2: "product.O2", |
| @@ -66,10 +61,16 @@ export function InsightDetail(props: { insight: StudentInsight; mode?: "full" | | |||
| 66 | const title = isRecord(entry) ? entry.course_title : undefined; | 61 | const title = isRecord(entry) ? entry.course_title : undefined; |
| 67 | return typeof title === "string" && title.length > 0 ? title : null; | 62 | return typeof title === "string" && title.length > 0 ? title : null; |
| 68 | }; | 63 | }; |
| 69 | - const courseLine = (id?: string | null) => courseTitle(id) ?? (id ? tx("insights.schoolWide") : null); | 64 | + /** |
| 70 | - const dimensionLabel = (dimension: string | null | undefined) => { | 65 | + * The attention list's own contract: a null `course` means the fact is |
| 71 | - const key = dimension ? DIMENSION_KEYS[dimension] : undefined; | 66 | + * school-wide, so that is the only case that may say so. A course id whose |
| 72 | - return key ? detailText(key) : null; | 67 | + * title never made it into the payload is NOT school-wide — saying it were |
| 68 | + * invents a fact on a student's report, so it is labelled as unresolved | ||
| 69 | + * (the id itself stays in the technical disclosure). | ||
| 70 | + */ | ||
| 71 | + const courseLine = (id?: string | null) => { | ||
| 72 | + if (!id) return tx("insights.schoolWide"); | ||
| 73 | + return courseTitle(id) ?? detailText("detail.unresolvedCourse"); | ||
| 73 | }; | 74 | }; |
| 74 | /** A card scope is `<dimension>=<label>`; the label half is already Turkish. */ | 75 | /** A card scope is `<dimension>=<label>`; the label half is already Turkish. */ |
| 75 | const scopeText = (scope?: string | null) => { | 76 | const scopeText = (scope?: string | null) => { |
src/components/insights/insight-module-views.tsxmodified+8 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | import { For, Show, type JSX } from "solid-js"; | 1 | import { For, Show, type JSX } from "solid-js"; |
| 2 | import { Badge } from "@/components/ui/badge"; | 2 | import { Badge } from "@/components/ui/badge"; |
| 3 | -import { detailText, type InsightDetailKey } from "@/i18n/insights-detail"; | 3 | +import { detailText, dimensionLabel, type InsightDetailKey } from "@/i18n/insights-detail"; |
| 4 | import type { Locale } from "@/i18n/messages"; | 4 | import type { Locale } from "@/i18n/messages"; |
| 5 | import { cn } from "@/lib/cn"; | 5 | import { cn } from "@/lib/cn"; |
| 6 | import { formatDateTime } from "@/lib/format"; | 6 | import { formatDateTime } from "@/lib/format"; |
| @@ -622,7 +622,7 @@ export function InsightModuleView(props: { module: string; value: unknown; cours | |||
| 622 | // evidence (attention items, recommendation cards) | 622 | // evidence (attention items, recommendation cards) |
| 623 | // --------------------------------------------------------------------------- | 623 | // --------------------------------------------------------------------------- |
| 624 | 624 | ||
| 625 | -type EvidenceKind = "rate" | "ratePoints" | "points" | "number" | "z" | "ms" | "minutes" | "hours" | "date" | "text" | "band" | "skip"; | 625 | +type EvidenceKind = "rate" | "ratePoints" | "points" | "number" | "z" | "ms" | "minutes" | "hours" | "date" | "text" | "dimension" | "band" | "skip"; |
| 626 | 626 | ||
| 627 | /** Evidence is ZEKA's loose "neden?" object, one shape per rule. A field with | 627 | /** Evidence is ZEKA's loose "neden?" object, one shape per rule. A field with |
| 628 | * no entry here has no honest label yet, so it stays in the technical | 628 | * no entry here has no honest label yet, so it stays in the technical |
| @@ -672,7 +672,7 @@ const EVIDENCE_FIELDS: Record<string, { key: InsightDetailKey; kind: EvidenceKin | |||
| 672 | reference_mean_contrast: { key: "evidence.referenceMeanContrast", kind: "rate" }, | 672 | reference_mean_contrast: { key: "evidence.referenceMeanContrast", kind: "rate" }, |
| 673 | reference_n_students: { key: "evidence.referenceNStudents", kind: "number" }, | 673 | reference_n_students: { key: "evidence.referenceNStudents", kind: "number" }, |
| 674 | relative_contrast: { key: "evidence.relativeContrast", kind: "rate" }, | 674 | relative_contrast: { key: "evidence.relativeContrast", kind: "rate" }, |
| 675 | - dimension: { key: "evidence.dimension", kind: "text" }, | 675 | + dimension: { key: "evidence.dimension", kind: "dimension" }, |
| 676 | label: { key: "evidence.label", kind: "text" }, | 676 | label: { key: "evidence.label", kind: "text" }, |
| 677 | fact: { key: "evidence.fact", kind: "text" }, | 677 | fact: { key: "evidence.fact", kind: "text" }, |
| 678 | window_from: { key: "evidence.windowFrom", kind: "date" }, | 678 | window_from: { key: "evidence.windowFrom", kind: "date" }, |
| @@ -701,6 +701,11 @@ function evidenceValue(kind: EvidenceKind, value: unknown, locale: Locale): { te | |||
| 701 | return { text: num(value) === null ? null : formatDateTime(num(value)!, locale), sentence: false }; | 701 | return { text: num(value) === null ? null : formatDateTime(num(value)!, locale), sentence: false }; |
| 702 | case "band": | 702 | case "band": |
| 703 | return { text: bandLabel(value), sentence: false }; | 703 | return { text: bandLabel(value), sentence: false }; |
| 704 | + case "dimension": | ||
| 705 | + // Same vocabulary as the segments section: an unmapped dimension reads as | ||
| 706 | + // `null` here, which sends it to the technical-disclosure count instead of | ||
| 707 | + // printing the snake_case machine value next to a mapped one. | ||
| 708 | + return { text: dimensionLabel(str(value)), sentence: false }; | ||
| 704 | case "text": { | 709 | case "text": { |
| 705 | const text = str(value); | 710 | const text = str(value); |
| 706 | return { text, sentence: text !== null && /\s/.test(text) }; | 711 | return { text, sentence: text !== null && /\s/.test(text) }; |
src/i18n/insights-detail.tsmodified+15 -1
| @@ -19,6 +19,7 @@ export const insightsDetailTr = { | |||
| 19 | "detail.technicalHint": "Etiketlenmemiş ham veri; kayıt anahtarları burada görünür.", | 19 | "detail.technicalHint": "Etiketlenmemiş ham veri; kayıt anahtarları burada görünür.", |
| 20 | "detail.hiddenFields": "{count} alan bu bölümde etiketsiz; teknik ayrıntıda.", | 20 | "detail.hiddenFields": "{count} alan bu bölümde etiketsiz; teknik ayrıntıda.", |
| 21 | "detail.elsewhere": "Bu bölümün ham verisi Teknik ayrıntı bölümünde.", | 21 | "detail.elsewhere": "Bu bölümün ham verisi Teknik ayrıntı bölümünde.", |
| 22 | + "detail.unresolvedCourse": "Ders adı çözümlenemedi", | ||
| 22 | "detail.notComputed": "Bu sürümde üretilemiyor", | 23 | "detail.notComputed": "Bu sürümde üretilemiyor", |
| 23 | "detail.reason": "Neden", | 24 | "detail.reason": "Neden", |
| 24 | "detail.value.missing": "—", | 25 | "detail.value.missing": "—", |
| @@ -178,7 +179,6 @@ export const insightsDetailTr = { | |||
| 178 | "segments.dimension.bilissel_talep": "Bilişsel talep", | 179 | "segments.dimension.bilissel_talep": "Bilişsel talep", |
| 179 | "segments.dimension.dikkat_tuzagi": "Dikkat tuzağı", | 180 | "segments.dimension.dikkat_tuzagi": "Dikkat tuzağı", |
| 180 | "segments.dimension.okuma_yuku": "Okuma yükü", | 181 | "segments.dimension.okuma_yuku": "Okuma yükü", |
| 181 | - "segments.dimension.unknown": "Boyut", | ||
| 182 | "product.O1": "Ders konumu", | 182 | "product.O1": "Ders konumu", |
| 183 | "product.O2": "Beceri boşluğu", | 183 | "product.O2": "Beceri boşluğu", |
| 184 | "product.O3": "Çalışma düzeni", | 184 | "product.O3": "Çalışma düzeni", |
| @@ -193,6 +193,20 @@ export const insightsDetailTr = { | |||
| 193 | 193 | ||
| 194 | export type InsightDetailKey = keyof typeof insightsDetailTr; | 194 | export type InsightDetailKey = keyof typeof insightsDetailTr; |
| 195 | 195 | ||
| 196 | +/** The segment vocabulary, shared by the segments section and the evidence | ||
| 197 | + * rows: an unmapped dimension yields `null` so callers omit it (or count it | ||
| 198 | + * into the technical-disclosure note) instead of printing the machine name. */ | ||
| 199 | +const DIMENSION_KEYS: Record<string, InsightDetailKey> = { | ||
| 200 | + bilissel_talep: "segments.dimension.bilissel_talep", | ||
| 201 | + dikkat_tuzagi: "segments.dimension.dikkat_tuzagi", | ||
| 202 | + okuma_yuku: "segments.dimension.okuma_yuku", | ||
| 203 | +}; | ||
| 204 | + | ||
| 205 | +export function dimensionLabel(dimension: string | null | undefined): string | null { | ||
| 206 | + const key = dimension ? DIMENSION_KEYS[dimension] : undefined; | ||
| 207 | + return key ? insightsDetailTr[key] : null; | ||
| 208 | +} | ||
| 209 | + | ||
| 196 | /** One label from the drawer's own dictionary, with `{name}` interpolation. */ | 210 | /** One label from the drawer's own dictionary, with `{name}` interpolation. */ |
| 197 | export function detailText(key: InsightDetailKey, vars?: Record<string, string | number>): string { | 211 | export function detailText(key: InsightDetailKey, vars?: Record<string, string | number>): string { |
| 198 | return formatMessage(insightsDetailTr[key], vars); | 212 | return formatMessage(insightsDetailTr[key], vars); |