feat: seed dashboard, fix My tickets filter
- Add demo dashboard with 7 widgets to seed script - Dashboard is_default=true — appears as home page on fresh seed - Add views/dashboards/dashboardWidgets to seed reset - Fix My tickets: now filters by first non-system user (not any owner) - Pass owner param in sidebar My tickets link - Update page.tsx view=my to respect owner URL param - Scrip engine already sorts by sort_order (verified) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,9 @@ import {
|
||||
templates,
|
||||
tickets,
|
||||
transactions,
|
||||
views,
|
||||
dashboards,
|
||||
dashboardWidgets,
|
||||
users,
|
||||
} from './schema.ts';
|
||||
|
||||
@@ -314,6 +317,9 @@ async function resetDatabase(db: Db) {
|
||||
await db.delete(customFieldValues);
|
||||
await db.delete(transactions);
|
||||
await db.delete(queueCustomFields);
|
||||
await db.delete(dashboardWidgets);
|
||||
await db.delete(dashboards);
|
||||
await db.delete(views);
|
||||
await db.delete(scrips);
|
||||
await db.delete(templates);
|
||||
await db.delete(tickets);
|
||||
@@ -775,6 +781,56 @@ async function main() {
|
||||
})));
|
||||
|
||||
console.log(`${reset ? 'Reset and seeded' : 'Seeded'} ${demoTickets.length} demo tickets across 4 queues`);
|
||||
|
||||
// ── Dashboard seeding ──
|
||||
const dashboardViews = [
|
||||
{ name: 'Open tickets', filters: [{ field: 'status', operator: 'is', value: 'open' }] },
|
||||
{ name: 'My tickets', filters: [{ field: 'owner', operator: 'is', value: userIds.dispatcher }] },
|
||||
{ name: 'Unassigned', filters: [{ field: 'owner', operator: 'is', value: 'unassigned' }] },
|
||||
{ name: 'All tickets', filters: [] },
|
||||
];
|
||||
|
||||
const viewRecords: Record<string, string> = {};
|
||||
for (const v of dashboardViews) {
|
||||
const [row] = await db.insert(views).values({
|
||||
name: v.name,
|
||||
filters: v.filters,
|
||||
is_public: true,
|
||||
}).returning();
|
||||
if (row) viewRecords[v.name] = row.id;
|
||||
}
|
||||
|
||||
const [dashboard] = await db.insert(dashboards).values({
|
||||
name: 'Support overview',
|
||||
description: 'Daily support team dashboard',
|
||||
is_default: true,
|
||||
}).returning();
|
||||
|
||||
if (dashboard) {
|
||||
const widgetDefs = [
|
||||
{ view: 'Open tickets', type: 'count', title: 'Open tickets', x: 0, y: 0, w: 3, h: 1 },
|
||||
{ view: 'My tickets', type: 'count', title: 'My tickets', x: 3, y: 0, w: 3, h: 1 },
|
||||
{ view: 'Unassigned', type: 'count', title: 'Unassigned', x: 6, y: 0, w: 3, h: 1 },
|
||||
{ view: 'All tickets', type: 'count', title: 'Total tickets', x: 9, y: 0, w: 3, h: 1 },
|
||||
{ view: 'Open tickets', type: 'status_chart', title: 'Status breakdown', x: 0, y: 1, w: 4, h: 2 },
|
||||
{ view: 'Open tickets', type: 'ticket_list', title: 'Recent open', x: 4, y: 1, w: 5, h: 2, config: { limit: 5 } },
|
||||
{ view: 'All tickets', type: 'grouped_counts', title: 'By queue', x: 9, y: 1, w: 3, h: 2, config: { group_by: 'queue' } },
|
||||
];
|
||||
|
||||
for (const w of widgetDefs) {
|
||||
await db.insert(dashboardWidgets).values({
|
||||
dashboard_id: dashboard.id,
|
||||
view_id: viewRecords[w.view],
|
||||
title: w.title,
|
||||
widget_type: w.type,
|
||||
position: { x: w.x, y: w.y, w: w.w, h: w.h },
|
||||
config: w.config ?? {},
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Seeded dashboard "${dashboard.name}" with ${widgetDefs.length} widgets`);
|
||||
}
|
||||
|
||||
console.log('Demo data ready');
|
||||
} finally {
|
||||
await pool.end();
|
||||
|
||||
Reference in New Issue
Block a user