From fbaff64ebfcce7f846e0b5a6b8a3e39e60d92c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 16 Sep 2026 08:33:09 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=94=8E=20name,=20class=20and=20a?= =?UTF-8?q?=20"what=20can=20I=20type=20here"=20line=20on=20every=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - student results carry their class: lib/student-classes resolves a class name per student from GET /classes/user/{id} (teacher+, cached per tab, only for a bounded list), used by the command palette people section and by UserSearchSelect - UserSearchSelect rows are now two lines — display name, then "class · username" for a student picker and username otherwise — instead of the raw account uuid; the picked value reads "Name (username)" - DataTableSearch takes a hint shown under the field while it has focus, threaded through DataTable (filterHint) and DataToolbar (searchHint); every search box in the app names the fields it really matches - the command palette says what it takes while the query is empty, and the user picker says it is a type-to-search field - ui-conventions documents both rules --- .claude/skills/ui-conventions/SKILL.md | 9 +++ src/components/layout/celebi-panel.tsx | 2 +- src/components/layout/command-palette.tsx | 14 ++++- src/components/ui/data-table-search.tsx | 31 +++++++++- src/components/ui/data-table.tsx | 3 + src/components/ui/data-toolbar.tsx | 3 + src/components/users/user-search-select.tsx | 41 +++++++++++-- src/components/users/user-table.tsx | 1 + src/i18n/messages.ts | 54 +++++++++++++++++ src/lib/student-classes.test.tsx | 65 +++++++++++++++++++++ src/lib/student-classes.ts | 58 ++++++++++++++++++ src/pages/classes-page.tsx | 2 +- src/pages/courses-page.tsx | 1 + src/pages/dashboard-page.tsx | 1 + src/pages/events-page.tsx | 1 + src/pages/exams-page.tsx | 1 + src/pages/payments-page.tsx | 1 + src/pages/question-bank-page.tsx | 1 + src/pages/staff-work-page.tsx | 2 +- src/pages/student-attendance-page.tsx | 1 + src/pages/student-marks-page.tsx | 1 + src/pages/student-pomodoro-page.tsx | 1 + src/pages/students-roster-page.tsx | 1 + src/pages/teachers-roster-page.tsx | 1 + src/pages/whiteboards-page.tsx | 2 +- 25 files changed, 284 insertions(+), 14 deletions(-) create mode 100644 src/lib/student-classes.test.tsx create mode 100644 src/lib/student-classes.ts diff --git a/.claude/skills/ui-conventions/SKILL.md b/.claude/skills/ui-conventions/SKILL.md index 036b920..6de0328 100644 --- a/.claude/skills/ui-conventions/SKILL.md +++ b/.claude/skills/ui-conventions/SKILL.md @@ -55,6 +55,15 @@ Active project reference docs (read the relevant one before changing that area): ## Shared pickers & empty states - Dropdowns: `Select` (drop-in for ``, `type="date"` input (use `DatePicker`) or an ad-hoc search `Input` (use `DataTableSearch`). +- Every search box says what it matches: pass `hint` (`DataTableSearch`), + `filterHint` (`DataTable`) or `searchHint` (`DataToolbar`) — a short line + shown under the field while it has focus. The text must name the fields the + filter really reads; never promise a field it does not search. +- `UserSearchSelect` rows are two lines: display name, then `class · username` + for a student picker (`role="student"`) and `username` otherwise — never the + raw account uuid. Class names come from `src/lib/student-classes.ts` + (`GET /classes/user/{id}`, teacher+, cached per tab); only ever call it for a + bounded list of students. - Confirmations and text prompts go through `ConfirmDialog`; never `window.confirm/prompt/alert`. - Empty states: `EmptyState` (full panel, `kind` picks the unDraw scene) or `EmptyInline` (cards/charts). Scenes live in `src/assets/illustrations/` (license + slugs in its README); pixel glyphs come from `PixelIcon` (pixelarticons, MIT). diff --git a/src/components/layout/celebi-panel.tsx b/src/components/layout/celebi-panel.tsx index 7c1a983..652a68d 100644 --- a/src/components/layout/celebi-panel.tsx +++ b/src/components/layout/celebi-panel.tsx @@ -322,7 +322,7 @@ export function CelebiPanel(props: { open: boolean; onOpenChange: (open: boolean keeps writing. */}
- +
{/* The jump control floats over the bottom of the transcript, next to the newest message it leads to, instead of sitting up by search. */} diff --git a/src/components/layout/command-palette.tsx b/src/components/layout/command-palette.tsx index 9c215f2..33dd848 100644 --- a/src/components/layout/command-palette.tsx +++ b/src/components/layout/command-palette.tsx @@ -20,6 +20,7 @@ import { } from "@/components/ui/icons"; import { getUserSearch } from "@/api/users"; import { HOME_ITEM, visibleNavGroups } from "@/components/layout/nav-items"; +import { createStudentClassLabels } from "@/lib/student-classes"; import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { useModules } from "@/stores/modules-context"; @@ -77,6 +78,9 @@ export function CommandPalette(props: CommandPaletteProps) { () => (props.open && role() === "admin" && peopleQuery() ? peopleQuery() : null), (q) => getUserSearch(q, undefined, "student", { limit: 6 }), ); + // Two students called "Ayşe Yılmaz" are only told apart by their class, so + // each visible match is resolved to one (see `student-classes`). + const classLabels = createStudentClassLabels(() => (people.latest?.items ?? []).map((person) => person.id)); const items = createMemo(() => { const list: CommandItem[] = []; @@ -293,7 +297,7 @@ export function CommandPalette(props: CommandPaletteProps) { category: "people", categoryLabel: peopleLabel, title: person.display_name || person.username, - description: person.username, + description: classLabels()[person.id] ? `${classLabels()[person.id]} · ${person.username}` : person.username, icon: IconUsers, onSelect: () => void navigate({ to: "/admin/users/$id", params: { id: person.id } }), })); @@ -435,6 +439,14 @@ export function CommandPalette(props: CommandPaletteProps) {
+ {/* What the field accepts — the palette takes names, pages and + actions, and an empty box says none of that on its own. */} + +

