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

fix(site): paginate audit logs#8513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 2 commits intomainfrom7995-audit-start
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletionssite/src/pages/AuditPage/AuditPage.test.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@ import { server } from "testHelpers/server"

import * as CreateDayString from "utils/createDayString"
import AuditPage from "./AuditPage"
import { DEFAULT_RECORDS_PER_PAGE } from "components/PaginationWidget/utils"

interface RenderPageOptions {
filter?: string
Expand DownExpand Up@@ -67,6 +68,27 @@ describe("AuditPage", () => {
screen.getByTestId(`audit-log-row-${MockAuditLog2.id}`)
})

it("renders page 5", async () => {
// Given
const page = 5
const getAuditLogsSpy = jest.spyOn(API, "getAuditLogs").mockResolvedValue({
audit_logs: [MockAuditLog, MockAuditLog2],
count: 2,
})

// When
await renderPage({ page: page })

// Then
expect(getAuditLogsSpy).toBeCalledWith({
limit: DEFAULT_RECORDS_PER_PAGE,
offset: DEFAULT_RECORDS_PER_PAGE * (page - 1),
q: "",
})
screen.getByTestId(`audit-log-row-${MockAuditLog.id}`)
screen.getByTestId(`audit-log-row-${MockAuditLog2.id}`)
})

describe("Filtering", () => {
it("filters by URL", async () => {
const getAuditLogsSpy = jest
Expand All@@ -76,7 +98,11 @@ describe("AuditPage", () => {
const query = "resource_type:workspace action:create"
await renderPage({ filter: query })

expect(getAuditLogsSpy).toBeCalledWith({ limit: 25, offset: 1, q: query })
expect(getAuditLogsSpy).toBeCalledWith({
limit: DEFAULT_RECORDS_PER_PAGE,
offset: 0,
q: query,
})
})

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

await waitFor(() =>
expect(getAuditLogsSpy).toBeCalledWith({
limit:25,
offset:1,
limit:DEFAULT_RECORDS_PER_PAGE,
offset:0,
q: query,
}),
)
Expand Down
11 changes: 8 additions & 3 deletionssite/src/pages/AuditPage/AuditPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
import { nonInitialPage } from "components/PaginationWidget/utils"
import {
DEFAULT_RECORDS_PER_PAGE,
nonInitialPage,
} from "components/PaginationWidget/utils"
import { useFeatureVisibility } from "hooks/useFeatureVisibility"
import { FC } from "react"
import { Helmet } from "react-helmet-async"
Expand DownExpand Up@@ -49,9 +52,11 @@ const AuditPage: FC = () => {
const { data, error } = useQuery({
queryKey: ["auditLogs", filter.query, pagination.page],
queryFn: () => {
const limit = DEFAULT_RECORDS_PER_PAGE
const page = pagination.page
return getAuditLogs({
offset:pagination.page,
limit:25,
offset: page <= 0 ? 0 : (page - 1) * limit,
limit:limit,
q: filter.query,
})
},
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp