Skip to content

Open-source status page, incident response and uptime monitoring

Preserve pageId when clearing status report component associations (#2144)

Maximilian Kaske8cd8250d6acb
diff --git a/apps/dashboard/src/components/data-table/status-reports/data-table-row-actions.tsx b/apps/dashboard/src/components/data-table/status-reports/data-table-row-actions.tsx
index 9cd445c02..e57b46764 100644
--- a/apps/dashboard/src/components/data-table/status-reports/data-table-row-actions.tsx
+++ b/apps/dashboard/src/components/data-table/status-reports/data-table-row-actions.tsx
@@ -135,9 +135,12 @@ export function DataTableRowActions({ row }: DataTableRowActionsProps) {
pageComponents: row.original.pageComponents?.map((c) => c.id) ?? [],
}}
onSubmit={async (values) => {
+ const hasComponents =
+ (page?.pageComponents?.length ?? 0) > 0 ||
+ (page?.pageComponentGroups?.length ?? 0) > 0;
await updateStatusReportMutation.mutateAsync({
id: row.original.id,
- pageComponents: values.pageComponents,
+ pageComponents: hasComponents ? values.pageComponents : undefined,
title: values.title,
status: values.status,
});
diff --git a/apps/server/src/routes/rpc/handlers/status-report/__tests__/status-report.test.ts b/apps/server/src/routes/rpc/handlers/status-report/__tests__/status-report.test.ts
index 5ff15060a..591bb4e17 100644
--- a/apps/server/src/routes/rpc/handlers/status-report/__tests__/status-report.test.ts
+++ b/apps/server/src/routes/rpc/handlers/status-report/__tests__/status-report.test.ts
@@ -1127,7 +1127,7 @@ describe("StatusReportService.UpdateStatusReport", () => {
);
});
- test("clears pageId when removing all components", async () => {
+ test("clears component associations but preserves pageId when removing all components", async () => {
// Create a temporary status report for this test
const tempReport = await db
.insert(statusReport)
@@ -1159,13 +1159,19 @@ describe("StatusReportService.UpdateStatusReport", () => {
expect(res.status).toBe(200);
- // Verify the pageId is now null
const afterReport = await db
.select()
.from(statusReport)
.where(eq(statusReport.id, tempReport.id))
.get();
- expect(afterReport?.pageId).toBeNull();
+ expect(afterReport?.pageId).toBe(1);
+
+ const afterAssoc = await db
+ .select()
+ .from(statusReportsToPageComponents)
+ .where(eq(statusReportsToPageComponents.statusReportId, tempReport.id))
+ .all();
+ expect(afterAssoc).toHaveLength(0);
} finally {
// Clean up
await db
diff --git a/packages/api/src/router/statusReport.ts b/packages/api/src/router/statusReport.ts
index f10e38a2a..6c5c690df 100644
--- a/packages/api/src/router/statusReport.ts
+++ b/packages/api/src/router/statusReport.ts
@@ -50,7 +50,7 @@ const updateStatusReportUpdateTRPCInput = z.object({
const updateStatusTRPCInput = z.object({
id: z.number(),
- pageComponents: z.array(z.number()),
+ pageComponents: z.array(z.number()).optional(),
title: z.string(),
status: CreateStatusReportInput.shape.status,
});
diff --git a/packages/services/src/status-report/__tests__/status-report.test.ts b/packages/services/src/status-report/__tests__/status-report.test.ts
index 657515196..d60307541 100644
--- a/packages/services/src/status-report/__tests__/status-report.test.ts
+++ b/packages/services/src/status-report/__tests__/status-report.test.ts
@@ -332,6 +332,7 @@ describe("updateStatusReport", () => {
.where(eq(statusReportsToPageComponents.statusReportId, report.id))
.all();
expect(assoc).toHaveLength(0);
+ expect(updated.pageId).toBe(testPageId);
});
});
});
diff --git a/packages/services/src/status-report/update.ts b/packages/services/src/status-report/update.ts
index fe1efd120..b13e0ed8e 100644
--- a/packages/services/src/status-report/update.ts
+++ b/packages/services/src/status-report/update.ts
@@ -20,14 +20,12 @@ import {
/**
* Update status-report metadata (title / status) and optionally replace the
* full set of page-component associations. Passing
- * `pageComponentIds: []` clears the associations (and nulls `pageId`);
- * omitting the field leaves both untouched.
+ * `pageComponentIds: []` clears the associations but leaves `pageId`
+ * untouched; omitting the field leaves both untouched.
*
- * The report's `pageId` follows its components: when the caller supplies
- * a new set of associations the report moves to whatever page those
- * components live on. Mixed-page inputs are rejected upstream by
- * `validatePageComponentIds` (all ids must share a page), so the only
- * states here are "one page" or "no components".
+ * A non-empty set moves the report to whatever page those components live
+ * on. Mixed-page inputs are rejected upstream by `validatePageComponentIds`
+ * (all ids must share a page).
*/
export async function updateStatusReport(args: {
ctx: ServiceContext;
@@ -55,12 +53,9 @@ export async function updateStatusReport(args: {
pageComponentIds: input.pageComponentIds,
});
- // `pageId` follows the association set: a new non-empty set moves
- // the report to that page; an empty set nulls it. This is the
- // behavior the Connect `UpdateStatusReport` tests have encoded
- // since the original handler — no caller today wants a "report
- // pinned to page X regardless of its components" guarantee.
- updateValues.pageId = validated.pageId;
+ if (validated.pageId !== null) {
+ updateValues.pageId = validated.pageId;
+ }
await updatePageComponentAssociations({
tx,