+ {role() === "admin" ? t("search.hint.commandAdmin") : t("search.hint.command")} +

+
+ {/* Command Items List */}
void; placeholder?: string; + /** + * What this particular box actually matches on, in the user's words. Shown + * under the field while it has focus — a placeholder alone never says + * whether a name, a code or a description is the thing to type. Keep it + * honest: it must list what the filter really reads, nothing more. + */ + hint?: string; class?: string; }; -/** Rounded search field: leading icon + conditional clear (X) button. */ +/** Rounded search field: leading icon, conditional clear (X) button, and an + * optional on-focus hint naming the fields it searches. */ export function DataTableSearch(props: DataTableSearchProps) { const t = useT(); + const [focused, setFocused] = createSignal(false); + const hintId = createUniqueId(); return ( -
+
setFocused(true)} + onFocusOut={() => setFocused(false)} + > props.onChange(event.currentTarget.value)} placeholder={props.placeholder ?? t("common.search")} + aria-describedby={props.hint ? hintId : undefined} class={cn("h-8 rounded-lg bg-muted/40 text-[13px] md:text-[13px]", props.value ? "pl-9 pr-8" : "pl-9")} /> @@ -33,6 +48,16 @@ export function DataTableSearch(props: DataTableSearchProps) { + {/* Floated rather than inline: a static line would push every toolbar + that carries a search box taller, on every page. */} + +

+ {props.hint} +

+
); } diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index d105842..2800e0f 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -54,6 +54,8 @@ export type DataTableProps = { filters?: JSX.Element; filterColumn?: string; filterPlaceholder?: string; + /** On-focus hint under the search box naming the fields it matches. */ + filterHint?: string; title?: string; description?: string; actions?: JSX.Element; @@ -274,6 +276,7 @@ export function DataTable(props: DataTableProps diff --git a/src/components/ui/data-toolbar.tsx b/src/components/ui/data-toolbar.tsx index 534fb85..c2cfd38 100644 --- a/src/components/ui/data-toolbar.tsx +++ b/src/components/ui/data-toolbar.tsx @@ -6,6 +6,8 @@ import { cn } from "@/lib/cn"; export function DataToolbar(props: { searchValue?: string; searchPlaceholder?: string; + /** On-focus hint under the search box naming the fields it matches. */ + searchHint?: string; onSearchInput?: (value: string) => void; filters?: JSX.Element; actions?: JSX.Element; @@ -21,6 +23,7 @@ export function DataToolbar(props: { class={cn("sm:max-w-72", props.inline && "min-w-0 flex-1")} value={props.searchValue ?? ""} placeholder={props.searchPlaceholder} + hint={props.searchHint} onChange={(value) => props.onSearchInput?.(value)} /> diff --git a/src/components/users/user-search-select.tsx b/src/components/users/user-search-select.tsx index 89c5a7c..44de377 100644 --- a/src/components/users/user-search-select.tsx +++ b/src/components/users/user-search-select.tsx @@ -1,6 +1,7 @@ import { Show, createEffect, createMemo, createSignal, onCleanup } from "solid-js"; import { getUserSearch } from "@/api/users"; import type { PersonRef, Role } from "@/api/client"; +import type { PersonLike } from "@/lib/person"; import { Combobox, ComboboxContent, @@ -11,7 +12,8 @@ import { ComboboxTrigger, } from "@/components/ui/combobox"; import { Label } from "@/components/ui/label"; -import { personLabelWithId } from "@/lib/person"; +import { personLabel } from "@/lib/person"; +import { createStudentClassLabels } from "@/lib/student-classes"; import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; @@ -33,6 +35,8 @@ export function UserSearchSelect(props: { placeholder?: string; emptyMessage?: string; disabled?: boolean; + /** Overrides the default "what can I type here" line under the field. */ + hint?: string; role?: Role; }) { const t = useT(); @@ -54,6 +58,24 @@ export function UserSearchSelect(props: { return users().filter((user) => !excluded.has(user.id)).slice(0, MAX_VISIBLE_RESULTS); }); + // A student picker shows the class next to the name: two students can share + // a name, and the account id the row used to carry is a uuid nobody reads. + // Only students get the extra lookup — see `student-classes`. + const classLabels = createStudentClassLabels(() => + props.role === "student" ? options().map((user) => user.id) : [], + ); + const secondaryLine = (user: PersonRef) => { + const cls = classLabels()[user.id]; + return cls ? `${cls} · ${user.username}` : user.username; + }; + // What the input reads after a pick — the name alone is ambiguous, the + // username is the thing that is unique and short. + const pickedLabel = (user: PersonLike) => { + if (!user || typeof user === "string") return personLabel(user); + const name = personLabel(user); + return name === user.username ? name : `${name} (${user.username})`; + }; + // Drop our local selection when the parent clears the bound value. createEffect(() => { if (!props.value && selected()) setSelected(null); @@ -130,14 +152,17 @@ export function UserSearchSelect(props: { if (value.trim().length > 0) setOpen(true); }} optionValue="id" - optionLabel={(user) => personLabelWithId(user)} - optionTextValue={(user) => personLabelWithId(user)} + optionLabel={(user) => pickedLabel(user)} + optionTextValue={(user) => pickedLabel(user)} defaultFilter={() => true} placeholder={props.placeholder ?? t("common.searchPlaceholder")} disabled={props.disabled || !canSearch()} itemComponent={(itemProps) => ( - {personLabelWithId(itemProps.item.rawValue)} + + {personLabel(itemProps.item.rawValue)} + {secondaryLine(itemProps.item.rawValue)} + )} > @@ -151,8 +176,12 @@ export function UserSearchSelect(props: { - -

{t("form.searchNoPermission")}

+ {t("form.searchNoPermission")}

}> + {/* An empty combobox looks like a dropdown that failed to load, so it + says outright that it is a type-to-search field and what it matches. */} +

+ {props.hint ?? (props.role === "student" ? t("search.hint.studentPicker") : props.role === "teacher" ? t("search.hint.teacherPicker") : t("search.hint.personPicker"))} +

); diff --git a/src/components/users/user-table.tsx b/src/components/users/user-table.tsx index 568339c..83fdda5 100644 --- a/src/components/users/user-table.tsx +++ b/src/components/users/user-table.tsx @@ -165,6 +165,7 @@ export function UserTable(props: { empty={t("admin.noUsers")} storageKey="admin-users" searchPredicate={searchUser} + filterHint={t("search.hint.users")} enablePagination pageSize={20} onRowClick={props.onUserClick} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index aa97949..f610843 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -1795,6 +1795,24 @@ export type MessageKey = | "work.addEntry" | "work.planShift" | "lookup.searchHint" + | "search.hint.command" + | "search.hint.commandAdmin" + | "search.hint.studentPicker" + | "search.hint.teacherPicker" + | "search.hint.personPicker" + | "search.hint.students" + | "search.hint.teachers" + | "search.hint.people" + | "search.hint.users" + | "search.hint.exams" + | "search.hint.events" + | "search.hint.courses" + | "search.hint.classes" + | "search.hint.bank" + | "search.hint.whiteboards" + | "search.hint.chat" + | "search.hint.deadlines" + | "search.hint.paymentsStudents" | "work.userNotFound" | "messages.inbox" | "messages.sent" @@ -3797,6 +3815,24 @@ const en: Dict = { "work.addEntry": "Add entry", "work.planShift": "Plan shift", "lookup.searchHint": "Type at least 2 characters to search.", + "search.hint.command": "Type a page or a quick action \u2014 e.g. \"homework\", \"exam\", \"dark theme\".", + "search.hint.commandAdmin": "Type a student name, a page or a quick action \u2014 e.g. \"Ay\u015fe\", \"homework\", \"dark theme\".", + "search.hint.studentPicker": "Type a student's name, surname or username; the list shows their class too.", + "search.hint.teacherPicker": "Type a teacher's name, surname or username.", + "search.hint.personPicker": "Type a name, surname or username.", + "search.hint.students": "Matches name, surname and username. Use the filter next to it for a class.", + "search.hint.teachers": "Matches name, surname and username.", + "search.hint.people": "Matches name, surname, username and user id.", + "search.hint.users": "Matches username, name, e-mail, user id and role.", + "search.hint.exams": "Matches exam title, description, course, exam kind and status.", + "search.hint.events": "Matches event title, description, audience and date.", + "search.hint.courses": "Matches course title, description, creator, teacher and term.", + "search.hint.classes": "Matches class name, grade and homeroom teacher.", + "search.hint.bank": "Matches a phrase inside the question text.", + "search.hint.whiteboards": "Matches board titles on the page you are viewing.", + "search.hint.chat": "Matches the text of the messages in this chat.", + "search.hint.deadlines": "Matches the title of the upcoming items.", + "search.hint.paymentsStudents": "Matches a student's name, surname or username.", "work.userNotFound": "No work log found for this user.", "work.show": "Show log", "work.forUser": "Log for {user}", @@ -5722,6 +5758,24 @@ const tr: Dict = { "work.addEntry": "Kayıt ekle", "work.planShift": "Vardiya planla", "lookup.searchHint": "Aramak için en az 2 karakter yaz.", + "search.hint.command": "Bir sayfa veya h\u0131zl\u0131 i\u015flem yaz\u0131n \u2014 \u00f6rn. \"\u00f6dev\", \"s\u0131nav\", \"koyu tema\".", + "search.hint.commandAdmin": "\u00d6\u011frenci ad\u0131, sayfa veya h\u0131zl\u0131 i\u015flem yaz\u0131n \u2014 \u00f6rn. \"Ay\u015fe\", \"\u00f6dev\", \"koyu tema\".", + "search.hint.studentPicker": "\u00d6\u011frencinin ad\u0131n\u0131, soyad\u0131n\u0131 veya kullan\u0131c\u0131 ad\u0131n\u0131 yaz\u0131n; listede s\u0131n\u0131f\u0131 da g\u00f6r\u00fcn\u00fcr.", + "search.hint.teacherPicker": "\u00d6\u011fretmenin ad\u0131n\u0131, soyad\u0131n\u0131 veya kullan\u0131c\u0131 ad\u0131n\u0131 yaz\u0131n.", + "search.hint.personPicker": "Ad, soyad veya kullan\u0131c\u0131 ad\u0131 yaz\u0131n.", + "search.hint.students": "Ad, soyad ve kullan\u0131c\u0131 ad\u0131nda arar. S\u0131n\u0131f i\u00e7in yan\u0131ndaki filtreyi kullan\u0131n.", + "search.hint.teachers": "Ad, soyad ve kullan\u0131c\u0131 ad\u0131nda arar.", + "search.hint.people": "Ad, soyad, kullan\u0131c\u0131 ad\u0131 ve kullan\u0131c\u0131 ID'sinde arar.", + "search.hint.users": "Kullan\u0131c\u0131 ad\u0131, ad, e-posta, kullan\u0131c\u0131 ID'si ve rolde arar.", + "search.hint.exams": "S\u0131nav ad\u0131, a\u00e7\u0131klama, ders, s\u0131nav t\u00fcr\u00fc ve durumda arar.", + "search.hint.events": "Etkinlik ad\u0131, a\u00e7\u0131klama, kat\u0131l\u0131mc\u0131 kitlesi ve tarihte arar.", + "search.hint.courses": "Ders ad\u0131, a\u00e7\u0131klama, olu\u015fturan, \u00f6\u011fretmen ve d\u00f6nemde arar.", + "search.hint.classes": "\u015eube ad\u0131, s\u0131n\u0131f d\u00fczeyi ve dan\u0131\u015fman \u00f6\u011fretmende arar.", + "search.hint.bank": "Soru metninde ge\u00e7en bir ifadeyi arar.", + "search.hint.whiteboards": "A\u00e7\u0131k olan sayfadaki tahta ba\u015fl\u0131klar\u0131nda arar.", + "search.hint.chat": "Bu sohbetteki mesajlar\u0131n metninde arar.", + "search.hint.deadlines": "Yakla\u015fan kay\u0131tlar\u0131n ba\u015fl\u0131\u011f\u0131nda arar.", + "search.hint.paymentsStudents": "\u00d6\u011frencinin ad\u0131nda, soyad\u0131nda veya kullan\u0131c\u0131 ad\u0131nda arar.", "work.userNotFound": "Bu kullanıcı için mesai kaydı bulunamadı.", "work.show": "Kaydı göster", "work.forUser": "{user} için kayıtlar", diff --git a/src/lib/student-classes.test.tsx b/src/lib/student-classes.test.tsx new file mode 100644 index 0000000..18a1152 --- /dev/null +++ b/src/lib/student-classes.test.tsx @@ -0,0 +1,65 @@ +import { createRoot } from "solid-js"; +import { createStudentClassLabels } from "./student-classes"; + +const calls: string[] = []; +const classesByUser: Record = { + s1: ["10-A"], + s2: ["11-B", "Seçmeli Fizik"], + s3: [], + s9: ["9-C"], +}; + +vi.mock("@/api/classes", () => ({ + getClassesByUserId: async (userId: string) => { + calls.push(userId); + const names = classesByUser[userId]; + if (!names) throw new Error("403"); + return { items: names.map((name, index) => ({ id: `${userId}-${index}`, name })), total: names.length, limit: null, offset: 0 }; + }, +})); + +const flush = () => new Promise((resolve) => setTimeout(resolve, 0)); + +// Solid holds effects until the root's synchronous body returns, so the root +// is entered and left before anything is awaited. +function withRoot(build: () => T): [T, () => void] { + let value!: T; + let dispose!: () => void; + createRoot((disposeRoot) => { + dispose = disposeRoot; + value = build(); + }); + return [value, dispose]; +} + +describe("createStudentClassLabels", () => { + beforeEach(() => { + calls.length = 0; + }); + + it("resolves a class name per student and joins multiple memberships", async () => { + const [labels, dispose] = withRoot(() => createStudentClassLabels(() => ["s1", "s2"])); + await flush(); + expect(labels().s1).toBe("10-A"); + expect(labels().s2).toBe("11-B, Seçmeli Fizik"); + dispose(); + }); + + it("leaves a student with no class — or a refused lookup — unlabelled", async () => { + const [labels, dispose] = withRoot(() => createStudentClassLabels(() => ["s3", "forbidden"])); + await flush(); + expect(labels().s3).toBeUndefined(); + expect(labels().forbidden).toBeUndefined(); + dispose(); + }); + + it("asks the backend once per student, however often the list is read", async () => { + const [, disposeFirst] = withRoot(() => createStudentClassLabels(() => ["s9"])); + await flush(); + const [, disposeSecond] = withRoot(() => createStudentClassLabels(() => ["s9"])); + await flush(); + expect(calls.filter((id) => id === "s9")).toHaveLength(1); + disposeFirst(); + disposeSecond(); + }); +}); diff --git a/src/lib/student-classes.ts b/src/lib/student-classes.ts new file mode 100644 index 0000000..fb5f5ba --- /dev/null +++ b/src/lib/student-classes.ts @@ -0,0 +1,58 @@ +import { createEffect, createSignal, onCleanup } from "solid-js"; +import { getClassesByUserId } from "@/api/classes"; + +/** + * Class labels for people shown in a search result. `/users/search` returns + * only id/username/display name, so "which class is this student in?" — the + * question that tells two students with the same name apart — needs a second + * read per student (`GET /classes/user/{id}`, teacher+). + * + * Only call this for a list that is already bounded (a picker's visible + * results, a palette page), and only for students: a caller below teacher + * gets a 403, which is swallowed here as "no label". + * + * Answers are cached for the lifetime of the tab. Class membership does not + * move during a session, and without the cache every keystroke-driven result + * list would re-ask for people it just looked up. + */ +const cache = new Map(); +const inflight = new Map>(); + +const MAX_CLASSES_PER_STUDENT = 3; + +function load(userId: string): Promise { + const cached = cache.get(userId); + if (cached !== undefined) return Promise.resolve(cached); + const running = inflight.get(userId); + if (running) return running; + const request = getClassesByUserId(userId, { limit: MAX_CLASSES_PER_STUDENT }) + .then((page) => page.items.map((group) => group.name).join(", ")) + // A 403/404 (no permission, no such membership) is not an error to show — + // the row simply carries no class. + .catch(() => "") + .then((label) => { + cache.set(userId, label); + inflight.delete(userId); + return label; + }); + inflight.set(userId, request); + return request; +} + +/** Reactive `id -> class name` map that fills in as the lookups land. */ +export function createStudentClassLabels(userIds: () => string[]) { + const [labels, setLabels] = createSignal>({}); + createEffect(() => { + let disposed = false; + onCleanup(() => { + disposed = true; + }); + for (const id of userIds()) { + void load(id).then((label) => { + if (disposed || !label) return; + setLabels((prev) => (prev[id] === label ? prev : { ...prev, [id]: label })); + }); + } + }); + return labels; +} diff --git a/src/pages/classes-page.tsx b/src/pages/classes-page.tsx index 4d1ea3f..a4d0fd2 100644 --- a/src/pages/classes-page.tsx +++ b/src/pages/classes-page.tsx @@ -177,7 +177,7 @@ function ClassesContent() { } >
- + 0}> diff --git a/src/pages/courses-page.tsx b/src/pages/courses-page.tsx index 6a1c7a0..12f44d1 100644 --- a/src/pages/courses-page.tsx +++ b/src/pages/courses-page.tsx @@ -184,6 +184,7 @@ function CoursesContent() { inline searchValue={search()} searchPlaceholder={t("common.searchPlaceholder")} + searchHint={t("search.hint.courses")} onSearchInput={setSearch} filters={