Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin): fix test pages paging #3557

Merged
merged 1 commit into from
May 2, 2024
Merged
Changes from all 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
18 changes: 12 additions & 6 deletions adminSiteServer/testPageRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ async function propsFromQueryParams(

let query = knex
.table("charts")
.select("id", "slug")
.whereRaw("publishedAt IS NOT NULL")
.limit(perPage)
.offset(perPage * (page - 1))
.orderBy("id", "DESC")
console.error(query.toSQL())

Expand Down Expand Up @@ -278,9 +275,17 @@ async function propsFromQueryParams(
)
}

console.error(query.toSQL())
const chartsQuery = query
.clone()
.select("id", "slug")
.limit(perPage)
.offset(perPage * (page - 1))

const countQuery = query.clone().count({ count: "*" })

console.error(chartsQuery.toSQL())

const charts: ChartItem[] = (await query).map((c) => ({
const charts: ChartItem[] = (await chartsQuery).map((c) => ({
id: c.id,
slug: c.slug ?? "",
}))
Expand All @@ -289,7 +294,8 @@ async function propsFromQueryParams(
charts.forEach((c) => (c.slug += `?tab=${tab}`))
}

const count = await charts.length
const countRes = (await countQuery) as { count: number }[]
const count = countRes[0]?.count as number
const numPages = Math.ceil(count / perPage)

const originalUrl = Url.fromURL(params.originalUrl)
Expand Down
Loading