A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
fix: stop application search session refetches (#3507)
Emanuele Tonellob42eb6ec0625
diff --git a/apps/web/src/routes/dashboard/applications/-index.test.tsx b/apps/web/src/routes/dashboard/applications/-index.test.tsxnew file mode 100644index 000000000..bd78a9a6d--- /dev/null+++ b/apps/web/src/routes/dashboard/applications/-index.test.tsx@@ -0,0 +1,113 @@+// @vitest-environment happy-dom++import { cleanup, render, screen, waitFor } from "@testing-library/react";+import userEvent from "@testing-library/user-event";+import { beforeEach, expect, it, vi } from "vitest";+import { i18n } from "@lingui/core";+import { I18nProvider } from "@lingui/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { createMemoryHistory, createRootRoute, createRouter, RouterProvider } from "@tanstack/react-router";++const mocks = vi.hoisted(() => ({ list: vi.fn() }));++vi.mock("@/libs/orpc/client", () => ({+ orpc: {+ applications: {+ list: { queryOptions: () => ({ queryKey: ["applications"], queryFn: mocks.list }) },+ tags: { queryOptions: () => ({ queryKey: ["tags"], queryFn: async () => [] }) },+ },+ },+}));+vi.mock("@/features/applications/components/application-detail-sheet", () => ({ ApplicationDetailSheet: () => null }));+vi.mock("@/features/applications/components/application-form-sheet", () => ({ ApplicationFormSheet: () => null }));+vi.mock("@/features/applications/components/export-applications-sheet", () => ({+ ExportApplicationsSheet: () => null,+}));+vi.mock("@/features/applications/components/import-applications-sheet", () => ({+ ImportApplicationsSheet: () => null,+}));+vi.mock("@/features/applications/components/board", () => ({ ApplicationBoard: () => null }));+vi.mock("@/features/applications/components/insights-view", () => ({ ApplicationInsights: () => null }));+vi.mock("../-components/header", () => ({ DashboardHeader: () => null }));++type TableProps = { applications: { id: string; company: string }[] };+vi.mock("@/features/applications/components/table-view", () => ({+ ApplicationTable: ({ applications }: TableProps) => (+ <ul aria-label="Applications">+ {applications.map((application) => (+ <li key={application.id}>{application.company}</li>+ ))}+ </ul>+ ),+}));++import { Route } from "./index";++beforeEach(() => {+ vi.restoreAllMocks();+ vi.clearAllMocks();+ i18n.loadAndActivate({ locale: "en-US", messages: {} });+ mocks.list.mockResolvedValue([+ { id: "one", company: "Acme", role: "Engineer", tags: [], archived: false },+ { id: "two", company: "Example", role: "Designer", tags: [], archived: false },+ { id: "archived", company: "Archived company", role: "Engineer", tags: [], archived: true },+ ]);+});++async function renderApplications(url: string) {+ const rootRoute = createRootRoute();+ const routeOptions = { ...Route.options, path: "/dashboard/applications/", getParentRoute: () => rootRoute };+ const routeTree = rootRoute.addChildren([Route.update(routeOptions)]);+ const router = createRouter({ routeTree, history: createMemoryHistory({ initialEntries: [url] }) });+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });+ await router.load();+ render(+ <QueryClientProvider client={queryClient}>+ <I18nProvider i18n={i18n}>+ <RouterProvider router={router} />+ </I18nProvider>+ </QueryClientProvider>,+ );+ await screen.findByPlaceholderText("Search applications…");+ return router;+}++it("clears a URL-seeded search without restoring it on reload", async () => {+ const router = await renderApplications(+ '/dashboard/applications/?search=no-such-company&tags=["missing"]&archived=true&view=table&sort=company',+ );+ expect(screen.getByPlaceholderText("Search applications…")).toHaveValue("no-such-company");+ await userEvent.click(screen.getByRole("button", { name: "Clear filters" }));++ expect(screen.getByPlaceholderText("Search applications…")).toHaveValue("");+ expect(await screen.findByText("Acme")).toBeVisible();+ expect(screen.getByText("Example")).toBeVisible();+ expect(screen.queryByText("Archived company")).not.toBeInTheDocument();+ await waitFor(() => expect(router.state.location.search).toEqual({ view: "table", sort: "company" }));++ const reloadUrl = router.history.location.href;+ cleanup();+ await renderApplications(reloadUrl);+ expect(screen.getByPlaceholderText("Search applications…")).toHaveValue("");+ expect(screen.getByText("Acme")).toBeVisible();+ expect(screen.getByText("Example")).toBeVisible();+ expect(screen.queryByRole("button", { name: "Clear filters" })).not.toBeInTheDocument();+});++it("filters typed company and role searches without navigating or refetching", async () => {+ const router = await renderApplications("/dashboard/applications/?view=table&sort=company");+ const navigate = vi.spyOn(router, "navigate");+ const url = router.history.location.href;+ const input = screen.getByPlaceholderText("Search applications…");++ await userEvent.type(input, "acme");+ expect(screen.getByText("Acme")).toBeVisible();+ expect(screen.queryByText("Example")).not.toBeInTheDocument();+ await userEvent.clear(input);+ await userEvent.type(input, "designer");+ expect(screen.getByText("Example")).toBeVisible();+ expect(screen.queryByText("Acme")).not.toBeInTheDocument();+ expect(navigate).not.toHaveBeenCalled();+ expect(router.history.location.href).toBe(url);+ expect(mocks.list).toHaveBeenCalledTimes(1);+});diff --git a/apps/web/src/routes/dashboard/applications/index.tsx b/apps/web/src/routes/dashboard/applications/index.tsxindex 773909043..b28584193 100644--- a/apps/web/src/routes/dashboard/applications/index.tsx+++ b/apps/web/src/routes/dashboard/applications/index.tsx@@ -67,6 +67,7 @@ function RouteComponent() {const { search, view, tags, sort, archived, create, applicationId } = Route.useSearch();const navigate = useNavigate({ from: Route.fullPath });+ const [textSearch, setTextSearch] = useState(search);const [addOpen, setAddOpen] = useState(false);const [importOpen, setImportOpen] = useState(false);const [exportOpen, setExportOpen] = useState(false);@@ -98,7 +99,7 @@ function RouteComponent() {// Board & table hide archived; tag/search filters + sort are applied client-side.const filtered = useMemo(() => {- const query = search.trim().toLowerCase();+ const query = textSearch.trim().toLowerCase();const rows = (applications ?? []).filter((app) => archived || !app.archived).filter((app) => tags.length === 0 || tags.every((tag: string) => app.tags.includes(tag)))@@ -111,13 +112,13 @@ function RouteComponent() {role: (a, b) => a.role.localeCompare(b.role),};return rows.sort(compare[sort as SortKey]);- }, [applications, search, tags, sort, archived]);+ }, [applications, textSearch, tags, sort, archived]);const archivedCount = (applications ?? []).filter((app) => app.archived).length;const isEmpty = (applications?.length ?? 0) === 0;- const setSearch = (patch: Partial<Search>) => void navigate({ search: (prev: Search) => ({ ...prev, ...patch }) });+ const setUrlSearch = (patch: Partial<Search>) => void navigate({ search: (prev: Search) => ({ ...prev, ...patch }) });return (<div className="flex h-[calc(100dvh-2rem)] flex-col gap-4">@@ -158,9 +159,9 @@ function RouteComponent() {<MagnifyingGlassIcon /></InputGroupAddon><InputGroupInput- value={search}+ value={textSearch}placeholder={t`Search applications…`}- onChange={(event) => setSearch({ search: event.target.value })}+ onChange={(event) => setTextSearch(event.target.value)}/></InputGroup>@@ -172,7 +173,7 @@ function RouteComponent() {value={tags}placeholder={t`Filter by tags`}options={(allTags ?? []).map((tag) => ({ value: tag, label: tag }))}- onValueChange={(value) => setSearch({ tags: value ?? [] })}+ onValueChange={(value) => setUrlSearch({ tags: value ?? [] })}/>)}@@ -182,7 +183,7 @@ function RouteComponent() {value={sort}placeholder={t`Sort by…`}options={SORT_OPTIONS.map((option) => ({ value: option.value, label: i18n.t(option.label) }))}- onValueChange={(value) => value && setSearch({ sort: value as SortKey })}+ onValueChange={(value) => value && setUrlSearch({ sort: value as SortKey })}/>)}@@ -191,7 +192,7 @@ function RouteComponent() {size="sm"variant={archived ? "secondary" : "outline"}className="shrink-0 max-sm:hidden"- onClick={() => setSearch({ archived: !archived })}+ onClick={() => setUrlSearch({ archived: !archived })}><ArchiveIcon /><Trans>Archived</Trans> ({archivedCount})@@ -223,7 +224,7 @@ function RouteComponent() {value={tags}placeholder={t`Any tag`}options={(allTags ?? []).map((tag) => ({ value: tag, label: tag }))}- onValueChange={(value) => setSearch({ tags: value ?? [] })}+ onValueChange={(value) => setUrlSearch({ tags: value ?? [] })}/></div>)}@@ -235,7 +236,7 @@ function RouteComponent() {className="w-full"value={sort}options={SORT_OPTIONS.map((option) => ({ value: option.value, label: i18n.t(option.label) }))}- onValueChange={(value) => value && setSearch({ sort: value as SortKey })}+ onValueChange={(value) => value && setUrlSearch({ sort: value as SortKey })}/></div>{archivedCount > 0 && (@@ -243,7 +244,7 @@ function RouteComponent() {size="sm"variant={archived ? "secondary" : "outline"}className="w-full"- onClick={() => setSearch({ archived: !archived })}+ onClick={() => setUrlSearch({ archived: !archived })}><ArchiveIcon /><Trans>Archived</Trans> ({archivedCount})@@ -295,7 +296,10 @@ function RouteComponent() {<Buttonsize="sm"variant="outline"- onClick={() => setSearch({ search: "", tags: [], archived: false })}+ onClick={() => {+ setTextSearch("");+ setUrlSearch({ search: "", tags: [], archived: false });+ }}><Trans>Clear filters</Trans></Button>