mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem The deliveries table loaded one page from the API and split it into pages of 5 in the browser, so older deliveries could not be reached. Linear: [FE-3750](https://linear.app/supabase/issue/FE-3750/add-pagination-to-platform-webhooks-deliveries-table) ## Solution - **Cursor pagination:** the table requests deliveries 5 at a time (`page[after]`), and Next and Previous load the next or previous page. It asks for 6 and shows 5, so Next is never enabled on an empty page. Previous uses the history of cursors we visited, because the API's `prev` link can skip a row or land on an empty page. - The footer reads "Showing N deliveries" (the API returns no total). The delivery search still filters only the loaded page. - **Loading and errors:** skeleton rows show while a page loads, and a failed load shows an error with a Try again button instead of "No deliveries found", and polling stops until you retry. If a later refresh fails, the loaded rows stay with a notice that they may be out of date, and polling continues. - Retry and Send test event refresh every cached page of the endpoint's deliveries. Switching endpoints starts again on page 1. - Retry from the details sheet now works for a delivery that is not on the current page. - A pending delivery has no result yet, so its row no longer opens the details sheet. Its Retry button is unchanged. - Removed the "Attempt" field from the details sheet. It was the row's position on the page, not an attempt number. A real one needs the API to return it (CTRL-1974). ## Review instructions 1. Enable the Platform Webhooks feature preview, open an endpoint, and send 7 test events (limited to 10 per minute). 2. Page 1 shows 5 deliveries, Previous is disabled and Next is enabled. Next shows the other 2 and disables Next. Previous goes back to the first 5. 3. On an endpoint with exactly 5 deliveries, both buttons are disabled. 4. In DevTools > Network, set throttling to "Slow 4G" and click Next. Skeleton rows show. Then block the `deliveries` request and click Next. "Failed to retrieve deliveries" shows with a Try again button. Wait 10 seconds: no new `deliveries` requests are sent. Unblock the request and click Try again to load the rows. Also block the request while rows are loaded: they stay, and an "Unable to refresh deliveries" notice appears within about 5 seconds and clears once you unblock. 5. Open the details sheet from the bottom row of page 1. In a second tab, send a test event and wait about 5 seconds. Click Retry delivery in the first tab. A toast and a `POST .../retry` request appear, even though the row has moved off page 1. 6. Set the endpoint URL to `https://httpbin.org/delay/10` and send a test event. While the new row shows `pending` (about 10 seconds), clicking it does nothing. Once it shows `success`, it opens the sheet.
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import type { WebhookScopeParams } from './platform-webhooks-fetchers'
|
|
|
|
const scopeId = (scope: WebhookScopeParams) =>
|
|
scope.scope === 'organization' ? scope.orgSlug : scope.projectRef
|
|
|
|
export const platformWebhooksKeys = {
|
|
endpoints: (scope: WebhookScopeParams, limit?: number, offset?: number) =>
|
|
['platform-webhooks', scope.scope, scopeId(scope), 'endpoints', { limit, offset }] as const,
|
|
endpoint: (scope: WebhookScopeParams, id: string | undefined) =>
|
|
['platform-webhooks', scope.scope, scopeId(scope), 'endpoints', id] as const,
|
|
// Prefix shared by every paginated deliveries query of an endpoint. Use it to
|
|
// invalidate all pages at once, since `deliveries(...)` also embeds the cursors.
|
|
deliveriesAll: (scope: WebhookScopeParams, endpointId: string | undefined) =>
|
|
[
|
|
'platform-webhooks',
|
|
scope.scope,
|
|
scopeId(scope),
|
|
'endpoints',
|
|
endpointId,
|
|
'deliveries',
|
|
] as const,
|
|
deliveries: (
|
|
scope: WebhookScopeParams,
|
|
endpointId: string | undefined,
|
|
size?: number,
|
|
after?: string,
|
|
before?: string
|
|
) => [...platformWebhooksKeys.deliveriesAll(scope, endpointId), { size, after, before }] as const,
|
|
delivery: (scope: WebhookScopeParams, endpointId: string | undefined, id: string | undefined) =>
|
|
[
|
|
'platform-webhooks',
|
|
scope.scope,
|
|
scopeId(scope),
|
|
'endpoints',
|
|
endpointId,
|
|
'deliveries',
|
|
id,
|
|
] as const,
|
|
}
|