Separate data requests from website feedback in the admin
Forms now has two queues, Website feedback and Data requests, each its own card on the admin home and a tab on the page, with what's new in each. The API takes ?kind=feedback|privacy and counts per queue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7c1723b0ad
commit
99d83eb090
5 changed files with 69 additions and 12 deletions
|
|
@ -23,6 +23,8 @@ const NOTE_LIMIT = 2000;
|
|||
|
||||
/* ── GET /api/admin/feedback ─────────────────────────────────────
|
||||
?status=new one of STATUSES, or omitted for all
|
||||
?kind=feedback website feedback (every type but 'privacy')
|
||||
?kind=privacy data requests from the Privacy page
|
||||
?type=broken feedback_type
|
||||
?q=retreat substring of the message
|
||||
?before=41 cursor: rows with a lower id than this
|
||||
|
|
@ -31,11 +33,17 @@ const NOTE_LIMIT = 2000;
|
|||
|
||||
admin.get("/feedback", (c) => {
|
||||
const db = c.get("db");
|
||||
const { status, type, q, before, limit } = c.req.query();
|
||||
const { status, type, kind, q, before, limit } = c.req.query();
|
||||
|
||||
const where = [];
|
||||
const params = [];
|
||||
|
||||
// Data requests and website feedback share the table but are two
|
||||
// queues in the admin (Forms → Website feedback, Data requests).
|
||||
const kindWhere =
|
||||
kind === "privacy" ? "feedback_type = 'privacy'" : kind === "feedback" ? "feedback_type <> 'privacy'" : null;
|
||||
if (kindWhere) where.push(kindWhere);
|
||||
|
||||
if (STATUSES.includes(status)) {
|
||||
where.push("status = ?");
|
||||
params.push(status);
|
||||
|
|
@ -69,19 +77,27 @@ admin.get("/feedback", (c) => {
|
|||
const hasMore = rows.length > take;
|
||||
const page = hasMore ? rows.slice(0, take) : rows;
|
||||
|
||||
// Counts are unfiltered on purpose: the tabs should show what's
|
||||
// waiting overall, not what's left after the current filter.
|
||||
// Status counts cover this queue (kind) but ignore the other
|
||||
// filters: the tabs show what's waiting, not what's left after a
|
||||
// search. newByKind is what's new in each queue, for the queue tabs.
|
||||
const counts = Object.fromEntries(STATUSES.map((s) => [s, 0]));
|
||||
for (const row of db
|
||||
.prepare("SELECT status, COUNT(*) AS n FROM feedback GROUP BY status")
|
||||
.prepare(`SELECT status, COUNT(*) AS n FROM feedback ${kindWhere ? `WHERE ${kindWhere}` : ""} GROUP BY status`)
|
||||
.all()) {
|
||||
counts[row.status] = row.n;
|
||||
}
|
||||
const newByKind = db
|
||||
.prepare(
|
||||
`SELECT SUM(feedback_type <> 'privacy') AS feedback, SUM(feedback_type = 'privacy') AS privacy
|
||||
FROM feedback WHERE status = 'new'`,
|
||||
)
|
||||
.get();
|
||||
|
||||
return c.json(
|
||||
{
|
||||
feedback: page,
|
||||
counts,
|
||||
newByKind: { feedback: newByKind?.feedback ?? 0, privacy: newByKind?.privacy ?? 0 },
|
||||
nextCursor: hasMore ? page[page.length - 1].id : null,
|
||||
},
|
||||
200,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue