Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7806fd

Browse files
authored
fix(site): paginate audit logs (#8513)
1 parent9aae983 commitb7806fd

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { server } from "testHelpers/server"
1515

1616
import*asCreateDayStringfrom"utils/createDayString"
1717
importAuditPagefrom"./AuditPage"
18+
import{DEFAULT_RECORDS_PER_PAGE}from"components/PaginationWidget/utils"
1819

1920
interfaceRenderPageOptions{
2021
filter?:string
@@ -67,6 +68,27 @@ describe("AuditPage", () => {
6768
screen.getByTestId(`audit-log-row-${MockAuditLog2.id}`)
6869
})
6970

71+
it("renders page 5",async()=>{
72+
// Given
73+
constpage=5
74+
constgetAuditLogsSpy=jest.spyOn(API,"getAuditLogs").mockResolvedValue({
75+
audit_logs:[MockAuditLog,MockAuditLog2],
76+
count:2,
77+
})
78+
79+
// When
80+
awaitrenderPage({page:page})
81+
82+
// Then
83+
expect(getAuditLogsSpy).toBeCalledWith({
84+
limit:DEFAULT_RECORDS_PER_PAGE,
85+
offset:DEFAULT_RECORDS_PER_PAGE*(page-1),
86+
q:"",
87+
})
88+
screen.getByTestId(`audit-log-row-${MockAuditLog.id}`)
89+
screen.getByTestId(`audit-log-row-${MockAuditLog2.id}`)
90+
})
91+
7092
describe("Filtering",()=>{
7193
it("filters by URL",async()=>{
7294
constgetAuditLogsSpy=jest
@@ -76,7 +98,11 @@ describe("AuditPage", () => {
7698
constquery="resource_type:workspace action:create"
7799
awaitrenderPage({filter:query})
78100

79-
expect(getAuditLogsSpy).toBeCalledWith({limit:25,offset:1,q:query})
101+
expect(getAuditLogsSpy).toBeCalledWith({
102+
limit:DEFAULT_RECORDS_PER_PAGE,
103+
offset:0,
104+
q:query,
105+
})
80106
})
81107

82108
it("resets page to 1 when filter is changed",async()=>{
@@ -91,8 +117,8 @@ describe("AuditPage", () => {
91117

92118
awaitwaitFor(()=>
93119
expect(getAuditLogsSpy).toBeCalledWith({
94-
limit:25,
95-
offset:1,
120+
limit:DEFAULT_RECORDS_PER_PAGE,
121+
offset:0,
96122
q:query,
97123
}),
98124
)

‎site/src/pages/AuditPage/AuditPage.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import{nonInitialPage}from"components/PaginationWidget/utils"
1+
import{
2+
DEFAULT_RECORDS_PER_PAGE,
3+
nonInitialPage,
4+
}from"components/PaginationWidget/utils"
25
import{useFeatureVisibility}from"hooks/useFeatureVisibility"
36
import{FC}from"react"
47
import{Helmet}from"react-helmet-async"
@@ -49,9 +52,11 @@ const AuditPage: FC = () => {
4952
const{ data, error}=useQuery({
5053
queryKey:["auditLogs",filter.query,pagination.page],
5154
queryFn:()=>{
55+
constlimit=DEFAULT_RECORDS_PER_PAGE
56+
constpage=pagination.page
5257
returngetAuditLogs({
53-
offset:pagination.page,
54-
limit:25,
58+
offset:page<=0 ?0 :(page-1)*limit,
59+
limit:limit,
5560
q:filter.query,
5661
})
5762
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp