Skip to content

Commit cae9905

Browse files
betegonclaude
andcommitted
fix(dashboard): remove unused prepareDashboardForUpdate and stripWidgetServerFields
These functions are only needed for widget update operations (add/edit/delete), which are not part of the core dashboard commands (list, view, create). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2c4da2f commit cae9905

File tree

2 files changed

+0
-153
lines changed

2 files changed

+0
-153
lines changed

src/types/dashboard.ts

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -504,84 +504,3 @@ export function assignDefaultLayout(
504504
// No gap found — place below everything
505505
return { ...widget, layout: { x: 0, y: maxY, w, h, minH } };
506506
}
507-
508-
// ---------------------------------------------------------------------------
509-
// Server field stripping utilities
510-
// ---------------------------------------------------------------------------
511-
512-
/**
513-
* Server-generated fields on widget queries that must be stripped before PUT.
514-
* NEVER strip user-controlled fields like conditions, columns, aggregates.
515-
*/
516-
const QUERY_SERVER_FIELDS = ["id", "widgetId", "dateCreated"] as const;
517-
518-
/**
519-
* Server-generated fields on widgets that must be stripped before PUT.
520-
* CRITICAL: Never strip widgetType, displayType, or layout — these are
521-
* user-controlled and stripping them causes widgets to reset to defaults.
522-
*/
523-
const WIDGET_SERVER_FIELDS = ["id", "dashboardId", "dateCreated"] as const;
524-
525-
/**
526-
* Server-generated fields on widget layout that must be stripped before PUT.
527-
*/
528-
const LAYOUT_SERVER_FIELDS = ["isResizable"] as const;
529-
530-
/**
531-
* Strip server-generated fields from a single widget for PUT requests.
532-
*
533-
* @param widget - Widget object from GET response
534-
* @returns Widget safe for PUT (widgetType, displayType, layout preserved)
535-
*/
536-
export function stripWidgetServerFields(
537-
widget: DashboardWidget
538-
): DashboardWidget {
539-
const cleaned = { ...widget };
540-
541-
// Strip widget-level server fields
542-
for (const field of WIDGET_SERVER_FIELDS) {
543-
delete (cleaned as Record<string, unknown>)[field];
544-
}
545-
546-
// Strip query-level server fields
547-
if (cleaned.queries) {
548-
cleaned.queries = cleaned.queries.map((q) => {
549-
const cleanedQuery = { ...q };
550-
for (const field of QUERY_SERVER_FIELDS) {
551-
delete (cleanedQuery as Record<string, unknown>)[field];
552-
}
553-
return cleanedQuery;
554-
});
555-
}
556-
557-
// Strip layout server fields
558-
if (cleaned.layout) {
559-
const cleanedLayout = { ...cleaned.layout };
560-
for (const field of LAYOUT_SERVER_FIELDS) {
561-
delete (cleanedLayout as Record<string, unknown>)[field];
562-
}
563-
cleaned.layout = cleanedLayout;
564-
}
565-
566-
return cleaned;
567-
}
568-
569-
/**
570-
* Prepare a full dashboard for PUT update.
571-
* Strips server-generated fields from all widgets while preserving
572-
* widgetType, displayType, and layout.
573-
*
574-
* @param dashboard - Dashboard detail from GET response
575-
* @returns Object with title and cleaned widgets, ready for PUT body
576-
*/
577-
export function prepareDashboardForUpdate(dashboard: DashboardDetail): {
578-
title: string;
579-
widgets: DashboardWidget[];
580-
projects?: number[];
581-
} {
582-
return {
583-
title: dashboard.title,
584-
widgets: (dashboard.widgets ?? []).map(stripWidgetServerFields),
585-
projects: dashboard.projects,
586-
};
587-
}

test/types/dashboard.test.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
prepareWidgetQueries,
2424
SPAN_AGGREGATE_FUNCTIONS,
2525
SpanAggregateFunctionSchema,
26-
stripWidgetServerFields,
2726
WIDGET_TYPES,
2827
type WidgetType,
2928
} from "../../src/types/dashboard.js";
@@ -600,74 +599,3 @@ describe("assignDefaultLayout", () => {
600599
expect(result.layout!.y).toBe(0);
601600
});
602601
});
603-
604-
// ---------------------------------------------------------------------------
605-
// stripWidgetServerFields
606-
// ---------------------------------------------------------------------------
607-
608-
describe("stripWidgetServerFields", () => {
609-
test("strips id, dashboardId, dateCreated from widget", () => {
610-
const widget: DashboardWidget = {
611-
id: "100",
612-
dashboardId: "42",
613-
dateCreated: "2026-01-01T00:00:00Z",
614-
title: "Test",
615-
displayType: "line",
616-
widgetType: "spans",
617-
};
618-
const result = stripWidgetServerFields(widget);
619-
expect(result).not.toHaveProperty("id");
620-
expect(result).not.toHaveProperty("dashboardId");
621-
expect(result).not.toHaveProperty("dateCreated");
622-
expect(result.title).toBe("Test");
623-
expect(result.displayType).toBe("line");
624-
expect(result.widgetType).toBe("spans");
625-
});
626-
627-
test("strips server fields from queries", () => {
628-
const widget: DashboardWidget = {
629-
title: "Test",
630-
displayType: "line",
631-
queries: [
632-
{
633-
id: "q1",
634-
widgetId: "w1",
635-
dateCreated: "2026-01-01T00:00:00Z",
636-
aggregates: ["count()"],
637-
conditions: "",
638-
name: "Query 1",
639-
},
640-
],
641-
};
642-
const result = stripWidgetServerFields(widget);
643-
const query = result.queries![0]!;
644-
expect(query).not.toHaveProperty("id");
645-
expect(query).not.toHaveProperty("widgetId");
646-
expect(query).not.toHaveProperty("dateCreated");
647-
expect(query.aggregates).toEqual(["count()"]);
648-
expect(query.name).toBe("Query 1");
649-
});
650-
651-
test("preserves user-facing fields", () => {
652-
const widget: DashboardWidget = {
653-
title: "My Widget",
654-
displayType: "table",
655-
widgetType: "spans",
656-
layout: { x: 0, y: 0, w: 6, h: 2 },
657-
queries: [
658-
{
659-
aggregates: ["count()"],
660-
columns: ["browser.name"],
661-
conditions: "is:unresolved",
662-
name: "",
663-
},
664-
],
665-
};
666-
const result = stripWidgetServerFields(widget);
667-
expect(result.title).toBe("My Widget");
668-
expect(result.displayType).toBe("table");
669-
expect(result.widgetType).toBe("spans");
670-
expect(result.layout).toBeDefined();
671-
expect(result.queries![0]!.conditions).toBe("is:unresolved");
672-
});
673-
});

0 commit comments

Comments
 (0)