From 52bbe313ef0317ed7a839068a30e129119f32d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Thu, 17 Sep 2026 22:13:50 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=94=8D=20one=20Turkish-aware?= =?UTF-8?q?=20filter=20behind=20every=20search=20box=20-=20new=20src/lib/s?= =?UTF-8?q?earch-text.ts:=20fold=20case,=20Turkish=20letters,=20accents=20?= =?UTF-8?q?and=20=20=20punctuation=20for=20comparison,=20and=20match=20eve?= =?UTF-8?q?ry=20typed=20term=20in=20any=20order,=20so=20=20=20"ogretmen"?= =?UTF-8?q?=20finds=20"=C3=96=C4=9Fretmen",=20"9a"=20finds=20"9-A"=20and?= =?UTF-8?q?=20"ayse=209a"=20finds=20both=20-=20replace=20the=20per-page=20?= =?UTF-8?q?toLocaleLowerCase().includes()=20filters=20with=20it=20across?= =?UTF-8?q?=20=20=20rosters,=20courses,=20exams,=20events,=20classes,=20me?= =?UTF-8?q?ssages,=20payments,=20whiteboards,=20=20=20the=20dashboard=20de?= =?UTF-8?q?adlines,=20the=20user=20table,=20the=20blueprint=20picker,=20th?= =?UTF-8?q?e=20command=20=20=20palette=20and=20=C3=87elebi's=20message=20s?= =?UTF-8?q?earch=20-=20DataTableSearch:=20Escape=20empties=20the=20field?= =?UTF-8?q?=20(and=20only=20then=20stops=20the=20event,=20=20=20so=20Escap?= =?UTF-8?q?e=20still=20closes=20the=20panel=20around=20it)=20-=20Searchabl?= =?UTF-8?q?eSelect:=20the=20same=20folding=20filter=20instead=20of=20Kobal?= =?UTF-8?q?te's=20raw=20=20=20substring=20test,=20plus=20a=20"no=20results?= =?UTF-8?q?"=20line=20where=20the=20popover=20used=20to=20just=20=20=20clo?= =?UTF-8?q?se=20and=20read=20as=20broken=20-=20UserSearchSelect:=20say=20i?= =?UTF-8?q?t=20is=20loading=20while=20the=20debounce=20and=20request=20run?= =?UTF-8?q?,=20=20=20instead=20of=20showing=20an=20empty=20panel=20that=20?= =?UTF-8?q?reads=20as=20"nobody=20matches"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/classes/blueprint-panel.tsx | 5 +- src/components/layout/command-palette.tsx | 7 ++- src/components/ui/data-table-search.tsx | 12 ++++- src/components/ui/searchable-select.test.tsx | 45 ++++++++++++++++++ src/components/ui/searchable-select.tsx | 31 ++++++++++-- src/components/users/user-search-select.tsx | 5 ++ src/components/users/user-table.tsx | 6 +-- src/lib/search-text.test.ts | 50 ++++++++++++++++++++ src/lib/search-text.ts | 40 ++++++++++++++++ src/pages/classes-page.tsx | 5 +- src/pages/courses-page.tsx | 9 ++-- src/pages/dashboard-page.tsx | 3 +- src/pages/events-page.tsx | 13 +++-- src/pages/exams-page.tsx | 13 +++-- src/pages/messages-page.tsx | 5 +- src/pages/payments-page.tsx | 8 ++-- src/pages/staff-work-page.tsx | 3 +- src/pages/student-attendance-page.tsx | 3 +- src/pages/student-marks-page.tsx | 3 +- src/pages/student-pomodoro-page.tsx | 3 +- src/pages/whiteboards-page.tsx | 5 +- 21 files changed, 229 insertions(+), 45 deletions(-) create mode 100644 src/components/ui/searchable-select.test.tsx create mode 100644 src/lib/search-text.test.ts create mode 100644 src/lib/search-text.ts diff --git a/src/components/classes/blueprint-panel.tsx b/src/components/classes/blueprint-panel.tsx index 4511985..ac4cbcc 100644 --- a/src/components/classes/blueprint-panel.tsx +++ b/src/components/classes/blueprint-panel.tsx @@ -11,6 +11,7 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { SidePanel } from "@/components/ui/side-panel"; import { courseKindLabel } from "@/lib/course-kind"; +import { matchesSearch } from "@/lib/search-text"; import { useT } from "@/stores/preferences-context"; export function BlueprintPanel(props: { @@ -47,9 +48,9 @@ export function BlueprintPanel(props: { }); const visibleCourses = createMemo(() => { - const q = filter().trim().toLocaleLowerCase("tr-TR"); + const q = filter().trim(); if (!q) return props.courses; - return props.courses.filter((c) => c.title.toLocaleLowerCase("tr-TR").includes(q)); + return props.courses.filter((c) => matchesSearch(q, c.title)); }); const isSelected = (id: string) => selected().includes(id); diff --git a/src/components/layout/command-palette.tsx b/src/components/layout/command-palette.tsx index 33dd848..f5dca52 100644 --- a/src/components/layout/command-palette.tsx +++ b/src/components/layout/command-palette.tsx @@ -26,6 +26,7 @@ import { useAuth } from "@/stores/auth-context"; import { useModules } from "@/stores/modules-context"; import { usePreferences, useT } from "@/stores/preferences-context"; import { cn } from "@/lib/cn"; +import { matchesSearch } from "@/lib/search-text"; export type CommandPaletteProps = { open: boolean; @@ -289,7 +290,7 @@ export function CommandPalette(props: CommandPaletteProps) { }); const filteredItems = createMemo(() => { - const q = query().trim().toLocaleLowerCase(prefs.locale()); + const q = query().trim(); if (!q) return items(); const peopleLabel = t("command.group.people"); const found: CommandItem[] = (people.latest?.items ?? []).map((person) => ({ @@ -302,9 +303,7 @@ export function CommandPalette(props: CommandPaletteProps) { onSelect: () => void navigate({ to: "/admin/users/$id", params: { id: person.id } }), })); return [...found, ...items().filter((item) => - `${item.title} ${item.description ?? ""} ${item.keywords ?? ""} ${item.categoryLabel}` - .toLocaleLowerCase(prefs.locale()) - .includes(q), + matchesSearch(q, item.title, item.description, item.keywords, item.categoryLabel), )]; }); diff --git a/src/components/ui/data-table-search.tsx b/src/components/ui/data-table-search.tsx index 8a09489..13dd30e 100644 --- a/src/components/ui/data-table-search.tsx +++ b/src/components/ui/data-table-search.tsx @@ -18,8 +18,8 @@ export type DataTableSearchProps = { class?: string; }; -/** Rounded search field: leading icon, conditional clear (X) button, and an - * optional on-focus hint naming the fields it searches. */ +/** Rounded search field: leading icon, conditional clear (X) button, Escape to + * empty it, and an optional on-focus hint naming the fields it searches. */ export function DataTableSearch(props: DataTableSearchProps) { const t = useT(); const [focused, setFocused] = createSignal(false); @@ -34,6 +34,14 @@ export function DataTableSearch(props: DataTableSearchProps) { props.onChange(event.currentTarget.value)} + // Escape empties the box instead of only blurring it: a filter the + // keyboard cannot undo leaves the list silently narrowed. + onKeyDown={(event: KeyboardEvent) => { + if (event.key !== "Escape" || !props.value) return; + event.preventDefault(); + event.stopPropagation(); + props.onChange(""); + }} 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")} diff --git a/src/components/ui/searchable-select.test.tsx b/src/components/ui/searchable-select.test.tsx new file mode 100644 index 0000000..b5a5114 --- /dev/null +++ b/src/components/ui/searchable-select.test.tsx @@ -0,0 +1,45 @@ +import { cleanup, fireEvent, render, screen, waitFor } from "@solidjs/testing-library"; +import { afterEach, expect, it, vi } from "vitest"; +import { SearchableSelect } from "@/components/ui/searchable-select"; +import { PreferencesProvider } from "@/stores/preferences-context"; + +const OPTIONS = [ + { value: "m", label: "9-A · Matematik" }, + { value: "t", label: "10-B · Türkçe" }, +]; + +afterEach(cleanup); + +function renderSelect(onChange = vi.fn()) { + render(() => ( + + + + )); + return { input: screen.getByRole("combobox"), onChange }; +} + +it("finds an option across a dash and word order", async () => { + const { input } = renderSelect(); + + fireEvent.input(input, { target: { value: "9a matematik" } }); + + await waitFor(() => expect(screen.getByRole("option", { name: "9-A · Matematik" })).toBeTruthy()); + expect(screen.queryByRole("option", { name: "10-B · Türkçe" })).toBeNull(); +}); + +it("finds an option typed without its Turkish diacritics", async () => { + const { input } = renderSelect(); + + fireEvent.input(input, { target: { value: "turkce" } }); + + await waitFor(() => expect(screen.getByRole("option", { name: "10-B · Türkçe" })).toBeTruthy()); +}); + +it("says so when the search matches nothing", async () => { + const { input } = renderSelect(); + + fireEvent.input(input, { target: { value: "fizik" } }); + + await waitFor(() => expect(screen.getByText("No results.")).toBeTruthy()); +}); diff --git a/src/components/ui/searchable-select.tsx b/src/components/ui/searchable-select.tsx index d293fcc..184ad40 100644 --- a/src/components/ui/searchable-select.tsx +++ b/src/components/ui/searchable-select.tsx @@ -1,4 +1,4 @@ -import { createMemo } from "solid-js"; +import { Show, createMemo, createSignal } from "solid-js"; import { Combobox, ComboboxContent, @@ -9,13 +9,16 @@ import { ComboboxItemLabel, ComboboxTrigger, } from "@/components/ui/combobox"; +import { matchesSearch } from "@/lib/search-text"; +import { useT } from "@/stores/preferences-context"; export type SearchableOption = { value: string; label: string }; /** * Type-to-filter dropdown over a preloaded option list. Kobalte handles - * filtering, keyboard nav, ARIA and highlight. Drop-in for a native `