feat(events): add pagination, filters, sort, and page size
Extend GET /api/runs with offset/total, date and trigger filters, and configurable column sort. Rebuild Events page with URL-driven state matching the KV page pagination pattern. Co-authored-by: Nasyarobby Putra <nasyarobby@gmail.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import * as store from "../../store.js";
|
||||
|
||||
/**
|
||||
* @param {Record<string, string | undefined>} q
|
||||
*/
|
||||
export function parseRunQueryParams(q) {
|
||||
const limit = q.limit != null ? Number(q.limit) : undefined;
|
||||
const offset = q.offset != null ? Number(q.offset) : undefined;
|
||||
return {
|
||||
owner: q.owner || undefined,
|
||||
workflow: q.workflow || undefined,
|
||||
status: q.status || undefined,
|
||||
trigger_type: q.trigger || undefined,
|
||||
after: q.after || undefined,
|
||||
before: q.before || undefined,
|
||||
limit: Number.isFinite(limit) ? limit : undefined,
|
||||
offset: Number.isFinite(offset) ? offset : undefined,
|
||||
sort: q.sort || undefined,
|
||||
order: q.order || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, string | undefined>} q
|
||||
*/
|
||||
export async function queryRunsFromRequest(q) {
|
||||
return store.queryRuns(parseRunQueryParams(q));
|
||||
}
|
||||
@@ -1,20 +1,12 @@
|
||||
import * as store from "../../store.js";
|
||||
import { queryRunsFromRequest } from "./run-query.js";
|
||||
|
||||
/**
|
||||
* @param {import("fastify").FastifyInstance} fastify
|
||||
*/
|
||||
export default async function runsPlugin(fastify) {
|
||||
fastify.get("/runs", async (req) => {
|
||||
const q = /** @type {Record<string, string | undefined>} */ (req.query ?? {});
|
||||
const limit = q.limit ? Number(q.limit) : undefined;
|
||||
const runs = await store.listRuns({
|
||||
owner: q.owner,
|
||||
workflow: q.workflow,
|
||||
status: q.status,
|
||||
limit: Number.isFinite(limit) ? limit : undefined,
|
||||
before: q.before,
|
||||
});
|
||||
return { runs };
|
||||
return queryRunsFromRequest(/** @type {Record<string, string | undefined>} */ (req.query ?? {}));
|
||||
});
|
||||
|
||||
fastify.get("/consecutive-failures", async (req) => {
|
||||
|
||||
Reference in New Issue
Block a user