File tree Expand file tree Collapse file tree 4 files changed +23
-14
lines changed Expand file tree Collapse file tree 4 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -57,14 +57,23 @@ export const useFilter = ({
57
57
const update = ( newValues : string | FilterValues ) => {
58
58
const serialized =
59
59
typeof newValues === "string" ? newValues : stringifyFilter ( newValues ) ;
60
- const noUpdateNeeded = searchParams . get ( useFilterParamsKey ) === serialized ;
60
+ const noUpdateNeeded = query === serialized ;
61
61
if ( noUpdateNeeded ) {
62
62
return ;
63
63
}
64
64
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 ) ;
68
77
onUpdate ?.( serialized ) ;
69
78
} ;
70
79
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ export function usePagination(
19
19
) : UsePaginationResult {
20
20
const { searchParams, onSearchParamsChange } = options ;
21
21
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 ;
24
24
25
25
return {
26
26
page,
Original file line number Diff line number Diff line change 1
1
import { screen , waitFor } from "@testing-library/react" ;
2
2
import userEvent from "@testing-library/user-event" ;
3
3
import { API } from "api/api" ;
4
+ import type { AuditLogsRequest } from "api/typesGenerated" ;
4
5
import { DEFAULT_RECORDS_PER_PAGE } from "components/PaginationWidget/utils" ;
5
6
import { http , HttpResponse } from "msw" ;
6
7
import {
@@ -106,7 +107,7 @@ describe("AuditPage", () => {
106
107
await userEvent . type ( filterField , query ) ;
107
108
108
109
await waitFor ( ( ) =>
109
- expect ( getAuditLogsSpy ) . toBeCalledWith ( {
110
+ expect ( getAuditLogsSpy ) . toHaveBeenCalledWith < [ AuditLogsRequest ] > ( {
110
111
limit : DEFAULT_RECORDS_PER_PAGE ,
111
112
offset : 0 ,
112
113
q : query ,
Original file line number Diff line number Diff line change 1
1
import { screen , waitFor , within } from "@testing-library/react" ;
2
2
import userEvent from "@testing-library/user-event" ;
3
3
import { API } from "api/api" ;
4
- import type { Workspace } from "api/typesGenerated" ;
4
+ import type { Workspace , WorkspacesResponse } from "api/typesGenerated" ;
5
5
import { http , HttpResponse } from "msw" ;
6
6
import {
7
7
MockDormantOutdatedWorkspace ,
@@ -28,18 +28,17 @@ describe("WorkspacesPage", () => {
28
28
} ) ;
29
29
30
30
it ( "renders an empty workspaces page" , async ( ) => {
31
- // Given
32
31
server . use (
33
32
http . get ( "/api/v2/workspaces" , async ( ) => {
34
- return HttpResponse . json ( { workspaces : [ ] , count : 0 } ) ;
33
+ return HttpResponse . json < WorkspacesResponse > ( {
34
+ workspaces : [ ] ,
35
+ count : 0 ,
36
+ } ) ;
35
37
} ) ,
36
38
) ;
37
39
38
- // When
39
40
renderWithAuth ( < WorkspacesPage /> ) ;
40
-
41
- // Then
42
- await screen . findByText ( "Create a workspace" ) ;
41
+ await screen . findByRole ( "heading" , { name : / C r e a t e a w o r k s p a c e / } ) ;
43
42
} ) ;
44
43
45
44
it ( "renders a filled workspaces page" , async ( ) => {
You can’t perform that action at this time.
0 commit comments