✨ refine insight tabs and student analysis
Browse files at this commite80f64fe0cc493821b48e5e538d554c30c880e7aParent: e0ee350- feat
- ✨ refine insight tabs and student analysis
17 changed files +1078 -230
- src/components/ai/insights-board.tsx +96 -178
- src/components/insights/insight-overview.tsx +51 -0
- src/components/insights/insight-runs-table.tsx +24 -16
- src/components/insights/insight-student-analysis-tabs.tsx +237 -0
- src/components/insights/insight-students-table.tsx +221 -0
- src/components/layout/nav-items.test.ts +4 -3
- src/components/layout/nav-items.ts +2 -1
- src/components/rag/rag-study-panel.tsx +34 -12
- src/components/ui/table-row-actions.tsx +2 -2
- src/components/ui/tabs.tsx +1 -1
- src/i18n/messages.ts +95 -2
- src/index.css +17 -0
- src/lib/insight-students.test.ts +43 -0
- src/lib/insight-students.ts +72 -0
- src/pages/ai-celebi-page.tsx +0 -10
- src/pages/ai-insight-student-page.tsx +173 -0
- src/routes/router.tsx +6 -5
src/components/ai/insights-board.tsxmodified+96 -178
| @@ -1,37 +1,28 @@ | |||
| 1 | -import { Show, Suspense, createMemo, createSignal } from "solid-js"; | 1 | +import { Show, Suspense, createEffect, createMemo, createSignal, on } from "solid-js"; |
| 2 | import { createResource } from "@/lib/create-resource"; | 2 | import { createResource } from "@/lib/create-resource"; |
| 3 | -import type { ColumnDef } from "@tanstack/solid-table"; | 3 | +import { getInsightRuns, getMyInsight, postInsightsRefresh } from "@/api/insights"; |
| 4 | -import { | 4 | +import { formatApiError, type Role } from "@/api/client"; |
| 5 | - getInsightByUserId, | ||
| 6 | - getInsightRuns, | ||
| 7 | - getMyInsight, | ||
| 8 | - postInsightComputeByUserId, | ||
| 9 | - postInsightsRefresh, | ||
| 10 | -} from "@/api/insights"; | ||
| 11 | -import { getMyStudents } from "@/api/parents"; | ||
| 12 | -import { getUserSearch } from "@/api/users"; | ||
| 13 | -import { formatApiError, type PersonRef, type Role } from "@/api/client"; | ||
| 14 | import { InsightDetail } from "@/components/insights/insight-detail"; | 5 | import { InsightDetail } from "@/components/insights/insight-detail"; |
| 6 | +import { InsightOverview } from "@/components/insights/insight-overview"; | ||
| 15 | import { InsightRunsTable } from "@/components/insights/insight-runs-table"; | 7 | import { InsightRunsTable } from "@/components/insights/insight-runs-table"; |
| 16 | -import { RosterPersonCell } from "@/components/users/roster-person-cell"; | 8 | +import { InsightStudentsTable } from "@/components/insights/insight-students-table"; |
| 17 | import { Alert } from "@/components/ui/alert"; | 9 | import { Alert } from "@/components/ui/alert"; |
| 18 | import { Button } from "@/components/ui/button"; | 10 | import { Button } from "@/components/ui/button"; |
| 19 | -import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; | 11 | +import { DataTableSkeleton } from "@/components/ui/data-table"; |
| 20 | import { ErrorAlert } from "@/components/ui/error-alert"; | 12 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 21 | -import { IconEye, IconRefresh, IconSparkles } from "@/components/ui/icons"; | 13 | +import { IconRefresh, IconSparkles } from "@/components/ui/icons"; |
| 22 | -import { SidePanel } from "@/components/ui/side-panel"; | 14 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 23 | -import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 24 | import { createFlash } from "@/lib/flash"; | 15 | import { createFlash } from "@/lib/flash"; |
| 25 | -import { matchesSearch } from "@/lib/search-text"; | 16 | +import { toStudentSignal, type StudentSignal } from "@/lib/insight-run-report"; |
| 17 | +import { insightOverview, loadInsightStudents, loadStudentSignals } from "@/lib/insight-students"; | ||
| 26 | import { personLabel } from "@/lib/person"; | 18 | import { personLabel } from "@/lib/person"; |
| 27 | import { hasMinRole } from "@/lib/roles"; | 19 | import { hasMinRole } from "@/lib/roles"; |
| 28 | import { useAuth } from "@/stores/auth-context"; | 20 | import { useAuth } from "@/stores/auth-context"; |
| 29 | import { usePreferences } from "@/stores/preferences-context"; | 21 | import { usePreferences } from "@/stores/preferences-context"; |
| 30 | 22 | ||
| 31 | -const PAGE_SIZE = 10; | 23 | +/** Every insight surface in one board: the viewer's own analysis, the picture |
| 32 | - | 24 | + * over the students they may browse (with each one's analysis in the table), |
| 33 | -/** Every insight surface in one board: the viewer's own analysis, the student | 25 | + * and the school-wide run log for managers. A student opens as a full page. */ |
| 34 | - * list they may browse, and the school-wide run log for managers. */ | ||
| 35 | export function InsightsBoard() { | 26 | export function InsightsBoard() { |
| 36 | const auth = useAuth(); | 27 | const auth = useAuth(); |
| 37 | const prefs = usePreferences(); | 28 | const prefs = usePreferences(); |
| @@ -39,12 +30,10 @@ export function InsightsBoard() { | |||
| 39 | const role = () => auth.user()?.role; | 30 | const role = () => auth.user()?.role; |
| 40 | const canBrowseStudents = () => role() === "parent" || hasMinRole(role(), "teacher"); | 31 | const canBrowseStudents = () => role() === "parent" || hasMinRole(role(), "teacher"); |
| 41 | const canManageRuns = () => hasMinRole(role(), "manager"); | 32 | const canManageRuns = () => hasMinRole(role(), "manager"); |
| 42 | - const [selectedStudent, setSelectedStudent] = createSignal<PersonRef | null>(null); | ||
| 43 | const [pageError, setPageError] = createSignal(""); | 33 | const [pageError, setPageError] = createSignal(""); |
| 44 | - const [panelError, setPanelError] = createSignal(""); | ||
| 45 | const [refreshingAll, setRefreshingAll] = createSignal(false); | 34 | const [refreshingAll, setRefreshingAll] = createSignal(false); |
| 46 | - const [computingStudent, setComputingStudent] = createSignal(false); | 35 | + const [insightTab, setInsightTab] = createSignal<"zeka" | "runs">("zeka"); |
| 47 | - const [, flash] = createFlash(); | 36 | + const [flashMessage, flash] = createFlash(); |
| 48 | 37 | ||
| 49 | const [selfInsight, { refetch: refetchSelfInsight }] = createResource( | 38 | const [selfInsight, { refetch: refetchSelfInsight }] = createResource( |
| 50 | () => auth.user()?.id ?? null, | 39 | () => auth.user()?.id ?? null, |
| @@ -52,28 +41,26 @@ export function InsightsBoard() { | |||
| 52 | ); | 41 | ); |
| 53 | const [students, { refetch: refetchStudents }] = createResource( | 42 | const [students, { refetch: refetchStudents }] = createResource( |
| 54 | () => (canBrowseStudents() ? role() : null), | 43 | () => (canBrowseStudents() ? role() : null), |
| 55 | - async (viewerRole: Role) => | 44 | + async (viewerRole: Role) => loadInsightStudents(viewerRole), |
| 56 | - viewerRole === "parent" | ||
| 57 | - ? (await getMyStudents({ limit: 200 })).items | ||
| 58 | - : (await getUserSearch("", undefined, "student", { limit: 200 })).items, | ||
| 59 | ); | 45 | ); |
| 60 | const [runs, { refetch: refetchRuns }] = createResource( | 46 | const [runs, { refetch: refetchRuns }] = createResource( |
| 61 | () => (canManageRuns() ? true : null), | 47 | () => (canManageRuns() ? true : null), |
| 62 | async () => getInsightRuns({ limit: 100 }), | 48 | async () => getInsightRuns({ limit: 100 }), |
| 63 | ); | 49 | ); |
| 64 | - const [insight, { mutate: mutateInsight, refetch: refetchInsight }] = createResource( | 50 | + // Each student's analysis lands in its row as it is read; rows start as |
| 65 | - () => selectedStudent()?.id ?? null, | 51 | + // "not loaded" so the table and the overview never show a guessed value. |
| 66 | - async (userId) => { | 52 | + const [signals, setSignals] = createSignal<Record<string, StudentSignal>>({}); |
| 67 | - if (!userId) return null; | 53 | + let readGeneration = 0; |
| 68 | - setPanelError(""); | 54 | + createEffect(on(() => students.latest, (list) => { |
| 69 | - try { | 55 | + if (!list) return; |
| 70 | - return await getInsightByUserId(userId); | 56 | + const generation = ++readGeneration; |
| 71 | - } catch (error) { | 57 | + setSignals(Object.fromEntries(list.map((person) => [person.id, toStudentSignal({ id: person.id, name: personLabel(person) }, null, null)]))); |
| 72 | - setPanelError(formatApiError(error)); | 58 | + void loadStudentSignals(list, (row) => { |
| 73 | - return null; | 59 | + if (generation === readGeneration) setSignals((current) => ({ ...current, [row.id]: row })); |
| 74 | - } | 60 | + }); |
| 75 | - }, | 61 | + })); |
| 76 | - ); | 62 | + const rows = createMemo(() => Object.values(signals())); |
| 63 | + const overview = createMemo(() => insightOverview(rows(), students.latest?.length ?? 0)); | ||
| 77 | 64 | ||
| 78 | const refreshPage = async () => { | 65 | const refreshPage = async () => { |
| 79 | setPageError(""); | 66 | setPageError(""); |
| @@ -102,54 +89,58 @@ export function InsightsBoard() { | |||
| 102 | } | 89 | } |
| 103 | }; | 90 | }; |
| 104 | 91 | ||
| 105 | - const queueStudentCompute = async () => { | 92 | + const studentAnalysis = () => ( |
| 106 | - const student = selectedStudent(); | 93 | + <Show when={canBrowseStudents()}> |
| 107 | - if (!student || computingStudent()) return; | 94 | + <Suspense fallback={<DataTableSkeleton columns={10} rows={8} />}> |
| 108 | - setComputingStudent(true); | 95 | + <Show when={students.error}> |
| 109 | - setPanelError(""); | 96 | + <ErrorAlert message={formatApiError(students.error)} onRetry={() => void refetchStudents()} /> |
| 110 | - try { | 97 | + </Show> |
| 111 | - await postInsightComputeByUserId(student.id); | 98 | + <Show when={!students.error && students()}> |
| 112 | - flash(tx("insights.recomputeQueued", { student: personLabel(student) })); | 99 | + <InsightOverview overview={overview()} /> |
| 113 | - } catch (error) { | 100 | + <section class="data-shell space-y-4 p-4"> |
| 114 | - setPanelError(formatApiError(error)); | 101 | + <InsightStudentsTable |
| 115 | - } finally { | 102 | + rows={rows()} |
| 116 | - setComputingStudent(false); | 103 | + title={tx("insights.title")} |
| 117 | - } | 104 | + description={role() === "parent" ? tx("insights.parentSubtitle") : tx("insights.subtitle")} |
| 118 | - }; | 105 | + empty={role() === "parent" ? tx("insights.emptyLinkedStudents") : tx("insights.emptyStudents")} |
| 119 | - | 106 | + actions={ |
| 120 | - const openStudent = (student: PersonRef) => { | 107 | + <> |
| 121 | - setPanelError(""); | 108 | + <Button variant="outline" size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => void refreshPage()}> |
| 122 | - mutateInsight(null); | 109 | + <IconRefresh class="h-4 w-4" /> |
| 123 | - setSelectedStudent(student); | 110 | + {tx("common.refresh")} |
| 124 | - }; | 111 | + </Button> |
| 112 | + <Show when={canManageRuns()}> | ||
| 113 | + <Button | ||
| 114 | + size="sm" | ||
| 115 | + class="min-w-[7.5rem] rounded-lg" | ||
| 116 | + disabled={refreshingAll()} | ||
| 117 | + onClick={() => void queueSchoolRefresh()} | ||
| 118 | + > | ||
| 119 | + <IconSparkles class="h-4 w-4" /> | ||
| 120 | + {refreshingAll() ? tx("insights.refreshingAll") : tx("insights.refreshAll")} | ||
| 121 | + </Button> | ||
| 122 | + </Show> | ||
| 123 | + </> | ||
| 124 | + } | ||
| 125 | + /> | ||
| 126 | + </section> | ||
| 127 | + </Show> | ||
| 128 | + </Suspense> | ||
| 129 | + </Show> | ||
| 130 | + ); | ||
| 125 | 131 | ||
| 126 | - const columns = createMemo<ColumnDef<PersonRef>[]>(() => [ | 132 | + const runAnalysis = () => ( |
| 127 | - { | 133 | + <section class="data-shell p-4"> |
| 128 | - id: "student", | 134 | + <Suspense fallback={<DataTableSkeleton columns={6} rows={5} />}> |
| 129 | - header: tx("insights.student"), | 135 | + <Show when={runs.error}> |
| 130 | - cell: (cell) => <RosterPersonCell person={cell.row.original} />, | 136 | + <ErrorAlert message={formatApiError(runs.error)} onRetry={() => void refetchRuns()} /> |
| 131 | - }, | 137 | + </Show> |
| 132 | - { | 138 | + <Show when={!runs.error}> |
| 133 | - id: "actions", | 139 | + <InsightRunsTable runs={runs()?.items ?? []} /> |
| 134 | - header: tx("common.actions"), | 140 | + </Show> |
| 135 | - meta: { | 141 | + </Suspense> |
| 136 | - headerClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap", | 142 | + </section> |
| 137 | - cellClass: "w-[110px] min-w-[110px] max-w-[110px] h-[45px] text-center whitespace-nowrap", | 143 | + ); |
| 138 | - }, | ||
| 139 | - cell: (cell) => ( | ||
| 140 | - <TableRowActions | ||
| 141 | - label={tx("common.actions")} | ||
| 142 | - actions={[ | ||
| 143 | - { | ||
| 144 | - label: tx("insights.viewAnalysis"), | ||
| 145 | - icon: <IconEye class="h-4 w-4" />, | ||
| 146 | - onSelect: () => openStudent(cell.row.original), | ||
| 147 | - }, | ||
| 148 | - ]} | ||
| 149 | - /> | ||
| 150 | - ), | ||
| 151 | - }, | ||
| 152 | - ]); | ||
| 153 | 144 | ||
| 154 | return ( | 145 | return ( |
| 155 | <div class="space-y-5"> | 146 | <div class="space-y-5"> |
| @@ -194,98 +185,25 @@ export function InsightsBoard() { | |||
| 194 | </Show> | 185 | </Show> |
| 195 | </Suspense> | 186 | </Suspense> |
| 196 | 187 | ||
| 197 | - <Show when={canBrowseStudents()}> | 188 | + <Show when={flashMessage()}> |
| 198 | - <section class="data-shell space-y-4 p-4"> | 189 | + <Alert variant="success">{flashMessage()}</Alert> |
| 199 | - <Suspense fallback={<DataTableSkeleton columns={2} rows={8} />}> | ||
| 200 | - <Show when={students.error}> | ||
| 201 | - <ErrorAlert message={formatApiError(students.error)} onRetry={() => void refetchStudents()} /> | ||
| 202 | - </Show> | ||
| 203 | - <Show when={!students.error}> | ||
| 204 | - <DataTable | ||
| 205 | - title={tx("insights.title")} | ||
| 206 | - description={role() === "parent" ? tx("insights.parentSubtitle") : tx("insights.subtitle")} | ||
| 207 | - actions={ | ||
| 208 | - <> | ||
| 209 | - <Button variant="outline" size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => void refreshPage()}> | ||
| 210 | - <IconRefresh class="h-4 w-4" /> | ||
| 211 | - {tx("common.refresh")} | ||
| 212 | - </Button> | ||
| 213 | - <Show when={canManageRuns()}> | ||
| 214 | - <Button | ||
| 215 | - size="sm" | ||
| 216 | - class="min-w-[7.5rem] rounded-lg" | ||
| 217 | - disabled={refreshingAll()} | ||
| 218 | - onClick={() => void queueSchoolRefresh()} | ||
| 219 | - > | ||
| 220 | - <IconSparkles class="h-4 w-4" /> | ||
| 221 | - {refreshingAll() ? tx("insights.refreshingAll") : tx("insights.refreshAll")} | ||
| 222 | - </Button> | ||
| 223 | - </Show> | ||
| 224 | - </> | ||
| 225 | - } | ||
| 226 | - columns={columns()} | ||
| 227 | - data={students() ?? []} | ||
| 228 | - empty={role() === "parent" ? tx("insights.emptyLinkedStudents") : tx("insights.emptyStudents")} | ||
| 229 | - emptyIllustration="people" | ||
| 230 | - filterPlaceholder={tx("insights.searchStudents")} | ||
| 231 | - filterHint={tx("search.hint.people")} | ||
| 232 | - searchPredicate={(student, query) => matchesSearch(query, student.display_name, student.username)} | ||
| 233 | - enablePagination | ||
| 234 | - pageSize={PAGE_SIZE} | ||
| 235 | - storageKey="insight-students" | ||
| 236 | - onRowClick={openStudent} | ||
| 237 | - /> | ||
| 238 | - </Show> | ||
| 239 | - </Suspense> | ||
| 240 | - </section> | ||
| 241 | </Show> | 190 | </Show> |
| 242 | 191 | ||
| 243 | - <Show when={canManageRuns()}> | 192 | + <Show when={canManageRuns()} fallback={studentAnalysis()}> |
| 244 | - <section class="data-shell p-4"> | 193 | + <Tabs value={insightTab()} onChange={(value) => setInsightTab(value as "zeka" | "runs")} class="space-y-4"> |
| 245 | - <Suspense fallback={<DataTableSkeleton columns={6} rows={5} />}> | 194 | + <TabsList aria-label={tx("insights.title")}> |
| 246 | - <Show when={runs.error}> | 195 | + <TabsTrigger value="zeka">{tx("insights.title")}</TabsTrigger> |
| 247 | - <ErrorAlert message={formatApiError(runs.error)} onRetry={() => void refetchRuns()} /> | 196 | + <TabsTrigger value="runs">{tx("insights.runs")}</TabsTrigger> |
| 248 | - </Show> | 197 | + </TabsList> |
| 249 | - <Show when={!runs.error}> | 198 | + <TabsContent value="zeka" class="mt-0 space-y-4"> |
| 250 | - <InsightRunsTable runs={runs()?.items ?? []} /> | 199 | + {studentAnalysis()} |
| 251 | - </Show> | 200 | + </TabsContent> |
| 252 | - </Suspense> | 201 | + <TabsContent value="runs" class="mt-0"> |
| 253 | - </section> | 202 | + {runAnalysis()} |
| 203 | + </TabsContent> | ||
| 204 | + </Tabs> | ||
| 254 | </Show> | 205 | </Show> |
| 255 | 206 | ||
| 256 | - <SidePanel | ||
| 257 | - size="wide" | ||
| 258 | - open={selectedStudent() != null} | ||
| 259 | - onOpenChange={(open) => { | ||
| 260 | - if (!open) { | ||
| 261 | - setSelectedStudent(null); | ||
| 262 | - mutateInsight(null); | ||
| 263 | - setPanelError(""); | ||
| 264 | - } | ||
| 265 | - }} | ||
| 266 | - title={personLabel(selectedStudent())} | ||
| 267 | - description={tx("insights.studentAnalysis")} | ||
| 268 | - > | ||
| 269 | - <div class="space-y-4"> | ||
| 270 | - <div class="flex flex-wrap justify-end gap-2"> | ||
| 271 | - <Button variant="outline" size="sm" class="rounded-lg" onClick={() => void refetchInsight()}> | ||
| 272 | - <IconRefresh class="h-4 w-4" /> | ||
| 273 | - {tx("common.refresh")} | ||
| 274 | - </Button> | ||
| 275 | - <Button size="sm" class="rounded-lg" disabled={computingStudent()} onClick={() => void queueStudentCompute()}> | ||
| 276 | - <IconSparkles class="h-4 w-4" /> | ||
| 277 | - {computingStudent() ? tx("insights.recomputing") : tx("insights.recompute")} | ||
| 278 | - </Button> | ||
| 279 | - </div> | ||
| 280 | - <Show when={panelError()}> | ||
| 281 | - <ErrorAlert message={panelError()} onRetry={() => void refetchInsight()} /> | ||
| 282 | - </Show> | ||
| 283 | - <Show when={insight.loading && !insight()}> | ||
| 284 | - <p class="py-8 text-center text-sm text-muted-foreground">{tx("common.loading")}</p> | ||
| 285 | - </Show> | ||
| 286 | - <Show when={insight()}>{(value) => <InsightDetail insight={value()} />}</Show> | ||
| 287 | - </div> | ||
| 288 | - </SidePanel> | ||
| 289 | </div> | 207 | </div> |
| 290 | ); | 208 | ); |
| 291 | } | 209 | } |
src/components/insights/insight-overview.tsxadded+51 -0
| @@ -0,0 +1,51 @@ | |||
| 1 | +import { Show } from "solid-js"; | ||
| 2 | +import { runReportDecimal, runReportPercent } from "@/lib/insight-run-report"; | ||
| 3 | +import type { InsightOverview as Overview } from "@/lib/insight-students"; | ||
| 4 | +import { cn } from "@/lib/cn"; | ||
| 5 | +import { usePreferences } from "@/stores/preferences-context"; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * The picture over the students read so far: how many have an analysis, how | ||
| 9 | + * many need attention, and the mean mark and attendance their summaries | ||
| 10 | + * measured. A figure no summary measured reads "no data", never 0. | ||
| 11 | + */ | ||
| 12 | +export function InsightOverview(props: { overview: Overview }) { | ||
| 13 | + const prefs = usePreferences(); | ||
| 14 | + const t = (key: string, vars?: Record<string, string | number>) => prefs.t(key as never, vars); | ||
| 15 | + const tile = (label: string, value: string, hint: string, tone?: "warn") => ( | ||
| 16 | + <div class="rounded-xl border border-border-line bg-surface-base px-4 py-3"> | ||
| 17 | + <p class="text-xs font-medium text-muted-foreground">{label}</p> | ||
| 18 | + <p class={cn("mono mt-1 text-2xl font-semibold tabular-nums text-text-strong", tone === "warn" && "text-warning-text")}>{value}</p> | ||
| 19 | + <p class="mt-0.5 text-xs text-muted-foreground">{hint}</p> | ||
| 20 | + </div> | ||
| 21 | + ); | ||
| 22 | + const o = () => props.overview; | ||
| 23 | + return ( | ||
| 24 | + <section class="space-y-2" aria-label={t("insights.summary")}> | ||
| 25 | + <div class="grid grid-cols-2 gap-3 lg:grid-cols-4"> | ||
| 26 | + {tile(t("insights.overview.analysed"), String(o().analysed), t("insights.overview.ofTotal", { total: o().total }))} | ||
| 27 | + {tile( | ||
| 28 | + t("insights.overview.needAttention"), | ||
| 29 | + String(o().needAttention), | ||
| 30 | + t("insights.overview.ofTotal", { total: o().total }), | ||
| 31 | + o().needAttention > 0 ? "warn" : undefined, | ||
| 32 | + )} | ||
| 33 | + {tile( | ||
| 34 | + t("insights.overview.marks"), | ||
| 35 | + o().marksAverage == null ? "—" : runReportDecimal(o().marksAverage!, prefs.locale()), | ||
| 36 | + o().marksAverage == null ? t("insights.overview.noData") : t("insights.overview.ofTotal", { total: o().analysed }), | ||
| 37 | + )} | ||
| 38 | + {tile( | ||
| 39 | + t("insights.overview.attendance"), | ||
| 40 | + o().attendanceRate == null ? "—" : runReportPercent(o().attendanceRate, prefs.locale()), | ||
| 41 | + o().attendanceRate == null ? t("insights.overview.noData") : t("insights.overview.ofTotal", { total: o().analysed }), | ||
| 42 | + )} | ||
| 43 | + </div> | ||
| 44 | + <Show when={o().loaded < o().total}> | ||
| 45 | + <p class="text-xs text-muted-foreground" role="status"> | ||
| 46 | + {t("insights.overview.reading", { loaded: o().loaded, total: o().total })} | ||
| 47 | + </p> | ||
| 48 | + </Show> | ||
| 49 | + </section> | ||
| 50 | + ); | ||
| 51 | +} | ||
src/components/insights/insight-runs-table.tsxmodified+24 -16
| @@ -5,7 +5,6 @@ import { InsightRunReport } from "@/components/insights/insight-run-report"; | |||
| 5 | import { Badge } from "@/components/ui/badge"; | 5 | import { Badge } from "@/components/ui/badge"; |
| 6 | import { DataTable } from "@/components/ui/data-table"; | 6 | import { DataTable } from "@/components/ui/data-table"; |
| 7 | import { IconFileText } from "@/components/ui/icons"; | 7 | import { IconFileText } from "@/components/ui/icons"; |
| 8 | -import { SidePanel } from "@/components/ui/side-panel"; | ||
| 9 | import { TableRowActions } from "@/components/ui/table-row-actions"; | 8 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 10 | import { runReportText, type RunReportKey } from "@/i18n/insights-run-report"; | 9 | import { runReportText, type RunReportKey } from "@/i18n/insights-run-report"; |
| 11 | import { cn } from "@/lib/cn"; | 10 | import { cn } from "@/lib/cn"; |
| @@ -31,6 +30,7 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) { | |||
| 31 | { | 30 | { |
| 32 | accessorKey: "run_day", | 31 | accessorKey: "run_day", |
| 33 | header: tx("insights.runDay"), | 32 | header: tx("insights.runDay"), |
| 33 | + meta: { align: "center" }, | ||
| 34 | cell: (cell) => ( | 34 | cell: (cell) => ( |
| 35 | <div> | 35 | <div> |
| 36 | <p class="font-medium text-text-strong">{cell.row.original.run_day}</p> | 36 | <p class="font-medium text-text-strong">{cell.row.original.run_day}</p> |
| @@ -41,6 +41,7 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) { | |||
| 41 | { | 41 | { |
| 42 | accessorKey: "status", | 42 | accessorKey: "status", |
| 43 | header: tx("insights.result"), | 43 | header: tx("insights.result"), |
| 44 | + meta: { align: "center" }, | ||
| 44 | cell: (cell) => ( | 45 | cell: (cell) => ( |
| 45 | <Badge variant={statusVariant(cell.row.original.status)} class="rounded-full"> | 46 | <Badge variant={statusVariant(cell.row.original.status)} class="rounded-full"> |
| 46 | {runReportStatusLabel(prefs.locale(), cell.row.original.status)} | 47 | {runReportStatusLabel(prefs.locale(), cell.row.original.status)} |
| @@ -51,11 +52,11 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) { | |||
| 51 | id: "processed", | 52 | id: "processed", |
| 52 | header: tx("insights.processed"), | 53 | header: tx("insights.processed"), |
| 53 | accessorFn: (row) => row.students_ok, | 54 | accessorFn: (row) => row.students_ok, |
| 54 | - meta: { align: "right" }, | 55 | + meta: { align: "center" }, |
| 55 | cell: (cell) => { | 56 | cell: (cell) => { |
| 56 | const run = cell.row.original; | 57 | const run = cell.row.original; |
| 57 | return ( | 58 | return ( |
| 58 | - <div class="text-right"> | 59 | + <div class="text-center"> |
| 59 | <p class="mono font-medium tabular-nums">{run.students_ok}/{run.students_total}</p> | 60 | <p class="mono font-medium tabular-nums">{run.students_ok}/{run.students_total}</p> |
| 60 | <p class="text-[11px] text-muted-foreground">{run.students_failed} / {run.students_skipped}</p> | 61 | <p class="text-[11px] text-muted-foreground">{run.students_failed} / {run.students_skipped}</p> |
| 61 | </div> | 62 | </div> |
| @@ -65,23 +66,24 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) { | |||
| 65 | { | 66 | { |
| 66 | accessorKey: "rows_written", | 67 | accessorKey: "rows_written", |
| 67 | header: tx("insights.written"), | 68 | header: tx("insights.written"), |
| 68 | - meta: { align: "right", cellClass: "mono tabular-nums" }, | 69 | + meta: { align: "center", cellClass: "mono tabular-nums" }, |
| 69 | }, | 70 | }, |
| 70 | { | 71 | { |
| 71 | accessorKey: "duration_ms", | 72 | accessorKey: "duration_ms", |
| 72 | header: tx("insights.duration"), | 73 | header: tx("insights.duration"), |
| 73 | - meta: { align: "right" }, | 74 | + meta: { align: "center" }, |
| 74 | cell: (cell) => <span class="mono tabular-nums">{formatDurationMinutes(cell.row.original.duration_ms, prefs.locale())}</span>, | 75 | cell: (cell) => <span class="mono tabular-nums">{formatDurationMinutes(cell.row.original.duration_ms, prefs.locale())}</span>, |
| 75 | }, | 76 | }, |
| 76 | { | 77 | { |
| 77 | id: "issues", | 78 | id: "issues", |
| 78 | header: tx("insights.issues"), | 79 | header: tx("insights.issues"), |
| 79 | enableSorting: false, | 80 | enableSorting: false, |
| 81 | + meta: { align: "center" }, | ||
| 80 | cell: (cell) => { | 82 | cell: (cell) => { |
| 81 | const run = cell.row.original; | 83 | const run = cell.row.original; |
| 82 | const issueCount = run.pending_students.length + run.failed_modules.length; | 84 | const issueCount = run.pending_students.length + run.failed_modules.length; |
| 83 | return ( | 85 | return ( |
| 84 | - <div class="space-y-1"> | 86 | + <div class="space-y-1 text-center"> |
| 85 | <p class={cn("text-xs", issueCount > 0 || run.budget_exceeded ? "text-warning-text" : "text-muted-foreground")}> | 87 | <p class={cn("text-xs", issueCount > 0 || run.budget_exceeded ? "text-warning-text" : "text-muted-foreground")}> |
| 86 | {issueCount > 0 ? tx("insights.issueCount", { count: issueCount }) : tx("insights.noIssues")} | 88 | {issueCount > 0 ? tx("insights.issueCount", { count: issueCount }) : tx("insights.noIssues")} |
| 87 | </p> | 89 | </p> |
| @@ -133,7 +135,7 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) { | |||
| 133 | columns={columns()} | 135 | columns={columns()} |
| 134 | data={props.runs} | 136 | data={props.runs} |
| 135 | empty={tx("insights.emptyRuns")} | 137 | empty={tx("insights.emptyRuns")} |
| 136 | - tableClass="min-w-[980px]" | 138 | + tableClass="insight-grid-table min-w-[980px]" |
| 137 | enablePagination | 139 | enablePagination |
| 138 | pageSize={10} | 140 | pageSize={10} |
| 139 | storageKey="insight-runs" | 141 | storageKey="insight-runs" |
| @@ -142,16 +144,22 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) { | |||
| 142 | 144 | ||
| 143 | <Show keyed when={selectedRun()}> | 145 | <Show keyed when={selectedRun()}> |
| 144 | {(run) => ( | 146 | {(run) => ( |
| 145 | - <SidePanel | 147 | + <section class="data-shell mt-5 space-y-4 p-5" aria-label={rtx("panelDescription", { day: run.run_day })}> |
| 146 | - size="xl" | 148 | + <div class="flex flex-wrap items-center justify-between gap-3 border-b border-border-line pb-3"> |
| 147 | - open | 149 | + <div> |
| 148 | - onOpenChange={(open) => { | 150 | + <p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground">{rtx("open")}</p> |
| 149 | - if (!open) setSelectedRun(null); | 151 | + <h2 class="mt-1 text-lg font-semibold text-text-strong">{rtx("panelDescription", { day: run.run_day })}</h2> |
| 150 | - }} | 152 | + </div> |
| 151 | - title={rtx("panelDescription", { day: run.run_day })} | 153 | + <button |
| 152 | - > | 154 | + type="button" |
| 155 | + class="rounded-lg border border-border/70 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| 156 | + onClick={() => setSelectedRun(null)} | ||
| 157 | + > | ||
| 158 | + {tx("common.close")} | ||
| 159 | + </button> | ||
| 160 | + </div> | ||
| 153 | <InsightRunReport run={run} /> | 161 | <InsightRunReport run={run} /> |
| 154 | - </SidePanel> | 162 | + </section> |
| 155 | )} | 163 | )} |
| 156 | </Show> | 164 | </Show> |
| 157 | </> | 165 | </> |
src/components/insights/insight-student-analysis-tabs.tsxadded+237 -0
| @@ -0,0 +1,237 @@ | |||
| 1 | +import { For, Show } from "solid-js"; | ||
| 2 | +import type { StudentInsight } from "@/api/client"; | ||
| 3 | +import { InsightDetail } from "@/components/insights/insight-detail"; | ||
| 4 | +import { InsightModuleView } from "@/components/insights/insight-module-views"; | ||
| 5 | +import { EmptyInline } from "@/components/ui/empty-inline"; | ||
| 6 | +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
| 7 | +import { isRecord, type UnknownRecord } from "@/lib/is-record"; | ||
| 8 | +import { usePreferences } from "@/stores/preferences-context"; | ||
| 9 | + | ||
| 10 | +type Rec = UnknownRecord; | ||
| 11 | + | ||
| 12 | +const obj = (value: unknown): Rec => (isRecord(value) ? value : {}); | ||
| 13 | +const num = (value: unknown): number | null => | ||
| 14 | + typeof value === "number" && Number.isFinite(value) ? value : null; | ||
| 15 | + | ||
| 16 | +function ChartCard(props: { label: string; value: string; hint?: string }) { | ||
| 17 | + return ( | ||
| 18 | + <div class="rounded-xl border border-border-line bg-surface-base px-4 py-3"> | ||
| 19 | + <p class="text-xs text-muted-foreground">{props.label}</p> | ||
| 20 | + <p class="mono mt-1 text-xl font-semibold tabular-nums text-text-strong">{props.value}</p> | ||
| 21 | + <Show when={props.hint}> | ||
| 22 | + <p class="mt-1 text-[11px] text-muted-foreground">{props.hint}</p> | ||
| 23 | + </Show> | ||
| 24 | + </div> | ||
| 25 | + ); | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +function BarChart(props: { | ||
| 29 | + items: Array<{ label: string; value: number | null; color?: string }>; | ||
| 30 | + format?: (value: number) => string; | ||
| 31 | +}) { | ||
| 32 | + const max = () => Math.max(...props.items.map((item) => item.value ?? 0), 1); | ||
| 33 | + const format = (value: number) => props.format?.(value) ?? String(value); | ||
| 34 | + return ( | ||
| 35 | + <div class="space-y-3"> | ||
| 36 | + <For each={props.items}> | ||
| 37 | + {(item) => ( | ||
| 38 | + <div class="space-y-1.5"> | ||
| 39 | + <div class="flex items-center justify-between gap-3 text-xs"> | ||
| 40 | + <span class="truncate text-muted-foreground">{item.label}</span> | ||
| 41 | + <span class="mono shrink-0 font-semibold text-text-strong"> | ||
| 42 | + {item.value == null ? "—" : format(item.value)} | ||
| 43 | + </span> | ||
| 44 | + </div> | ||
| 45 | + <div class="h-2 overflow-hidden rounded-full bg-surface-fill"> | ||
| 46 | + <div | ||
| 47 | + class={`h-full rounded-full ${item.color ?? "bg-primary"}`} | ||
| 48 | + style={{ width: `${item.value == null ? 0 : Math.max(3, (item.value / max()) * 100)}%` }} | ||
| 49 | + /> | ||
| 50 | + </div> | ||
| 51 | + </div> | ||
| 52 | + )} | ||
| 53 | + </For> | ||
| 54 | + </div> | ||
| 55 | + ); | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +function AttendanceChart(props: { value: unknown; t: (key: string) => string }) { | ||
| 59 | + const overall = () => obj(obj(props.value).overall); | ||
| 60 | + const count = (key: string) => num(overall()[key]) ?? 0; | ||
| 61 | + const rate = () => num(overall().rate); | ||
| 62 | + return ( | ||
| 63 | + <div class="space-y-4"> | ||
| 64 | + <div class="grid gap-3 sm:grid-cols-3"> | ||
| 65 | + <ChartCard label={props.t("insights.analysis.rate")} value={rate() == null ? "—" : `%${Math.round(rate()! * 100)}`} /> | ||
| 66 | + <ChartCard label={props.t("insights.analysis.present")} value={String(count("present"))} /> | ||
| 67 | + <ChartCard label={props.t("insights.analysis.absent")} value={String(count("absent"))} /> | ||
| 68 | + </div> | ||
| 69 | + <BarChart | ||
| 70 | + items={[ | ||
| 71 | + { label: props.t("insights.analysis.present"), value: count("present"), color: "bg-success" }, | ||
| 72 | + { label: props.t("insights.analysis.absent"), value: count("absent"), color: "bg-destructive" }, | ||
| 73 | + { label: props.t("insights.analysis.late"), value: count("late"), color: "bg-warning" }, | ||
| 74 | + { label: props.t("insights.analysis.excused"), value: count("excused"), color: "bg-info" }, | ||
| 75 | + ]} | ||
| 76 | + /> | ||
| 77 | + </div> | ||
| 78 | + ); | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +function MarksChart(props: { value: unknown; t: (key: string) => string }) { | ||
| 82 | + const courses = () => Object.entries(obj(obj(props.value).courses)); | ||
| 83 | + const items = () => courses().map(([id, raw]) => { | ||
| 84 | + const stat = obj(raw); | ||
| 85 | + return { label: String(stat.course_title ?? id).slice(0, 32), value: num(stat.average) }; | ||
| 86 | + }); | ||
| 87 | + const averages = () => items().map((item) => item.value).filter((value): value is number => value != null); | ||
| 88 | + const average = () => averages().length ? averages().reduce((sum, value) => sum + value, 0) / averages().length : null; | ||
| 89 | + return ( | ||
| 90 | + <div class="space-y-4"> | ||
| 91 | + <div class="grid gap-3 sm:grid-cols-3"> | ||
| 92 | + <ChartCard label={props.t("insights.analysis.average")} value={average() == null ? "—" : average()!.toLocaleString("tr-TR", { maximumFractionDigits: 1 })} /> | ||
| 93 | + <ChartCard label={props.t("insights.analysis.courses")} value={String(items().length)} /> | ||
| 94 | + <ChartCard label={props.t("insights.analysis.bestMark")} value={averages().length ? Math.max(...averages()).toLocaleString("tr-TR", { maximumFractionDigits: 1 }) : "—"} /> | ||
| 95 | + </div> | ||
| 96 | + <Show when={items().length > 0} fallback={<EmptyInline title={props.t("insights.noSummary")} illustration="charts" />}> | ||
| 97 | + <BarChart items={items()} format={(value) => value.toLocaleString("tr-TR", { maximumFractionDigits: 1 })} /> | ||
| 98 | + </Show> | ||
| 99 | + </div> | ||
| 100 | + ); | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +function StudyChart(props: { value: unknown; t: (key: string) => string }) { | ||
| 104 | + const recent = () => obj(obj(props.value).recent_28d); | ||
| 105 | + const hours = () => { | ||
| 106 | + const milliseconds = num(recent().total_focus_ms); | ||
| 107 | + return milliseconds == null ? null : milliseconds / 3_600_000; | ||
| 108 | + }; | ||
| 109 | + return ( | ||
| 110 | + <div class="space-y-4"> | ||
| 111 | + <div class="grid gap-3 sm:grid-cols-3"> | ||
| 112 | + <ChartCard label={props.t("insights.analysis.focusHours")} value={hours() == null ? "—" : hours()!.toLocaleString("tr-TR", { maximumFractionDigits: 1 })} /> | ||
| 113 | + <ChartCard label={props.t("insights.analysis.activeDays")} value={String(num(recent().active_days) ?? "—")} /> | ||
| 114 | + <ChartCard label={props.t("insights.analysis.regularity")} value={num(recent().regularity) == null ? "—" : `%${Math.round(num(recent().regularity)! * 100)}`} /> | ||
| 115 | + </div> | ||
| 116 | + <BarChart | ||
| 117 | + items={[ | ||
| 118 | + { label: props.t("insights.analysis.focusHours"), value: hours(), color: "bg-primary" }, | ||
| 119 | + { label: props.t("insights.analysis.activeDays"), value: num(recent().active_days), color: "bg-info" }, | ||
| 120 | + { label: props.t("insights.analysis.sessions"), value: num(recent().n_stints), color: "bg-success" }, | ||
| 121 | + ]} | ||
| 122 | + format={(value) => value.toLocaleString("tr-TR", { maximumFractionDigits: 1 })} | ||
| 123 | + /> | ||
| 124 | + </div> | ||
| 125 | + ); | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +function SubmissionChart(props: { value: unknown; t: (key: string) => string }) { | ||
| 129 | + const overall = () => obj(obj(props.value).overall); | ||
| 130 | + const count = (key: string) => num(overall()[key]) ?? 0; | ||
| 131 | + const total = () => count("n"); | ||
| 132 | + const submittedRate = () => total() > 0 ? count("n_submitted") / total() : null; | ||
| 133 | + return ( | ||
| 134 | + <div class="space-y-4"> | ||
| 135 | + <div class="grid gap-3 sm:grid-cols-3"> | ||
| 136 | + <ChartCard label={props.t("insights.analysis.submittedRate")} value={submittedRate() == null ? "—" : `%${Math.round(submittedRate()! * 100)}`} /> | ||
| 137 | + <ChartCard label={props.t("insights.analysis.submitted")} value={String(count("n_submitted"))} /> | ||
| 138 | + <ChartCard label={props.t("insights.analysis.missing")} value={String(count("n_missing"))} /> | ||
| 139 | + </div> | ||
| 140 | + <BarChart | ||
| 141 | + items={[ | ||
| 142 | + { label: props.t("insights.analysis.submitted"), value: count("n_submitted"), color: "bg-success" }, | ||
| 143 | + { label: props.t("insights.analysis.late"), value: count("n_late"), color: "bg-warning" }, | ||
| 144 | + { label: props.t("insights.analysis.missing"), value: count("n_missing"), color: "bg-destructive" }, | ||
| 145 | + ]} | ||
| 146 | + /> | ||
| 147 | + </div> | ||
| 148 | + ); | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +function ModuleTab(props: { | ||
| 152 | + module: "attendance" | "marks" | "study" | "submission"; | ||
| 153 | + value: unknown; | ||
| 154 | + courseTitle: (id: string) => string | null; | ||
| 155 | + t: (key: string) => string; | ||
| 156 | +}) { | ||
| 157 | + const chart = () => { | ||
| 158 | + if (props.module === "attendance") return <AttendanceChart value={props.value} t={props.t} />; | ||
| 159 | + if (props.module === "marks") return <MarksChart value={props.value} t={props.t} />; | ||
| 160 | + if (props.module === "study") return <StudyChart value={props.value} t={props.t} />; | ||
| 161 | + return <SubmissionChart value={props.value} t={props.t} />; | ||
| 162 | + }; | ||
| 163 | + return ( | ||
| 164 | + <Show when={props.value != null} fallback={<EmptyInline title={props.t("insights.sectionNotComputed")} illustration="charts" />}> | ||
| 165 | + <div class="space-y-5"> | ||
| 166 | + <section class="rounded-xl border border-border-line bg-surface-base p-4"> | ||
| 167 | + <div class="mb-4 flex items-center justify-between gap-3"> | ||
| 168 | + <h2 class="text-sm font-semibold text-text-strong">{props.t(`insights.modules.${props.module}`)}</h2> | ||
| 169 | + <span class="text-xs text-muted-foreground">{props.t("insights.analysis.visual")}</span> | ||
| 170 | + </div> | ||
| 171 | + {chart()} | ||
| 172 | + </section> | ||
| 173 | + <section class="rounded-xl border border-border-line bg-surface-base p-4"> | ||
| 174 | + <InsightModuleView module={props.module} value={props.value} courseTitle={props.courseTitle} /> | ||
| 175 | + </section> | ||
| 176 | + </div> | ||
| 177 | + </Show> | ||
| 178 | + ); | ||
| 179 | +} | ||
| 180 | + | ||
| 181 | +export function InsightStudentAnalysisTabs(props: { insight: StudentInsight }) { | ||
| 182 | + const prefs = usePreferences(); | ||
| 183 | + const t = (key: string) => prefs.t(key as never); | ||
| 184 | + const summary = () => props.insight.summary; | ||
| 185 | + const courseTitle = (id: string) => { | ||
| 186 | + const courses = obj(obj(summary()?.marks).courses); | ||
| 187 | + const course = obj(courses[id]); | ||
| 188 | + return typeof course.course_title === "string" ? course.course_title : null; | ||
| 189 | + }; | ||
| 190 | + const moduleValue = (module: "attendance" | "marks" | "study" | "submission") => summary()?.[module] ?? null; | ||
| 191 | + | ||
| 192 | + return ( | ||
| 193 | + <Tabs defaultValue="overview" class="space-y-4"> | ||
| 194 | + <TabsList class="w-full justify-start overflow-x-auto"> | ||
| 195 | + <TabsTrigger value="overview">{t("insights.analysis.overview")}</TabsTrigger> | ||
| 196 | + <TabsTrigger value="attendance">{t("insights.modules.attendance")}</TabsTrigger> | ||
| 197 | + <TabsTrigger value="marks">{t("insights.modules.marks")}</TabsTrigger> | ||
| 198 | + <TabsTrigger value="study">{t("insights.modules.study")}</TabsTrigger> | ||
| 199 | + <TabsTrigger value="submission">{t("insights.modules.submission")}</TabsTrigger> | ||
| 200 | + </TabsList> | ||
| 201 | + | ||
| 202 | + <TabsContent value="overview" class="mt-0 space-y-5"> | ||
| 203 | + <section class="grid gap-3 sm:grid-cols-2 xl:grid-cols-4"> | ||
| 204 | + <ChartCard label={t("insights.modules.attendance")} value={num(obj(obj(moduleValue("attendance")).overall).rate) == null ? "—" : `%${Math.round(num(obj(obj(moduleValue("attendance")).overall).rate)! * 100)}`} /> | ||
| 205 | + <ChartCard label={t("insights.modules.marks")} value={(() => { | ||
| 206 | + const values = Object.values(obj(obj(moduleValue("marks")).courses)).map((raw) => num(obj(raw).average)).filter((value): value is number => value != null); | ||
| 207 | + return values.length ? (values.reduce((sum, value) => sum + value, 0) / values.length).toLocaleString("tr-TR", { maximumFractionDigits: 1 }) : "—"; | ||
| 208 | + })()} /> | ||
| 209 | + <ChartCard label={t("insights.modules.study")} value={(() => { | ||
| 210 | + const milliseconds = num(obj(obj(moduleValue("study")).recent_28d).total_focus_ms); | ||
| 211 | + return milliseconds == null ? "—" : `${(milliseconds / 3_600_000).toLocaleString("tr-TR", { maximumFractionDigits: 1 })} sa`; | ||
| 212 | + })()} /> | ||
| 213 | + <ChartCard label={t("insights.modules.submission")} value={(() => { | ||
| 214 | + const overall = obj(obj(moduleValue("submission")).overall); | ||
| 215 | + const total = num(overall.n) ?? 0; | ||
| 216 | + const submitted = num(overall.n_submitted) ?? 0; | ||
| 217 | + return total > 0 ? `%${Math.round((submitted / total) * 100)}` : "—"; | ||
| 218 | + })()} /> | ||
| 219 | + </section> | ||
| 220 | + <InsightDetail insight={props.insight} mode="cards" /> | ||
| 221 | + </TabsContent> | ||
| 222 | + | ||
| 223 | + <TabsContent value="attendance" class="mt-0"> | ||
| 224 | + <ModuleTab module="attendance" value={moduleValue("attendance")} courseTitle={courseTitle} t={t} /> | ||
| 225 | + </TabsContent> | ||
| 226 | + <TabsContent value="marks" class="mt-0"> | ||
| 227 | + <ModuleTab module="marks" value={moduleValue("marks")} courseTitle={courseTitle} t={t} /> | ||
| 228 | + </TabsContent> | ||
| 229 | + <TabsContent value="study" class="mt-0"> | ||
| 230 | + <ModuleTab module="study" value={moduleValue("study")} courseTitle={courseTitle} t={t} /> | ||
| 231 | + </TabsContent> | ||
| 232 | + <TabsContent value="submission" class="mt-0"> | ||
| 233 | + <ModuleTab module="submission" value={moduleValue("submission")} courseTitle={courseTitle} t={t} /> | ||
| 234 | + </TabsContent> | ||
| 235 | + </Tabs> | ||
| 236 | + ); | ||
| 237 | +} | ||
src/components/insights/insight-students-table.tsxadded+221 -0
| @@ -0,0 +1,221 @@ | |||
| 1 | +import { For, createMemo, createSignal, type JSX } from "solid-js"; | ||
| 2 | +import { Link, useNavigate } from "@tanstack/solid-router"; | ||
| 3 | +import type { ColumnDef } from "@tanstack/solid-table"; | ||
| 4 | +import { Badge } from "@/components/ui/badge"; | ||
| 5 | +import { Button } from "@/components/ui/button"; | ||
| 6 | +import { DataTable } from "@/components/ui/data-table"; | ||
| 7 | +import { IconEye } from "@/components/ui/icons"; | ||
| 8 | +import { TableRowActions } from "@/components/ui/table-row-actions"; | ||
| 9 | +import { runReportText } from "@/i18n/insights-run-report"; | ||
| 10 | +import { | ||
| 11 | + confidenceText, | ||
| 12 | + studentAttendanceText, | ||
| 13 | + studentMarksText, | ||
| 14 | + studentStatusText, | ||
| 15 | + type StudentSignal, | ||
| 16 | +} from "@/lib/insight-run-report"; | ||
| 17 | +import { cn } from "@/lib/cn"; | ||
| 18 | +import { matchesSearch } from "@/lib/search-text"; | ||
| 19 | +import { usePreferences } from "@/stores/preferences-context"; | ||
| 20 | + | ||
| 21 | +type Filter = "all" | "attention" | "none"; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Every student's analysis at a glance: status, attention items, cards, the | ||
| 25 | + * marks, attendance and focus their summary measured, confidence and when it | ||
| 26 | + * was computed. Numeric columns sort on the real value; a row opens the | ||
| 27 | + * student's full analysis page. | ||
| 28 | + */ | ||
| 29 | +export function InsightStudentsTable(props: { | ||
| 30 | + rows: StudentSignal[]; | ||
| 31 | + title: string; | ||
| 32 | + description: string; | ||
| 33 | + empty: string; | ||
| 34 | + actions?: JSX.Element; | ||
| 35 | +}) { | ||
| 36 | + const prefs = usePreferences(); | ||
| 37 | + const navigate = useNavigate(); | ||
| 38 | + const locale = () => prefs.locale(); | ||
| 39 | + const t = (key: string, vars?: Record<string, string | number>) => prefs.t(key as never, vars); | ||
| 40 | + const rt = (key: Parameters<typeof runReportText>[1]) => runReportText(locale(), key); | ||
| 41 | + const [filter, setFilter] = createSignal<Filter>("all"); | ||
| 42 | + const visible = createMemo(() => | ||
| 43 | + props.rows.filter((row) => | ||
| 44 | + filter() === "attention" ? row.attention > 0 : filter() === "none" ? row.state === "no_summary" : true, | ||
| 45 | + ), | ||
| 46 | + ); | ||
| 47 | + const counts = createMemo(() => ({ | ||
| 48 | + all: props.rows.length, | ||
| 49 | + attention: props.rows.filter((row) => row.attention > 0).length, | ||
| 50 | + none: props.rows.filter((row) => row.state === "no_summary").length, | ||
| 51 | + })); | ||
| 52 | + const loaded = (row: StudentSignal) => row.state === "ok"; | ||
| 53 | + const muted = "text-muted-foreground"; | ||
| 54 | + const calculatedDate = (value: number | null | undefined) => { | ||
| 55 | + if (value == null) return "—"; | ||
| 56 | + return new Intl.DateTimeFormat(locale() === "tr" ? "tr-TR" : "en-US", { | ||
| 57 | + day: "2-digit", | ||
| 58 | + month: "2-digit", | ||
| 59 | + year: "numeric", | ||
| 60 | + }).format(new Date(value)); | ||
| 61 | + }; | ||
| 62 | + | ||
| 63 | + const columns = createMemo<ColumnDef<StudentSignal>[]>(() => [ | ||
| 64 | + { | ||
| 65 | + id: "student", | ||
| 66 | + accessorFn: (row) => row.name, | ||
| 67 | + header: rt("student"), | ||
| 68 | + size: 220, | ||
| 69 | + meta: { align: "center" }, | ||
| 70 | + cell: (cell) => ( | ||
| 71 | + <Link to="/ai/insights/$userId" params={{ userId: cell.row.original.id }} class="font-medium text-text-default hover:text-primary-text hover:underline"> | ||
| 72 | + {cell.row.original.name} | ||
| 73 | + </Link> | ||
| 74 | + ), | ||
| 75 | + }, | ||
| 76 | + { | ||
| 77 | + id: "status", | ||
| 78 | + accessorFn: (row) => row.state, | ||
| 79 | + header: rt("status" as never), | ||
| 80 | + meta: { align: "center" }, | ||
| 81 | + cell: (cell) => { | ||
| 82 | + const row = cell.row.original; | ||
| 83 | + return ( | ||
| 84 | + <Badge | ||
| 85 | + variant="outline" | ||
| 86 | + class={cn( | ||
| 87 | + "rounded-full", | ||
| 88 | + row.state === "ok" && "border-success/30 bg-success/10 text-success-text", | ||
| 89 | + row.state === "error" && "border-destructive/30 bg-destructive/10 text-destructive-text", | ||
| 90 | + row.state === "not_loaded" && "animate-pulse", | ||
| 91 | + )} | ||
| 92 | + title={row.error ?? undefined} | ||
| 93 | + > | ||
| 94 | + {row.state === "error" ? t("insights.readFailed") : studentStatusText(locale(), row)} | ||
| 95 | + </Badge> | ||
| 96 | + ); | ||
| 97 | + }, | ||
| 98 | + }, | ||
| 99 | + { | ||
| 100 | + id: "attention", | ||
| 101 | + accessorFn: (row) => row.attention, | ||
| 102 | + header: rt("attention"), | ||
| 103 | + meta: { align: "center" }, | ||
| 104 | + cell: (cell) => ( | ||
| 105 | + <span class={cn("mono tabular-nums", cell.row.original.attention > 0 ? "font-semibold text-warning-text" : muted)}> | ||
| 106 | + {loaded(cell.row.original) || cell.row.original.state === "no_summary" ? cell.row.original.attention : "—"} | ||
| 107 | + </span> | ||
| 108 | + ), | ||
| 109 | + }, | ||
| 110 | + { | ||
| 111 | + id: "cards", | ||
| 112 | + accessorFn: (row) => row.cards, | ||
| 113 | + header: rt("cards"), | ||
| 114 | + meta: { align: "center" }, | ||
| 115 | + cell: (cell) => <span class="mono tabular-nums">{cell.row.original.state === "not_loaded" ? "—" : cell.row.original.cards}</span>, | ||
| 116 | + }, | ||
| 117 | + { | ||
| 118 | + id: "marks", | ||
| 119 | + accessorFn: (row) => row.marks.average ?? -1, | ||
| 120 | + header: rt("marksAverage"), | ||
| 121 | + meta: { align: "center" }, | ||
| 122 | + cell: (cell) => <span class={cn("mono tabular-nums", !loaded(cell.row.original) && muted)}>{studentMarksText(locale(), cell.row.original)}</span>, | ||
| 123 | + }, | ||
| 124 | + { | ||
| 125 | + id: "attendance", | ||
| 126 | + accessorFn: (row) => (row.attendance.observed > 0 ? row.attendance.rate ?? -1 : -1), | ||
| 127 | + header: rt("attendanceRate"), | ||
| 128 | + meta: { align: "center" }, | ||
| 129 | + cell: (cell) => { | ||
| 130 | + const row = cell.row.original; | ||
| 131 | + const low = loaded(row) && row.attendance.observed > 0 && (row.attendance.rate ?? 1) < 0.85; | ||
| 132 | + return <span class={cn("mono tabular-nums", low && "font-semibold text-warning-text", !loaded(row) && muted)}>{studentAttendanceText(locale(), row)}</span>; | ||
| 133 | + }, | ||
| 134 | + }, | ||
| 135 | + { | ||
| 136 | + id: "study", | ||
| 137 | + accessorFn: (row) => row.study.stints, | ||
| 138 | + header: t("insights.studyStints"), | ||
| 139 | + meta: { align: "center" }, | ||
| 140 | + cell: (cell) => <span class={cn("mono tabular-nums", !loaded(cell.row.original) && muted)}>{loaded(cell.row.original) ? cell.row.original.study.stints : "—"}</span>, | ||
| 141 | + }, | ||
| 142 | + { | ||
| 143 | + id: "confidence", | ||
| 144 | + accessorFn: (row) => row.confidence ?? "", | ||
| 145 | + header: rt("confidence"), | ||
| 146 | + meta: { align: "center" }, | ||
| 147 | + cell: (cell) => <span class={muted}>{cell.row.original.confidence ? confidenceText(locale(), cell.row.original.confidence) : "—"}</span>, | ||
| 148 | + }, | ||
| 149 | + { | ||
| 150 | + id: "computedAt", | ||
| 151 | + accessorFn: (row) => row.computed_at ?? 0, | ||
| 152 | + header: t("insights.computedAt"), | ||
| 153 | + meta: { align: "center", cellClass: "mono text-xs text-muted-foreground whitespace-nowrap" }, | ||
| 154 | + cell: (cell) => calculatedDate(cell.row.original.computed_at), | ||
| 155 | + }, | ||
| 156 | + { | ||
| 157 | + id: "actions", | ||
| 158 | + header: t("common.actions"), | ||
| 159 | + enableSorting: false, | ||
| 160 | + meta: { | ||
| 161 | + align: "center", | ||
| 162 | + headerClass: "text-center", | ||
| 163 | + cellClass: "text-center", | ||
| 164 | + }, | ||
| 165 | + cell: (cell) => ( | ||
| 166 | + <TableRowActions | ||
| 167 | + label={t("common.actions")} | ||
| 168 | + actions={[{ | ||
| 169 | + label: t("insights.viewAnalysis"), | ||
| 170 | + icon: <IconEye class="h-4 w-4" />, | ||
| 171 | + onSelect: () => void navigate({ to: "/ai/insights/$userId", params: { userId: cell.row.original.id } }), | ||
| 172 | + }]} | ||
| 173 | + /> | ||
| 174 | + ), | ||
| 175 | + }, | ||
| 176 | + ]); | ||
| 177 | + | ||
| 178 | + const filters: { id: Filter; label: string }[] = [ | ||
| 179 | + { id: "all", label: t("insights.filter.all") }, | ||
| 180 | + { id: "attention", label: t("insights.filter.attention") }, | ||
| 181 | + { id: "none", label: t("insights.filter.noAnalysis") }, | ||
| 182 | + ]; | ||
| 183 | + | ||
| 184 | + return ( | ||
| 185 | + <DataTable | ||
| 186 | + title={props.title} | ||
| 187 | + description={props.description} | ||
| 188 | + actions={props.actions} | ||
| 189 | + columns={columns()} | ||
| 190 | + data={visible()} | ||
| 191 | + onRowClick={(row) => void navigate({ to: "/ai/insights/$userId", params: { userId: row.id } })} | ||
| 192 | + empty={props.empty} | ||
| 193 | + emptyIllustration="people" | ||
| 194 | + filterPlaceholder={t("insights.searchStudents")} | ||
| 195 | + filterHint={t("search.hint.people")} | ||
| 196 | + searchPredicate={(row, query) => matchesSearch(query, row.name)} | ||
| 197 | + filters={ | ||
| 198 | + <div class="flex flex-wrap items-center gap-1.5" role="group" aria-label={t("insights.filter.all")}> | ||
| 199 | + <For each={filters}> | ||
| 200 | + {(item) => ( | ||
| 201 | + <Button | ||
| 202 | + type="button" | ||
| 203 | + size="sm" | ||
| 204 | + variant={filter() === item.id ? "default" : "outline"} | ||
| 205 | + aria-pressed={filter() === item.id} | ||
| 206 | + onClick={() => setFilter(item.id)} | ||
| 207 | + > | ||
| 208 | + {item.label} | ||
| 209 | + <span class="mono ml-1 tabular-nums opacity-70">{counts()[item.id]}</span> | ||
| 210 | + </Button> | ||
| 211 | + )} | ||
| 212 | + </For> | ||
| 213 | + </div> | ||
| 214 | + } | ||
| 215 | + enablePagination | ||
| 216 | + pageSize={10} | ||
| 217 | + tableClass="insight-grid-table min-w-[70rem]" | ||
| 218 | + storageKey="insight-students-v2" | ||
| 219 | + /> | ||
| 220 | + ); | ||
| 221 | +} | ||
src/components/layout/nav-items.test.tsmodified+4 -3
| @@ -163,12 +163,13 @@ test("the AI group exposes four separate module routes", () => { | |||
| 163 | expect(routeLabelKey("/ai/studio", "student")).toBe("aiHub.tab.studio"); | 163 | expect(routeLabelKey("/ai/studio", "student")).toBe("aiHub.tab.studio"); |
| 164 | }); | 164 | }); |
| 165 | 165 | ||
| 166 | -test("AI modules navigate while account settings still opens a shell surface", () => { | 166 | +test("AI modules navigate while Çelebi and account settings open shell surfaces", () => { |
| 167 | const celebi = visibleNavGroups("student") | 167 | const celebi = visibleNavGroups("student") |
| 168 | .flatMap((g) => g.items) | 168 | .flatMap((g) => g.items) |
| 169 | .find((i) => i.id === "ai-celebi"); | 169 | .find((i) => i.id === "ai-celebi"); |
| 170 | - expect(celebi?.to).toBe("/ai/celebi"); | 170 | + expect(celebi?.to).toBe(""); |
| 171 | - expect(celebi?.action).toBeUndefined(); | 171 | + expect(celebi?.action).toBe("celebi"); |
| 172 | + expect(routeNavItem("/ai/celebi", "student")).toBeUndefined(); | ||
| 172 | const settings = visibleNavGroups("student") | 173 | const settings = visibleNavGroups("student") |
| 173 | .flatMap((g) => g.items) | 174 | .flatMap((g) => g.items) |
| 174 | .find((i) => i.id === "settings-student"); | 175 | .find((i) => i.id === "settings-student"); |
src/components/layout/nav-items.tsmodified+2 -1
| @@ -97,9 +97,10 @@ const AI_INSIGHTS_ITEM: NavItem = { | |||
| 97 | 97 | ||
| 98 | const AI_CELEBI_ITEM: NavItem = { | 98 | const AI_CELEBI_ITEM: NavItem = { |
| 99 | id: "ai-celebi", | 99 | id: "ai-celebi", |
| 100 | - to: "/ai/celebi", | 100 | + to: "", |
| 101 | labelKey: "nav.celebi", | 101 | labelKey: "nav.celebi", |
| 102 | Icon: IconSparkles, | 102 | Icon: IconSparkles, |
| 103 | + action: "celebi", | ||
| 103 | }; | 104 | }; |
| 104 | 105 | ||
| 105 | const AI_GROUP: NavGroup = { | 106 | const AI_GROUP: NavGroup = { |
src/components/rag/rag-study-panel.tsxmodified+34 -12
| @@ -18,8 +18,7 @@ import { RagThreadList } from "@/components/rag/rag-thread-list"; | |||
| 18 | import { Alert } from "@/components/ui/alert"; | 18 | import { Alert } from "@/components/ui/alert"; |
| 19 | import { Button } from "@/components/ui/button"; | 19 | import { Button } from "@/components/ui/button"; |
| 20 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 20 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 21 | -import { EmptyInline } from "@/components/ui/empty-inline"; | 21 | +import { IconEdit, IconPlus } from "@/components/ui/icons"; |
| 22 | -import { IconPlus } from "@/components/ui/icons"; | ||
| 23 | import { scopeFromCitations } from "@/lib/rag-study-scope"; | 22 | import { scopeFromCitations } from "@/lib/rag-study-scope"; |
| 24 | import { usePreferences } from "@/stores/preferences-context"; | 23 | import { usePreferences } from "@/stores/preferences-context"; |
| 25 | 24 | ||
| @@ -35,6 +34,7 @@ export function RagStudyPanel() { | |||
| 35 | const { locale } = usePreferences(); | 34 | const { locale } = usePreferences(); |
| 36 | const copy = () => ragCopy(locale()); | 35 | const copy = () => ragCopy(locale()); |
| 37 | const [threadId, setThreadId] = createSignal<string | undefined>(); | 36 | const [threadId, setThreadId] = createSignal<string | undefined>(); |
| 37 | + const [activeThread, setActiveThread] = createSignal<RagThread>(); | ||
| 38 | const [threadsVersion, setThreadsVersion] = createSignal(0); | 38 | const [threadsVersion, setThreadsVersion] = createSignal(0); |
| 39 | const [messages, setMessages] = createSignal<RagMessage[]>([]); | 39 | const [messages, setMessages] = createSignal<RagMessage[]>([]); |
| 40 | const [draft, setDraft] = createSignal(""); | 40 | const [draft, setDraft] = createSignal(""); |
| @@ -113,6 +113,7 @@ export function RagStudyPanel() { | |||
| 113 | stopStream(); | 113 | stopStream(); |
| 114 | setError(""); | 114 | setError(""); |
| 115 | setThreadId(thread.id); | 115 | setThreadId(thread.id); |
| 116 | + setActiveThread(thread); | ||
| 116 | try { | 117 | try { |
| 117 | setMessages((await getRagThreadMessages(thread.id, { limit: 500 })).items); | 118 | setMessages((await getRagThreadMessages(thread.id, { limit: 500 })).items); |
| 118 | } catch (err) { | 119 | } catch (err) { |
| @@ -124,6 +125,7 @@ export function RagStudyPanel() { | |||
| 124 | stopStream(); | 125 | stopStream(); |
| 125 | setError(""); | 126 | setError(""); |
| 126 | setThreadId(undefined); | 127 | setThreadId(undefined); |
| 128 | + setActiveThread(undefined); | ||
| 127 | setMessages([]); | 129 | setMessages([]); |
| 128 | }; | 130 | }; |
| 129 | 131 | ||
| @@ -139,14 +141,17 @@ export function RagStudyPanel() { | |||
| 139 | { id: `local-${now}`, thread_id: threadId() ?? "", role: "user", status: "complete", content, abstained: false, reason: "", citations: [], created_at: now }, | 141 | { id: `local-${now}`, thread_id: threadId() ?? "", role: "user", status: "complete", content, abstained: false, reason: "", citations: [], created_at: now }, |
| 140 | ]); | 142 | ]); |
| 141 | try { | 143 | try { |
| 142 | - const activeThread = threadId() ?? (await postRagThread()).id; | 144 | + const currentThread = threadId(); |
| 143 | - setThreadId(activeThread); | 145 | + const createdThread = currentThread ? undefined : await postRagThread(); |
| 144 | - const accepted = await postRagMessage(activeThread, content); | 146 | + const resolvedThreadId = currentThread ?? createdThread!.id; |
| 147 | + if (createdThread) setActiveThread(createdThread); | ||
| 148 | + setThreadId(resolvedThreadId); | ||
| 149 | + const accepted = await postRagMessage(resolvedThreadId, content); | ||
| 145 | setMessages((items) => [ | 150 | setMessages((items) => [ |
| 146 | ...items, | 151 | ...items, |
| 147 | - { id: accepted.message_id, thread_id: activeThread, role: "assistant", status: "pending", content: "", abstained: false, reason: "", citations: [], created_at: Date.now() }, | 152 | + { id: accepted.message_id, thread_id: resolvedThreadId, role: "assistant", status: "pending", content: "", abstained: false, reason: "", citations: [], created_at: Date.now() }, |
| 148 | ]); | 153 | ]); |
| 149 | - streamAnswer(activeThread, accepted.message_id); | 154 | + streamAnswer(resolvedThreadId, accepted.message_id); |
| 150 | setThreadsVersion((version) => version + 1); | 155 | setThreadsVersion((version) => version + 1); |
| 151 | } catch (err) { | 156 | } catch (err) { |
| 152 | setError(formatApiError(err)); | 157 | setError(formatApiError(err)); |
| @@ -163,8 +168,8 @@ export function RagStudyPanel() { | |||
| 163 | }; | 168 | }; |
| 164 | 169 | ||
| 165 | return ( | 170 | return ( |
| 166 | - <div class="grid min-h-[32rem] gap-4 lg:grid-cols-[16rem_minmax(0,1fr)]"> | 171 | + <div class="grid min-h-[calc(100dvh-10rem)] gap-4 lg:h-[calc(100dvh-10rem)] lg:grid-cols-[18rem_minmax(0,1fr)]"> |
| 167 | - <aside class="flex min-h-0 flex-col gap-3 rounded-xl border border-border-line bg-surface-base p-3 lg:max-h-[calc(100dvh-14rem)]"> | 172 | + <aside class="flex h-full min-h-0 flex-col gap-3 rounded-xl border border-border-line bg-surface-base p-3 shadow-xs"> |
| 168 | <div class="flex items-center justify-between gap-2"> | 173 | <div class="flex items-center justify-between gap-2"> |
| 169 | <h2 class="text-sm font-semibold text-text-strong">{copy().history}</h2> | 174 | <h2 class="text-sm font-semibold text-text-strong">{copy().history}</h2> |
| 170 | <Button type="button" size="sm" class="h-8 rounded-lg" onClick={newThread}> | 175 | <Button type="button" size="sm" class="h-8 rounded-lg" onClick={newThread}> |
| @@ -183,14 +188,29 @@ export function RagStudyPanel() { | |||
| 183 | /> | 188 | /> |
| 184 | </aside> | 189 | </aside> |
| 185 | 190 | ||
| 186 | - <section class="flex min-h-0 flex-col overflow-hidden rounded-xl border border-border-line bg-surface-base lg:max-h-[calc(100dvh-14rem)]" aria-label={copy().title}> | 191 | + <section class="flex h-full min-h-0 flex-col overflow-hidden rounded-xl border border-border-line bg-surface-base shadow-xs" aria-label={copy().title}> |
| 192 | + <header class="flex shrink-0 items-center justify-between gap-3 border-b border-border-line px-4 py-3"> | ||
| 193 | + <div class="min-w-0"> | ||
| 194 | + <p class="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground">{copy().tabLabel}</p> | ||
| 195 | + <p class="truncate text-sm font-semibold text-text-strong">{activeThread()?.title || (threadId() ? copy().untitled : copy().emptyChat)}</p> | ||
| 196 | + </div> | ||
| 197 | + <div class="flex shrink-0 items-center gap-2"> | ||
| 198 | + <Show when={activeThread()}> | ||
| 199 | + {(thread) => ( | ||
| 200 | + <Button type="button" size="sm" variant="outline" class="h-8 rounded-lg" aria-label={copy().rename} title={copy().rename} onClick={() => setRenaming(thread())}> | ||
| 201 | + <IconEdit class="h-3.5 w-3.5" /> | ||
| 202 | + </Button> | ||
| 203 | + )} | ||
| 204 | + </Show> | ||
| 205 | + </div> | ||
| 206 | + </header> | ||
| 187 | <div class="min-h-0 flex-1 space-y-4 overflow-y-auto p-4" aria-live="polite"> | 207 | <div class="min-h-0 flex-1 space-y-4 overflow-y-auto p-4" aria-live="polite"> |
| 188 | <Show when={error()}> | 208 | <Show when={error()}> |
| 189 | <Alert variant="destructive">{error()}</Alert> | 209 | <Alert variant="destructive">{error()}</Alert> |
| 190 | </Show> | 210 | </Show> |
| 191 | <Show | 211 | <Show |
| 192 | when={messages().length > 0} | 212 | when={messages().length > 0} |
| 193 | - fallback={<EmptyInline class="py-16" size="md" illustration="messages" title={copy().emptyChat} hint={copy().emptyChatHint} />} | 213 | + fallback={<p class="py-16 text-center text-sm text-muted-foreground">{copy().emptyChatHint}</p>} |
| 194 | > | 214 | > |
| 195 | <For each={messages()}> | 215 | <For each={messages()}> |
| 196 | {(message, index) => { | 216 | {(message, index) => { |
| @@ -242,7 +262,9 @@ export function RagStudyPanel() { | |||
| 242 | onConfirm={async (title) => { | 262 | onConfirm={async (title) => { |
| 243 | const thread = renaming(); | 263 | const thread = renaming(); |
| 244 | if (!thread) return; | 264 | if (!thread) return; |
| 245 | - await patchRagThreadById(thread.id, title?.trim() || null); | 265 | + const nextTitle = title?.trim() || null; |
| 266 | + await patchRagThreadById(thread.id, nextTitle); | ||
| 267 | + if (activeThread()?.id === thread.id) setActiveThread({ ...activeThread()!, title: nextTitle }); | ||
| 246 | setThreadsVersion((version) => version + 1); | 268 | setThreadsVersion((version) => version + 1); |
| 247 | }} | 269 | }} |
| 248 | /> | 270 | /> |
src/components/ui/table-row-actions.tsxmodified+2 -2
| @@ -25,8 +25,8 @@ export function TableRowActions(props: { label: string; actions: TableRowAction[ | |||
| 25 | <DropdownMenu placement="bottom-end" gutter={6}> | 25 | <DropdownMenu placement="bottom-end" gutter={6}> |
| 26 | <DropdownMenuTrigger | 26 | <DropdownMenuTrigger |
| 27 | class={props.compact | 27 | class={props.compact |
| 28 | - ? "inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border/80 bg-muted/45 text-foreground outline-hidden transition-colors hover:border-primary/30 hover:bg-primary/8 hover:text-primary-text focus-visible:ring-2 focus-visible:ring-ring data-expanded:border-primary/30 data-expanded:bg-primary/10 data-expanded:text-primary-text" | 28 | + ? "inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg border border-border/80 bg-muted/45 text-foreground outline-hidden transition-colors hover:border-primary/30 hover:bg-primary/8 hover:text-primary-text focus-visible:ring-2 focus-visible:ring-ring data-expanded:border-primary/30 data-expanded:bg-primary/10 data-expanded:text-primary-text" |
| 29 | - : "inline-flex h-8 min-w-[78px] items-center justify-center gap-1.5 rounded-lg border border-border/80 bg-muted/45 px-2 text-xs font-semibold text-foreground outline-hidden transition-colors hover:border-primary/30 hover:bg-primary/8 hover:text-primary-text focus-visible:ring-2 focus-visible:ring-ring data-expanded:border-primary/30 data-expanded:bg-primary/10 data-expanded:text-primary-text"} | 29 | + : "inline-flex h-8 min-w-[78px] cursor-pointer items-center justify-center gap-1.5 rounded-lg border border-border/80 bg-muted/45 px-2 text-xs font-semibold text-foreground outline-hidden transition-colors hover:border-primary/30 hover:bg-primary/8 hover:text-primary-text focus-visible:ring-2 focus-visible:ring-ring data-expanded:border-primary/30 data-expanded:bg-primary/10 data-expanded:text-primary-text"} |
| 30 | aria-label={props.label} | 30 | aria-label={props.label} |
| 31 | title={props.label} | 31 | title={props.label} |
| 32 | > | 32 | > |
src/components/ui/tabs.tsxmodified+1 -1
| @@ -30,7 +30,7 @@ export function TabsTrigger<T extends ValidComponent = "button">( | |||
| 30 | return ( | 30 | return ( |
| 31 | <TabsPrimitive.Trigger | 31 | <TabsPrimitive.Trigger |
| 32 | class={cn( | 32 | class={cn( |
| 33 | - "group inline-flex h-8 shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent px-3 text-sm font-medium text-muted-foreground transition-[background-color,border-color,box-shadow,color] duration-200 hover:bg-muted/70 hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-selected:border-border data-selected:bg-surface-base data-selected:text-foreground data-selected:shadow-xs", | 33 | + "group inline-flex h-8 shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent px-3 text-sm font-medium text-muted-foreground transition-[background-color,border-color,box-shadow,color] duration-200 hover:bg-muted/70 hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-selected:border-border data-selected:bg-surface-base data-selected:text-foreground data-selected:shadow-xs", |
| 34 | local.class, | 34 | local.class, |
| 35 | )} | 35 | )} |
| 36 | {...rest} | 36 | {...rest} |
src/i18n/messages.tsmodified+95 -2
| @@ -619,6 +619,19 @@ export type MessageKey = | |||
| 619 | | "common.deleted" | 619 | | "common.deleted" |
| 620 | | "common.saved" | 620 | | "common.saved" |
| 621 | | "common.loadAll" | 621 | | "common.loadAll" |
| 622 | + | "insights.readFailed" | ||
| 623 | + | "insights.studyStints" | ||
| 624 | + | "insights.filter.all" | ||
| 625 | + | "insights.filter.attention" | ||
| 626 | + | "insights.filter.noAnalysis" | ||
| 627 | + | "insights.overview.analysed" | ||
| 628 | + | "insights.overview.needAttention" | ||
| 629 | + | "insights.overview.marks" | ||
| 630 | + | "insights.overview.attendance" | ||
| 631 | + | "insights.overview.reading" | ||
| 632 | + | "insights.overview.ofTotal" | ||
| 633 | + | "insights.overview.noData" | ||
| 634 | + | "insights.notFound" | ||
| 622 | | "auth.demoLogin" | 635 | | "auth.demoLogin" |
| 623 | | "setup.title" | 636 | | "setup.title" |
| 624 | | "setup.progress" | 637 | | "setup.progress" |
| @@ -994,6 +1007,7 @@ export type MessageKey = | |||
| 994 | | "insights.noSummary" | 1007 | | "insights.noSummary" |
| 995 | | "insights.noSummaryHint" | 1008 | | "insights.noSummaryHint" |
| 996 | | "insights.computedAt" | 1009 | | "insights.computedAt" |
| 1010 | + | "insights.confidence" | ||
| 997 | | "insights.retainUntil" | 1011 | | "insights.retainUntil" |
| 998 | | "insights.sectionNotComputed" | 1012 | | "insights.sectionNotComputed" |
| 999 | | "insights.noEvidence" | 1013 | | "insights.noEvidence" |
| @@ -1016,6 +1030,23 @@ export type MessageKey = | |||
| 1016 | | "insights.confidence.none" | 1030 | | "insights.confidence.none" |
| 1017 | | "insights.confidence.exploratory" | 1031 | | "insights.confidence.exploratory" |
| 1018 | | "insights.confidence.stable" | 1032 | | "insights.confidence.stable" |
| 1033 | + | "insights.analysis.overview" | ||
| 1034 | + | "insights.analysis.visual" | ||
| 1035 | + | "insights.analysis.rate" | ||
| 1036 | + | "insights.analysis.present" | ||
| 1037 | + | "insights.analysis.absent" | ||
| 1038 | + | "insights.analysis.late" | ||
| 1039 | + | "insights.analysis.excused" | ||
| 1040 | + | "insights.analysis.average" | ||
| 1041 | + | "insights.analysis.courses" | ||
| 1042 | + | "insights.analysis.bestMark" | ||
| 1043 | + | "insights.analysis.focusHours" | ||
| 1044 | + | "insights.analysis.activeDays" | ||
| 1045 | + | "insights.analysis.regularity" | ||
| 1046 | + | "insights.analysis.sessions" | ||
| 1047 | + | "insights.analysis.submittedRate" | ||
| 1048 | + | "insights.analysis.submitted" | ||
| 1049 | + | "insights.analysis.missing" | ||
| 1019 | | "insights.runs" | 1050 | | "insights.runs" |
| 1020 | | "insights.runsSubtitle" | 1051 | | "insights.runsSubtitle" |
| 1021 | | "insights.runDay" | 1052 | | "insights.runDay" |
| @@ -2809,6 +2840,19 @@ const en: Dict = { | |||
| 2809 | "common.deleted": "Deleted.", | 2840 | "common.deleted": "Deleted.", |
| 2810 | "common.saved": "Saved successfully.", | 2841 | "common.saved": "Saved successfully.", |
| 2811 | "common.loadAll": "Load all", | 2842 | "common.loadAll": "Load all", |
| 2843 | + "insights.readFailed": "Could not read", | ||
| 2844 | + "insights.studyStints": "Focus", | ||
| 2845 | + "insights.filter.all": "All", | ||
| 2846 | + "insights.filter.attention": "Needs attention", | ||
| 2847 | + "insights.filter.noAnalysis": "No analysis yet", | ||
| 2848 | + "insights.overview.analysed": "Analysed", | ||
| 2849 | + "insights.overview.needAttention": "Need attention", | ||
| 2850 | + "insights.overview.marks": "Average mark", | ||
| 2851 | + "insights.overview.attendance": "Attendance", | ||
| 2852 | + "insights.overview.reading": "Reading {loaded} of {total} students…", | ||
| 2853 | + "insights.overview.ofTotal": "of {total}", | ||
| 2854 | + "insights.overview.noData": "No data yet", | ||
| 2855 | + "insights.notFound": "This student is not in your list.", | ||
| 2812 | "auth.demoLogin": "Sign in with the demo account ({username})", | 2856 | "auth.demoLogin": "Sign in with the demo account ({username})", |
| 2813 | "setup.title": "School setup", | 2857 | "setup.title": "School setup", |
| 2814 | "setup.progress": "{done} of {total} done", | 2858 | "setup.progress": "{done} of {total} done", |
| @@ -3183,7 +3227,8 @@ const en: Dict = { | |||
| 3183 | "insights.summary": "Summary", | 3227 | "insights.summary": "Summary", |
| 3184 | "insights.noSummary": "No analysis yet", | 3228 | "insights.noSummary": "No analysis yet", |
| 3185 | "insights.noSummaryHint": "Queue a computation to create the first analysis.", | 3229 | "insights.noSummaryHint": "Queue a computation to create the first analysis.", |
| 3186 | - "insights.computedAt": "Computed at", | 3230 | + "insights.computedAt": "Date", |
| 3231 | + "insights.confidence": "Confidence", | ||
| 3187 | "insights.retainUntil": "Retained until", | 3232 | "insights.retainUntil": "Retained until", |
| 3188 | "insights.sectionNotComputed": "This section was not computed.", | 3233 | "insights.sectionNotComputed": "This section was not computed.", |
| 3189 | "insights.noEvidence": "No supporting data.", | 3234 | "insights.noEvidence": "No supporting data.", |
| @@ -3206,6 +3251,23 @@ const en: Dict = { | |||
| 3206 | "insights.confidence.none": "Insufficient data", | 3251 | "insights.confidence.none": "Insufficient data", |
| 3207 | "insights.confidence.exploratory": "Exploratory", | 3252 | "insights.confidence.exploratory": "Exploratory", |
| 3208 | "insights.confidence.stable": "Stable", | 3253 | "insights.confidence.stable": "Stable", |
| 3254 | + "insights.analysis.overview": "Overview", | ||
| 3255 | + "insights.analysis.visual": "Visual analysis", | ||
| 3256 | + "insights.analysis.rate": "Rate", | ||
| 3257 | + "insights.analysis.present": "Present", | ||
| 3258 | + "insights.analysis.absent": "Absent", | ||
| 3259 | + "insights.analysis.late": "Late", | ||
| 3260 | + "insights.analysis.excused": "Excused", | ||
| 3261 | + "insights.analysis.average": "Average", | ||
| 3262 | + "insights.analysis.courses": "Courses", | ||
| 3263 | + "insights.analysis.bestMark": "Highest average", | ||
| 3264 | + "insights.analysis.focusHours": "Focus hours", | ||
| 3265 | + "insights.analysis.activeDays": "Active days", | ||
| 3266 | + "insights.analysis.regularity": "Regularity", | ||
| 3267 | + "insights.analysis.sessions": "Sessions", | ||
| 3268 | + "insights.analysis.submittedRate": "Submission rate", | ||
| 3269 | + "insights.analysis.submitted": "Submitted", | ||
| 3270 | + "insights.analysis.missing": "Missing", | ||
| 3209 | "insights.runs": "Analysis runs", | 3271 | "insights.runs": "Analysis runs", |
| 3210 | "insights.runsSubtitle": "Nightly and manually queued school analyses.", | 3272 | "insights.runsSubtitle": "Nightly and manually queued school analyses.", |
| 3211 | "insights.runDay": "Run day", | 3273 | "insights.runDay": "Run day", |
| @@ -5001,6 +5063,19 @@ const tr: Dict = { | |||
| 5001 | "common.deleted": "Silindi.", | 5063 | "common.deleted": "Silindi.", |
| 5002 | "common.saved": "Başarıyla kaydedildi.", | 5064 | "common.saved": "Başarıyla kaydedildi.", |
| 5003 | "common.loadAll": "Tümünü yükle", | 5065 | "common.loadAll": "Tümünü yükle", |
| 5066 | + "insights.readFailed": "Okunamadı", | ||
| 5067 | + "insights.studyStints": "Odak", | ||
| 5068 | + "insights.filter.all": "Tümü", | ||
| 5069 | + "insights.filter.attention": "Dikkat gerekenler", | ||
| 5070 | + "insights.filter.noAnalysis": "Analizi olmayanlar", | ||
| 5071 | + "insights.overview.analysed": "Analiz edilen", | ||
| 5072 | + "insights.overview.needAttention": "Dikkat gereken", | ||
| 5073 | + "insights.overview.marks": "Not ortalaması", | ||
| 5074 | + "insights.overview.attendance": "Devam oranı", | ||
| 5075 | + "insights.overview.reading": "{total} öğrenciden {loaded} okundu…", | ||
| 5076 | + "insights.overview.ofTotal": "{total} öğrenciden", | ||
| 5077 | + "insights.overview.noData": "Henüz veri yok", | ||
| 5078 | + "insights.notFound": "Bu öğrenci listende yok.", | ||
| 5004 | "auth.demoLogin": "Demo hesabıyla gir ({username})", | 5079 | "auth.demoLogin": "Demo hesabıyla gir ({username})", |
| 5005 | "setup.title": "Okul kurulumu", | 5080 | "setup.title": "Okul kurulumu", |
| 5006 | "setup.progress": "{total} adımdan {done} tamam", | 5081 | "setup.progress": "{total} adımdan {done} tamam", |
| @@ -5375,7 +5450,8 @@ const tr: Dict = { | |||
| 5375 | "insights.summary": "Özet", | 5450 | "insights.summary": "Özet", |
| 5376 | "insights.noSummary": "Henüz analiz yok", | 5451 | "insights.noSummary": "Henüz analiz yok", |
| 5377 | "insights.noSummaryHint": "İlk analizi oluşturmak için hesaplamayı sıraya alın.", | 5452 | "insights.noSummaryHint": "İlk analizi oluşturmak için hesaplamayı sıraya alın.", |
| 5378 | - "insights.computedAt": "Hesaplanma", | 5453 | + "insights.computedAt": "Tarih", |
| 5454 | + "insights.confidence": "Güven", | ||
| 5379 | "insights.retainUntil": "Saklanma sonu", | 5455 | "insights.retainUntil": "Saklanma sonu", |
| 5380 | "insights.sectionNotComputed": "Bu bölüm hesaplanmadı.", | 5456 | "insights.sectionNotComputed": "Bu bölüm hesaplanmadı.", |
| 5381 | "insights.noEvidence": "Destekleyici veri yok.", | 5457 | "insights.noEvidence": "Destekleyici veri yok.", |
| @@ -5398,6 +5474,23 @@ const tr: Dict = { | |||
| 5398 | "insights.confidence.none": "Yetersiz veri", | 5474 | "insights.confidence.none": "Yetersiz veri", |
| 5399 | "insights.confidence.exploratory": "Keşifsel", | 5475 | "insights.confidence.exploratory": "Keşifsel", |
| 5400 | "insights.confidence.stable": "Kararlı", | 5476 | "insights.confidence.stable": "Kararlı", |
| 5477 | + "insights.analysis.overview": "Genel bakış", | ||
| 5478 | + "insights.analysis.visual": "Grafiksel analiz", | ||
| 5479 | + "insights.analysis.rate": "Oran", | ||
| 5480 | + "insights.analysis.present": "Var", | ||
| 5481 | + "insights.analysis.absent": "Yok", | ||
| 5482 | + "insights.analysis.late": "Geç", | ||
| 5483 | + "insights.analysis.excused": "İzinli", | ||
| 5484 | + "insights.analysis.average": "Ortalama", | ||
| 5485 | + "insights.analysis.courses": "Ders", | ||
| 5486 | + "insights.analysis.bestMark": "En yüksek ortalama", | ||
| 5487 | + "insights.analysis.focusHours": "Odak saati", | ||
| 5488 | + "insights.analysis.activeDays": "Aktif gün", | ||
| 5489 | + "insights.analysis.regularity": "Düzenlilik", | ||
| 5490 | + "insights.analysis.sessions": "Oturum", | ||
| 5491 | + "insights.analysis.submittedRate": "Teslim oranı", | ||
| 5492 | + "insights.analysis.submitted": "Teslim", | ||
| 5493 | + "insights.analysis.missing": "Eksik", | ||
| 5401 | "insights.runs": "Analiz çalıştırmaları", | 5494 | "insights.runs": "Analiz çalıştırmaları", |
| 5402 | "insights.runsSubtitle": "Gece çalışan ve elle sıraya alınan okul analizleri.", | 5495 | "insights.runsSubtitle": "Gece çalışan ve elle sıraya alınan okul analizleri.", |
| 5403 | "insights.runDay": "Çalışma günü", | 5496 | "insights.runDay": "Çalışma günü", |
src/index.cssmodified+17 -0
| @@ -238,6 +238,23 @@ | |||
| 238 | padding-bottom: 0; | 238 | padding-bottom: 0; |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | +/* Insight ledgers are intentionally spreadsheet-like: centered metrics and | ||
| 242 | + * explicit cell rules make a wide scan easier than a card-style table. */ | ||
| 243 | +.insight-grid-table th, | ||
| 244 | +.insight-grid-table td { | ||
| 245 | + border-right: 1px solid hsl(var(--border)); | ||
| 246 | + text-align: center; | ||
| 247 | +} | ||
| 248 | + | ||
| 249 | +.insight-grid-table th:last-child, | ||
| 250 | +.insight-grid-table td:last-child { | ||
| 251 | + border-right: 0; | ||
| 252 | +} | ||
| 253 | + | ||
| 254 | +.insight-grid-table tbody tr:nth-child(even) { | ||
| 255 | + background-color: color-mix(in oklab, hsl(var(--muted)) 18%, hsl(var(--card))); | ||
| 256 | +} | ||
| 257 | + | ||
| 241 | @utility detail-breadcrumb { | 258 | @utility detail-breadcrumb { |
| 242 | @apply flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground font-medium; | 259 | @apply flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground font-medium; |
| 243 | 260 | ||
src/lib/insight-students.test.tsadded+43 -0
| @@ -0,0 +1,43 @@ | |||
| 1 | +import type { PersonRef, StudentInsight } from "@/api/client"; | ||
| 2 | +import { insightOverview, loadStudentSignals } from "./insight-students"; | ||
| 3 | +import { toStudentSignal } from "./insight-run-report"; | ||
| 4 | + | ||
| 5 | +const person = (id: string): PersonRef => ({ id, username: id, display_name: id.toUpperCase() }); | ||
| 6 | +const insight = (id: string, average: number, rate: number, attention: number): StudentInsight => ({ | ||
| 7 | + user_id: id, | ||
| 8 | + summary: { | ||
| 9 | + confidence: "high", | ||
| 10 | + computed_at: 1, | ||
| 11 | + marks: { courses: { c1: { n_marks: 2, average } } }, | ||
| 12 | + attendance: { overall: { rate, n_obs: 10 } }, | ||
| 13 | + } as never, | ||
| 14 | + attention: Array.from({ length: attention }, () => ({}) as never), | ||
| 15 | + cards: [], | ||
| 16 | + segments: [], | ||
| 17 | +}); | ||
| 18 | + | ||
| 19 | +it("reads every student, turning a failed read into that row's error", async () => { | ||
| 20 | + const rows: string[] = []; | ||
| 21 | + await loadStudentSignals([person("a"), person("b")], (row) => rows.push(`${row.id}:${row.state}`), async (id) => { | ||
| 22 | + if (id === "b") throw new Error("boom"); | ||
| 23 | + return insight(id, 80, 0.9, 0); | ||
| 24 | + }); | ||
| 25 | + expect(rows.sort()).toEqual(["a:ok", "b:error"]); | ||
| 26 | +}); | ||
| 27 | + | ||
| 28 | +it("summarises only what the summaries measured", () => { | ||
| 29 | + const signals = [ | ||
| 30 | + toStudentSignal({ id: "a", name: "A" }, insight("a", 80, 0.9, 2), null), | ||
| 31 | + toStudentSignal({ id: "b", name: "B" }, insight("b", 60, 0.7, 0), null), | ||
| 32 | + toStudentSignal({ id: "c", name: "C" }, { user_id: "c", summary: null, attention: [], cards: [], segments: [] }, null), | ||
| 33 | + toStudentSignal({ id: "d", name: "D" }, null, null), | ||
| 34 | + ]; | ||
| 35 | + expect(insightOverview(signals, 5)).toEqual({ | ||
| 36 | + total: 5, | ||
| 37 | + loaded: 3, | ||
| 38 | + analysed: 2, | ||
| 39 | + needAttention: 1, | ||
| 40 | + marksAverage: 70, | ||
| 41 | + attendanceRate: 0.8, | ||
| 42 | + }); | ||
| 43 | +}); | ||
src/lib/insight-students.tsadded+72 -0
| @@ -0,0 +1,72 @@ | |||
| 1 | +import { formatApiError, type PersonRef, type Role, type StudentInsight } from "@/api/client"; | ||
| 2 | +import { getInsightByUserId } from "@/api/insights"; | ||
| 3 | +import { getMyStudents } from "@/api/parents"; | ||
| 4 | +import { getUserSearch } from "@/api/users"; | ||
| 5 | +import { personLabel } from "@/lib/person"; | ||
| 6 | +import { toStudentSignal, type StudentSignal } from "@/lib/insight-run-report"; | ||
| 7 | + | ||
| 8 | +/** Students the viewer may analyse: a parent's linked children, or the school's students for staff. */ | ||
| 9 | +export async function loadInsightStudents(role: Role): Promise<PersonRef[]> { | ||
| 10 | + return role === "parent" | ||
| 11 | + ? (await getMyStudents({ limit: 200 })).items | ||
| 12 | + : (await getUserSearch("", undefined, "student", { limit: 200 })).items; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +/** Parallel insight reads; there is no bulk endpoint. */ | ||
| 16 | +const READ_CONCURRENCY = 6; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Read every student's insight a few at a time, reporting each row as it | ||
| 20 | + * lands so the table fills progressively instead of waiting on the slowest. | ||
| 21 | + * A failed read becomes that row's `error` state, never a made-up value. | ||
| 22 | + */ | ||
| 23 | +export async function loadStudentSignals( | ||
| 24 | + students: PersonRef[], | ||
| 25 | + onRow: (signal: StudentSignal) => void, | ||
| 26 | + read: (userId: string) => Promise<StudentInsight> = getInsightByUserId, | ||
| 27 | +): Promise<void> { | ||
| 28 | + const queue = [...students]; | ||
| 29 | + const worker = async () => { | ||
| 30 | + for (let person = queue.shift(); person; person = queue.shift()) { | ||
| 31 | + const identity = { id: person.id, name: personLabel(person) }; | ||
| 32 | + try { | ||
| 33 | + onRow(toStudentSignal(identity, await read(person.id), null)); | ||
| 34 | + } catch (error) { | ||
| 35 | + onRow(toStudentSignal(identity, null, formatApiError(error))); | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + }; | ||
| 39 | + await Promise.all(Array.from({ length: READ_CONCURRENCY }, worker)); | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +export type InsightOverview = { | ||
| 43 | + total: number; | ||
| 44 | + /** Rows read so far (any state but `not_loaded`). */ | ||
| 45 | + loaded: number; | ||
| 46 | + /** Students with a computed summary. */ | ||
| 47 | + analysed: number; | ||
| 48 | + /** Students with at least one attention item. */ | ||
| 49 | + needAttention: number; | ||
| 50 | + /** Mean of the per-student mark averages that exist; null when none do. */ | ||
| 51 | + marksAverage: number | null; | ||
| 52 | + /** Mean of the observed attendance rates (0..1); null when none observed. */ | ||
| 53 | + attendanceRate: number | null; | ||
| 54 | +}; | ||
| 55 | + | ||
| 56 | +/** The school picture over the rows read so far — only fields a summary actually measured. */ | ||
| 57 | +export function insightOverview(signals: StudentSignal[], total: number): InsightOverview { | ||
| 58 | + const analysed = signals.filter((signal) => signal.state === "ok"); | ||
| 59 | + const marks = analysed.map((signal) => signal.marks.average).filter((value): value is number => value != null); | ||
| 60 | + const attendance = analysed | ||
| 61 | + .filter((signal) => signal.attendance.observed > 0 && signal.attendance.rate != null) | ||
| 62 | + .map((signal) => signal.attendance.rate as number); | ||
| 63 | + const mean = (values: number[]) => (values.length ? values.reduce((sum, value) => sum + value, 0) / values.length : null); | ||
| 64 | + return { | ||
| 65 | + total, | ||
| 66 | + loaded: signals.filter((signal) => signal.state !== "not_loaded").length, | ||
| 67 | + analysed: analysed.length, | ||
| 68 | + needAttention: signals.filter((signal) => signal.attention > 0).length, | ||
| 69 | + marksAverage: mean(marks), | ||
| 70 | + attendanceRate: mean(attendance), | ||
| 71 | + }; | ||
| 72 | +} | ||
src/pages/ai-celebi-page.tsxdeleted+0 -10
| @@ -1,10 +0,0 @@ | |||
| 1 | -import { CelebiLauncher } from "@/components/ai/celebi-launcher"; | ||
| 2 | -import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 3 | - | ||
| 4 | -export default function AiCelebiPage() { | ||
| 5 | - return ( | ||
| 6 | - <RouteGuard minRole="student"> | ||
| 7 | - <CelebiLauncher /> | ||
| 8 | - </RouteGuard> | ||
| 9 | - ); | ||
| 10 | -} | ||
src/pages/ai-insight-student-page.tsxadded+173 -0
| @@ -0,0 +1,173 @@ | |||
| 1 | +import { Show, createMemo, createSignal } from "solid-js"; | ||
| 2 | +import { useParams } from "@tanstack/solid-router"; | ||
| 3 | +import { createResource } from "@/lib/create-resource"; | ||
| 4 | +import { formatApiError, type InsightConfidence } from "@/api/client"; | ||
| 5 | +import { getInsightByUserId, postInsightComputeByUserId } from "@/api/insights"; | ||
| 6 | +import { InsightStudentAnalysisTabs } from "@/components/insights/insight-student-analysis-tabs"; | ||
| 7 | +import { Breadcrumbs } from "@/components/layout/breadcrumbs"; | ||
| 8 | +import { RouteGuard } from "@/components/layout/route-guard"; | ||
| 9 | +import { Alert } from "@/components/ui/alert"; | ||
| 10 | +import { Button } from "@/components/ui/button"; | ||
| 11 | +import { ErrorAlert } from "@/components/ui/error-alert"; | ||
| 12 | +import { Badge } from "@/components/ui/badge"; | ||
| 13 | +import { IconAlert, IconChart, IconDownload, IconSparkles } from "@/components/ui/icons"; | ||
| 14 | +import { PageSpinner } from "@/components/ui/page-spinner"; | ||
| 15 | +import { createFlash } from "@/lib/flash"; | ||
| 16 | +import { loadInsightStudents } from "@/lib/insight-students"; | ||
| 17 | +import { personLabel } from "@/lib/person"; | ||
| 18 | +import { hasMinRole } from "@/lib/roles"; | ||
| 19 | +import { useAuth } from "@/stores/auth-context"; | ||
| 20 | +import { usePreferences } from "@/stores/preferences-context"; | ||
| 21 | + | ||
| 22 | +function confidenceVariant(confidence: InsightConfidence) { | ||
| 23 | + if (confidence === "stable") return "success" as const; | ||
| 24 | + if (confidence === "exploratory") return "warning" as const; | ||
| 25 | + return "secondary" as const; | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +export default function AiInsightStudentPage() { | ||
| 29 | + return ( | ||
| 30 | + <RouteGuard> | ||
| 31 | + <AiInsightStudentContent /> | ||
| 32 | + </RouteGuard> | ||
| 33 | + ); | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * One student's analysis as a page of its own — it used to open in a side | ||
| 38 | + * panel over the list, too narrow for the module sections, attention items | ||
| 39 | + * and recommendation cards it carries. The name comes from the same student | ||
| 40 | + * list the board reads (a parent's children, the school's students for | ||
| 41 | + * staff): `/users/{id}` is admin-only. | ||
| 42 | + */ | ||
| 43 | +function AiInsightStudentContent() { | ||
| 44 | + const auth = useAuth(); | ||
| 45 | + const prefs = usePreferences(); | ||
| 46 | + const t = (key: string, vars?: Record<string, string | number>) => prefs.t(key as never, vars); | ||
| 47 | + const params = useParams({ from: "/ai/insights/$userId" }); | ||
| 48 | + const userId = () => params().userId; | ||
| 49 | + const role = () => auth.user()?.role; | ||
| 50 | + const canRecompute = () => hasMinRole(role(), "teacher"); | ||
| 51 | + const [queuing, setQueuing] = createSignal(false); | ||
| 52 | + const [actionError, setActionError] = createSignal(""); | ||
| 53 | + const [flash, setFlash] = createFlash(); | ||
| 54 | + | ||
| 55 | + const [students] = createResource(() => role() ?? null, (viewerRole) => loadInsightStudents(viewerRole).catch(() => [])); | ||
| 56 | + const person = createMemo(() => (students() ?? []).find((student) => student.id === userId()) ?? null); | ||
| 57 | + const [insight, { refetch }] = createResource(userId, (id) => getInsightByUserId(id)); | ||
| 58 | + const studentName = () => person() ? personLabel(person()!) : userId(); | ||
| 59 | + const initials = () => studentName() | ||
| 60 | + .split(/\s+/) | ||
| 61 | + .filter(Boolean) | ||
| 62 | + .slice(0, 2) | ||
| 63 | + .map((part) => part[0]?.toUpperCase()) | ||
| 64 | + .join("") || "?"; | ||
| 65 | + const confidenceLabel = (confidence: InsightConfidence) => | ||
| 66 | + confidence === "none" || confidence === "exploratory" || confidence === "stable" | ||
| 67 | + ? t(`insights.confidence.${confidence}`) | ||
| 68 | + : confidence; | ||
| 69 | + const numericDate = (value: number | null | undefined) => { | ||
| 70 | + if (value == null) return "—"; | ||
| 71 | + return new Intl.DateTimeFormat(prefs.locale() === "tr" ? "tr-TR" : "en-US", { | ||
| 72 | + day: "2-digit", | ||
| 73 | + month: "2-digit", | ||
| 74 | + year: "numeric", | ||
| 75 | + }).format(new Date(value)); | ||
| 76 | + }; | ||
| 77 | + | ||
| 78 | + const recompute = async () => { | ||
| 79 | + const current = person(); | ||
| 80 | + if (queuing()) return; | ||
| 81 | + setQueuing(true); | ||
| 82 | + setActionError(""); | ||
| 83 | + try { | ||
| 84 | + await postInsightComputeByUserId(userId()); | ||
| 85 | + setFlash(t("insights.recomputeQueued", { student: current ? personLabel(current) : userId() })); | ||
| 86 | + } catch (error) { | ||
| 87 | + setActionError(formatApiError(error)); | ||
| 88 | + } finally { | ||
| 89 | + setQueuing(false); | ||
| 90 | + } | ||
| 91 | + }; | ||
| 92 | + | ||
| 93 | + return ( | ||
| 94 | + <div class="mx-auto w-full max-w-[1240px] space-y-5"> | ||
| 95 | + <div class="space-y-2"> | ||
| 96 | + <Breadcrumbs items={[{ label: t("insights.title"), to: "/ai/insights" }, { label: studentName() }]} /> | ||
| 97 | + </div> | ||
| 98 | + <Show when={flash()}> | ||
| 99 | + <Alert variant="success">{flash()}</Alert> | ||
| 100 | + </Show> | ||
| 101 | + <Show when={actionError()}> | ||
| 102 | + <Alert variant="destructive">{actionError()}</Alert> | ||
| 103 | + </Show> | ||
| 104 | + <Show when={students() && !person()}> | ||
| 105 | + <Alert variant="warning">{t("insights.notFound")}</Alert> | ||
| 106 | + </Show> | ||
| 107 | + <Show when={insight.error}> | ||
| 108 | + <ErrorAlert message={formatApiError(insight.error)} onRetry={() => void refetch()} /> | ||
| 109 | + </Show> | ||
| 110 | + <Show when={!insight.error} fallback={null}> | ||
| 111 | + <Show when={insight()} fallback={<PageSpinner />}> | ||
| 112 | + {(value) => ( | ||
| 113 | + <div class="space-y-5"> | ||
| 114 | + <section class="overflow-hidden rounded-2xl border border-border-line bg-surface-base shadow-xs"> | ||
| 115 | + <div class="flex flex-col gap-4 p-5 sm:flex-row sm:items-center sm:justify-between sm:p-6"> | ||
| 116 | + <div class="flex min-w-0 items-center gap-4"> | ||
| 117 | + <div class="flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-primary text-lg font-semibold text-primary-foreground shadow-xs"> | ||
| 118 | + {initials()} | ||
| 119 | + </div> | ||
| 120 | + <div class="min-w-0"> | ||
| 121 | + <p class="text-xs font-semibold uppercase tracking-[0.14em] text-primary-text">{t("insights.title")}</p> | ||
| 122 | + <h1 class="mt-1 truncate text-2xl font-semibold tracking-tight text-text-strong">{studentName()}</h1> | ||
| 123 | + <p class="mt-1 text-sm text-muted-foreground">{t("insights.studentAnalysis")}</p> | ||
| 124 | + </div> | ||
| 125 | + </div> | ||
| 126 | + <div class="flex flex-wrap items-center gap-2"> | ||
| 127 | + <Button variant="outline" size="sm" class="rounded-lg" disabled title={t("comingSoon.title")}> | ||
| 128 | + <IconDownload class="h-4 w-4" /> | ||
| 129 | + {t("common.export")} | ||
| 130 | + </Button> | ||
| 131 | + <Show when={canRecompute()}> | ||
| 132 | + <Button size="sm" class="rounded-lg" disabled={queuing()} onClick={() => void recompute()}> | ||
| 133 | + <IconSparkles class="h-4 w-4" /> | ||
| 134 | + {queuing() ? t("insights.recomputing") : t("insights.recompute")} | ||
| 135 | + </Button> | ||
| 136 | + </Show> | ||
| 137 | + </div> | ||
| 138 | + </div> | ||
| 139 | + <div class="grid border-t border-border-line sm:grid-cols-4"> | ||
| 140 | + <div class="border-border-line px-5 py-3 sm:border-r"> | ||
| 141 | + <p class="text-xs text-muted-foreground">{t("insights.computedAt")}</p> | ||
| 142 | + <p class="mono mt-1 text-sm font-semibold text-text-strong">{numericDate(value().summary?.computed_at)}</p> | ||
| 143 | + </div> | ||
| 144 | + <div class="border-border-line px-5 py-3 sm:border-r"> | ||
| 145 | + <p class="text-xs text-muted-foreground">{t("insights.confidence")}</p> | ||
| 146 | + <Show | ||
| 147 | + when={value().summary} | ||
| 148 | + fallback={<span class="mt-1 block text-sm text-muted-foreground">—</span>} | ||
| 149 | + > | ||
| 150 | + {(summary) => <Badge variant={confidenceVariant(summary().confidence)} class="mt-1 rounded-full">{confidenceLabel(summary().confidence)}</Badge>} | ||
| 151 | + </Show> | ||
| 152 | + </div> | ||
| 153 | + <div class="border-border-line px-5 py-3 sm:border-r"> | ||
| 154 | + <p class="flex items-center gap-1.5 text-xs text-muted-foreground"><IconAlert class="h-3.5 w-3.5" />{t("insights.attention")}</p> | ||
| 155 | + <p class="mono mt-1 text-lg font-semibold text-text-strong">{value().attention.length}</p> | ||
| 156 | + </div> | ||
| 157 | + <div class="px-5 py-3"> | ||
| 158 | + <p class="flex items-center gap-1.5 text-xs text-muted-foreground"><IconChart class="h-3.5 w-3.5" />{t("insights.recommendations")}</p> | ||
| 159 | + <p class="mono mt-1 text-lg font-semibold text-text-strong">{value().cards.length}</p> | ||
| 160 | + </div> | ||
| 161 | + </div> | ||
| 162 | + </section> | ||
| 163 | + | ||
| 164 | + <section class="data-shell p-5"> | ||
| 165 | + <InsightStudentAnalysisTabs insight={value()} /> | ||
| 166 | + </section> | ||
| 167 | + </div> | ||
| 168 | + )} | ||
| 169 | + </Show> | ||
| 170 | + </Show> | ||
| 171 | + </div> | ||
| 172 | + ); | ||
| 173 | +} | ||
src/routes/router.tsxmodified+6 -5
| @@ -74,7 +74,7 @@ const WhiteboardPage = lazyRoute(() => import("@/pages/whiteboard-page")); | |||
| 74 | const AiStudioPage = lazyRoute(() => import("@/pages/ai-studio-page")); | 74 | const AiStudioPage = lazyRoute(() => import("@/pages/ai-studio-page")); |
| 75 | const AiStudyPage = lazyRoute(() => import("@/pages/ai-study-page")); | 75 | const AiStudyPage = lazyRoute(() => import("@/pages/ai-study-page")); |
| 76 | const AiInsightsPage = lazyRoute(() => import("@/pages/ai-insights-page")); | 76 | const AiInsightsPage = lazyRoute(() => import("@/pages/ai-insights-page")); |
| 77 | -const AiCelebiPage = lazyRoute(() => import("@/pages/ai-celebi-page")); | 77 | +const AiInsightStudentPage = lazyRoute(() => import("@/pages/ai-insight-student-page")); |
| 78 | const ComingSoonPage = lazyRoute(() => import("@/pages/coming-soon-page")); | 78 | const ComingSoonPage = lazyRoute(() => import("@/pages/coming-soon-page")); |
| 79 | const StudentsRosterPage = lazyRoute(() => import("@/pages/students-roster-page")); | 79 | const StudentsRosterPage = lazyRoute(() => import("@/pages/students-roster-page")); |
| 80 | const TeachersRosterPage = lazyRoute(() => import("@/pages/teachers-roster-page")); | 80 | const TeachersRosterPage = lazyRoute(() => import("@/pages/teachers-roster-page")); |
| @@ -481,10 +481,11 @@ const aiInsightsRoute = createRoute({ | |||
| 481 | component: AiInsightsPage, | 481 | component: AiInsightsPage, |
| 482 | }); | 482 | }); |
| 483 | 483 | ||
| 484 | -const aiCelebiRoute = createRoute({ | 484 | +// One student's analysis as a full page (it used to be a side panel). |
| 485 | +const aiInsightStudentRoute = createRoute({ | ||
| 485 | getParentRoute: () => rootRoute, | 486 | getParentRoute: () => rootRoute, |
| 486 | - path: "/ai/celebi", | 487 | + path: "/ai/insights/$userId", |
| 487 | - component: AiCelebiPage, | 488 | + component: AiInsightStudentPage, |
| 488 | }); | 489 | }); |
| 489 | 490 | ||
| 490 | // The audio workshop had its own route before the hub gathered it. | 491 | // The audio workshop had its own route before the hub gathered it. |
| @@ -614,7 +615,7 @@ const routeTree = rootRoute.addChildren([ | |||
| 614 | aiStudioRoute, | 615 | aiStudioRoute, |
| 615 | aiStudyRoute, | 616 | aiStudyRoute, |
| 616 | aiInsightsRoute, | 617 | aiInsightsRoute, |
| 617 | - aiCelebiRoute, | 618 | + aiInsightStudentRoute, |
| 618 | soundStudioRoute, | 619 | soundStudioRoute, |
| 619 | studentsRosterRoute, | 620 | studentsRosterRoute, |
| 620 | teachersRosterRoute, | 621 | teachersRosterRoute, |