Skip to content

Commit 338cf4d

Browse files
committed
Merge branch 'mes/batch-update-01' into mes/batch-update-02
2 parents 18ad064 + fb9d8f2 commit 338cf4d

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

site/src/components/Filter/Filter.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,23 @@ export const useFilter = ({
5757
const update = (newValues: string | FilterValues) => {
5858
const serialized =
5959
typeof newValues === "string" ? newValues : stringifyFilter(newValues);
60-
const noUpdateNeeded = searchParams.get(useFilterParamsKey) === serialized;
60+
const noUpdateNeeded = query === serialized;
6161
if (noUpdateNeeded) {
6262
return;
6363
}
6464

65-
const copy = new URLSearchParams(searchParams);
66-
copy.set(useFilterParamsKey, serialized);
67-
onSearchParamsChange(copy);
65+
/**
66+
* @todo 2025-07-15 - We have a slightly nasty bug here, where trying to
67+
* update state the "React way" causes our code to break.
68+
*
69+
* In theory, it would be better to make a copy of the search params. We
70+
* can then mutate and dispatch the copy instead of the original. Doing
71+
* that causes other parts of our existing logic to break, though.
72+
* That's a sign that our other code is slightly broken, and only just
73+
* happens to work by chance right now.
74+
*/
75+
searchParams.set(useFilterParamsKey, serialized);
76+
onSearchParamsChange(searchParams);
6877
onUpdate?.(serialized);
6978
};
7079

site/src/hooks/usePagination.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export function usePagination(
1919
): UsePaginationResult {
2020
const { searchParams, onSearchParamsChange } = options;
2121
const limit = DEFAULT_RECORDS_PER_PAGE;
22-
const rawPage = Number.parseInt(searchParams.get(paginationKey) || "0", 10);
23-
const page = Number.isNaN(rawPage) ? 1 : rawPage;
22+
const rawPage = Number.parseInt(searchParams.get(paginationKey) || "1", 10);
23+
const page = Number.isNaN(rawPage) || rawPage <= 0 ? 1 : rawPage;
2424

2525
return {
2626
page,

site/src/pages/AuditPage/AuditPage.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { screen, waitFor } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
33
import { API } from "api/api";
4+
import type { AuditLogsRequest } from "api/typesGenerated";
45
import { DEFAULT_RECORDS_PER_PAGE } from "components/PaginationWidget/utils";
56
import { http, HttpResponse } from "msw";
67
import {
@@ -106,7 +107,7 @@ describe("AuditPage", () => {
106107
await userEvent.type(filterField, query);
107108

108109
await waitFor(() =>
109-
expect(getAuditLogsSpy).toBeCalledWith({
110+
expect(getAuditLogsSpy).toHaveBeenCalledWith<[AuditLogsRequest]>({
110111
limit: DEFAULT_RECORDS_PER_PAGE,
111112
offset: 0,
112113
q: query,

site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { screen, waitFor, within } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
33
import { API } from "api/api";
4-
import type { Workspace } from "api/typesGenerated";
4+
import type { Workspace, WorkspacesResponse } from "api/typesGenerated";
55
import { http, HttpResponse } from "msw";
66
import {
77
MockDormantOutdatedWorkspace,
@@ -28,18 +28,17 @@ describe("WorkspacesPage", () => {
2828
});
2929

3030
it("renders an empty workspaces page", async () => {
31-
// Given
3231
server.use(
3332
http.get("/api/v2/workspaces", async () => {
34-
return HttpResponse.json({ workspaces: [], count: 0 });
33+
return HttpResponse.json<WorkspacesResponse>({
34+
workspaces: [],
35+
count: 0,
36+
});
3537
}),
3638
);
3739

38-
// When
3940
renderWithAuth(<WorkspacesPage />);
40-
41-
// Then
42-
await screen.findByText("Create a workspace");
41+
await screen.findByRole("heading", { name: /Create a workspace/ });
4342
});
4443

4544
it("renders a filled workspaces page", async () => {

0 commit comments

Comments
 (0)