-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathapi.v1.query.dashboards._index.ts
More file actions
54 lines (48 loc) · 1.58 KB
/
api.v1.query.dashboards._index.ts
File metadata and controls
54 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { json } from "@remix-run/server-runtime";
import type { DashboardSummary, DashboardWidgetSummary } from "@trigger.dev/core/v3/schemas";
import type { BuiltInDashboard } from "~/presenters/v3/MetricDashboardPresenter.server";
import { createLoaderApiRoute } from "~/services/routeBuilders/apiBuilder.server";
import { builtInDashboard } from "~/presenters/v3/BuiltInDashboards.server";
const BUILT_IN_DASHBOARD_KEYS = ["overview", "llm"];
function serializeDashboard(dashboard: BuiltInDashboard): DashboardSummary {
const widgets: DashboardWidgetSummary[] = [];
if (dashboard.layout.version === "1") {
for (const [id, widget] of Object.entries(dashboard.layout.widgets)) {
// Skip title widgets — they're just section headers
if (widget.display.type === "title") continue;
widgets.push({
id,
title: widget.title,
query: widget.query,
type: widget.display.type,
});
}
}
return {
key: dashboard.key,
title: dashboard.title,
widgets,
};
}
export const loader = createLoaderApiRoute(
{
allowJWT: true,
corsStrategy: "all",
findResource: async () => 1,
authorization: {
action: "read",
resource: () => ({ query: "dashboards" }),
superScopes: ["read:query", "read:all", "admin"],
},
},
async () => {
const dashboards = BUILT_IN_DASHBOARD_KEYS.map((key) => {
try {
return serializeDashboard(builtInDashboard(key));
} catch {
return null;
}
}).filter((d): d is DashboardSummary => d !== null);
return json({ dashboards });
}
);