@burdenoff/microfe-movethewheels 2026.1102.2 → 2026.1107.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MoveTheWheelsRoot.js +148 -140
- package/dist/MoveTheWheelsRoutes.js +29 -25
- package/dist/generated/tracking-quality-operations.d.ts +467 -1
- package/dist/generated/wspace-types.d.ts +9779 -330
- package/dist/movethewheels/pages/ReportsPage.d.ts +1 -0
- package/dist/movethewheels/utils/reports.d.ts +132 -0
- package/dist/node_modules/lucide-react/dist/esm/icons/file-chart-column-increasing.js +26 -0
- package/dist/pages/ReportsPage.js +721 -0
- package/dist/utils/reports.js +202 -0
- package/package.json +3 -2
- package/src/generated/tracking-quality-operations.ts +569 -1
- package/src/generated/wspace-types.ts +11263 -380
- package/src/movethewheels/MoveTheWheelsRoot.tsx +8 -0
- package/src/movethewheels/MoveTheWheelsRoutes.tsx +4 -0
- package/src/movethewheels/pages/ReportsPage.tsx +999 -0
- package/src/movethewheels/utils/reports.ts +419 -0
|
@@ -0,0 +1,999 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports Page (BOFF-3989)
|
|
3
|
+
*
|
|
4
|
+
* Saved MoveTheWheels reports over the workspace's own data: operations,
|
|
5
|
+
* finance, fleet, customers and inventory. A report is generated on demand or
|
|
6
|
+
* on a daily, weekly or monthly schedule; every generation is kept as a run
|
|
7
|
+
* with its headline figures and detail rows, previewed here and downloadable
|
|
8
|
+
* as CSV or JSON.
|
|
9
|
+
*/
|
|
10
|
+
import { useCallback, useEffect, useMemo, useState, type FormEvent } from 'react';
|
|
11
|
+
import {
|
|
12
|
+
CalendarClock,
|
|
13
|
+
Download,
|
|
14
|
+
FileBarChart,
|
|
15
|
+
Loader2,
|
|
16
|
+
Pencil,
|
|
17
|
+
Play,
|
|
18
|
+
Plus,
|
|
19
|
+
RefreshCw,
|
|
20
|
+
Trash2,
|
|
21
|
+
} from 'lucide-react';
|
|
22
|
+
import { EmphasisPanel, PagePurpose } from '@burdenoff/fe-libs/ui';
|
|
23
|
+
import { PermissionProvider, usePermissions } from '@burdenoff/fe-libs/shared/providers/shell';
|
|
24
|
+
import { clearGraphqlFetchResponseCache } from '@burdenoff/fe-libs/shared/graphql';
|
|
25
|
+
import { PageLayout } from '../components/PageLayout';
|
|
26
|
+
import { FormError } from '../components/FormError';
|
|
27
|
+
import { Notice, useNotice } from '../components/Notice';
|
|
28
|
+
import {
|
|
29
|
+
Badge,
|
|
30
|
+
Button,
|
|
31
|
+
Card,
|
|
32
|
+
CardContent,
|
|
33
|
+
CardDescription,
|
|
34
|
+
CardHeader,
|
|
35
|
+
CardTitle,
|
|
36
|
+
Dialog,
|
|
37
|
+
DialogContent,
|
|
38
|
+
DialogDescription,
|
|
39
|
+
DialogFooter,
|
|
40
|
+
DialogHeader,
|
|
41
|
+
DialogTitle,
|
|
42
|
+
Input,
|
|
43
|
+
Label,
|
|
44
|
+
Select,
|
|
45
|
+
SelectContent,
|
|
46
|
+
SelectItem,
|
|
47
|
+
SelectTrigger,
|
|
48
|
+
SelectValue,
|
|
49
|
+
Skeleton,
|
|
50
|
+
Switch,
|
|
51
|
+
Table,
|
|
52
|
+
TableBody,
|
|
53
|
+
TableCell,
|
|
54
|
+
TableHead,
|
|
55
|
+
TableHeader,
|
|
56
|
+
TableRow,
|
|
57
|
+
Textarea,
|
|
58
|
+
} from '../components/ui';
|
|
59
|
+
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
60
|
+
import { useModuleSettings } from '../providers/ModuleSettingsProvider';
|
|
61
|
+
import { executeGraphQL } from '../utils/graphqlClient';
|
|
62
|
+
import {
|
|
63
|
+
formatCurrency,
|
|
64
|
+
formatDate,
|
|
65
|
+
formatDateTime,
|
|
66
|
+
formatDistance,
|
|
67
|
+
formatWeight,
|
|
68
|
+
} from '../utils/formatters';
|
|
69
|
+
import {
|
|
70
|
+
CREATE_MTW_REPORT_MUTATION,
|
|
71
|
+
DELETE_MTW_REPORT_MUTATION,
|
|
72
|
+
FREQUENCY_OPTIONS,
|
|
73
|
+
GENERATE_MTW_REPORT_MUTATION,
|
|
74
|
+
MTW_REPORTS_QUERY,
|
|
75
|
+
MTW_REPORT_RUNS_QUERY,
|
|
76
|
+
MTW_REPORT_RUN_EXPORT_QUERY,
|
|
77
|
+
MTW_REPORT_RUN_QUERY,
|
|
78
|
+
PERIOD_DAYS_MAX,
|
|
79
|
+
PERIOD_DAYS_MIN,
|
|
80
|
+
PREVIEW_ROWS,
|
|
81
|
+
REPORT_TYPE_OPTIONS,
|
|
82
|
+
UPDATE_MTW_REPORT_MUTATION,
|
|
83
|
+
WEEKDAY_LABELS,
|
|
84
|
+
formatCell,
|
|
85
|
+
formatMetric,
|
|
86
|
+
metricLabel,
|
|
87
|
+
newReportInput,
|
|
88
|
+
reportInputError,
|
|
89
|
+
reportToInput,
|
|
90
|
+
reportTypeLabel,
|
|
91
|
+
scheduleSummary,
|
|
92
|
+
suggestedPeriodDays,
|
|
93
|
+
toServiceInput,
|
|
94
|
+
type MtwReport,
|
|
95
|
+
type MtwReportExport,
|
|
96
|
+
type MtwReportFormat,
|
|
97
|
+
type MtwReportFrequency,
|
|
98
|
+
type MtwReportInput,
|
|
99
|
+
type MtwReportRunDetail,
|
|
100
|
+
type MtwReportRunSummary,
|
|
101
|
+
type MtwReportType,
|
|
102
|
+
} from '../utils/reports';
|
|
103
|
+
|
|
104
|
+
const METRIC_FORMATTERS = {
|
|
105
|
+
currency: formatCurrency,
|
|
106
|
+
distance: formatDistance,
|
|
107
|
+
weight: formatWeight,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
function downloadText(fileName: string, text: string, type: string): void {
|
|
111
|
+
const url = URL.createObjectURL(new Blob([text], { type }));
|
|
112
|
+
const anchor = document.createElement('a');
|
|
113
|
+
anchor.href = url;
|
|
114
|
+
anchor.download = fileName;
|
|
115
|
+
document.body.appendChild(anchor);
|
|
116
|
+
anchor.click();
|
|
117
|
+
anchor.remove();
|
|
118
|
+
URL.revokeObjectURL(url);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function message(caught: unknown, fallback: string): string {
|
|
122
|
+
return caught instanceof Error && caught.message ? caught.message : fallback;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function statusVariant(status: string | null): 'default' | 'outline' | 'destructive' | 'secondary' {
|
|
126
|
+
if (status === 'COMPLETED') return 'default';
|
|
127
|
+
if (status === 'FAILED') return 'destructive';
|
|
128
|
+
if (status === 'RUNNING') return 'secondary';
|
|
129
|
+
return 'outline';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function periodLabel(run: Pick<MtwReportRunSummary, 'periodStart' | 'periodEnd'>): string {
|
|
133
|
+
return `${formatDateTime(run.periodStart)} – ${formatDateTime(run.periodEnd)}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export default function ReportsPage() {
|
|
137
|
+
const { workspaceId } = useMoveTheWheels();
|
|
138
|
+
return (
|
|
139
|
+
<PermissionProvider scopeId={workspaceId ?? null} gateway="workspace">
|
|
140
|
+
<ReportsWorkbench />
|
|
141
|
+
</PermissionProvider>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function ReportsWorkbench() {
|
|
146
|
+
const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
|
|
147
|
+
useMoveTheWheels();
|
|
148
|
+
const { settings } = useModuleSettings();
|
|
149
|
+
const permissions = usePermissions();
|
|
150
|
+
const graphQLOptions = useMemo(
|
|
151
|
+
() => ({
|
|
152
|
+
apiGatewayUrl,
|
|
153
|
+
authToken,
|
|
154
|
+
workspaceToken,
|
|
155
|
+
workspaceId,
|
|
156
|
+
tenantId,
|
|
157
|
+
actorId: currentUser?.id,
|
|
158
|
+
}),
|
|
159
|
+
[apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const [reports, setReports] = useState<MtwReport[]>([]);
|
|
163
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
164
|
+
const [loadError, setLoadError] = useState<string | null>(null);
|
|
165
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
166
|
+
const [runs, setRuns] = useState<MtwReportRunSummary[]>([]);
|
|
167
|
+
const [run, setRun] = useState<MtwReportRunDetail | null>(null);
|
|
168
|
+
const [isRunLoading, setIsRunLoading] = useState(false);
|
|
169
|
+
const [busy, setBusy] = useState<string | null>(null);
|
|
170
|
+
const [actionError, setActionError] = useState<string | null>(null);
|
|
171
|
+
const [editing, setEditing] = useState<MtwReport | 'new' | null>(null);
|
|
172
|
+
const [deleting, setDeleting] = useState<MtwReport | null>(null);
|
|
173
|
+
const [reloadKey, setReloadKey] = useState(0);
|
|
174
|
+
// Re-read the reports after a write or an explicit refresh. The shell answers a
|
|
175
|
+
// repeated query from a short-lived response cache while the page is loading,
|
|
176
|
+
// so clear it first; otherwise a report created right after the page opened
|
|
177
|
+
// would be missing from the refreshed list and the selection would fall back
|
|
178
|
+
// to another report.
|
|
179
|
+
const reloadReports = useCallback(() => {
|
|
180
|
+
clearGraphqlFetchResponseCache();
|
|
181
|
+
setReloadKey((key) => key + 1);
|
|
182
|
+
}, []);
|
|
183
|
+
const { message: notice, notify } = useNotice();
|
|
184
|
+
|
|
185
|
+
const permissionsReady = Boolean(
|
|
186
|
+
workspaceId &&
|
|
187
|
+
currentUser?.id &&
|
|
188
|
+
permissions.scopeId === workspaceId &&
|
|
189
|
+
!permissions.isLoading &&
|
|
190
|
+
!permissions.error
|
|
191
|
+
);
|
|
192
|
+
// Only hide an action when the effective permissions positively say no; the
|
|
193
|
+
// service enforces mtw-report permissions either way.
|
|
194
|
+
const can = useCallback(
|
|
195
|
+
(action: 'create' | 'update' | 'delete' | 'generate') =>
|
|
196
|
+
!permissionsReady ||
|
|
197
|
+
permissions.isSuperAdmin ||
|
|
198
|
+
permissions.hasPermission(`mtw-report:${action}`),
|
|
199
|
+
[permissionsReady, permissions]
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const selected = reports.find((report) => report.id === selectedId) ?? null;
|
|
203
|
+
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (!graphQLOptions.workspaceId) return;
|
|
206
|
+
let cancelled = false;
|
|
207
|
+
setIsLoading(true);
|
|
208
|
+
executeGraphQL<{ mtwReports: MtwReport[] }>(graphQLOptions, MTW_REPORTS_QUERY, {
|
|
209
|
+
pagination: { limit: 100 },
|
|
210
|
+
})
|
|
211
|
+
.then((data) => {
|
|
212
|
+
if (cancelled) return;
|
|
213
|
+
setReports(data.mtwReports);
|
|
214
|
+
setLoadError(null);
|
|
215
|
+
setSelectedId((current) =>
|
|
216
|
+
current && data.mtwReports.some((report) => report.id === current)
|
|
217
|
+
? current
|
|
218
|
+
: (data.mtwReports[0]?.id ?? null)
|
|
219
|
+
);
|
|
220
|
+
})
|
|
221
|
+
.catch((caught: unknown) => {
|
|
222
|
+
if (!cancelled) setLoadError(message(caught, 'Could not load the reports'));
|
|
223
|
+
})
|
|
224
|
+
.finally(() => {
|
|
225
|
+
if (!cancelled) setIsLoading(false);
|
|
226
|
+
});
|
|
227
|
+
return () => {
|
|
228
|
+
cancelled = true;
|
|
229
|
+
};
|
|
230
|
+
}, [graphQLOptions, reloadKey]);
|
|
231
|
+
|
|
232
|
+
const loadRun = useCallback(
|
|
233
|
+
async (runId: string) => {
|
|
234
|
+
setIsRunLoading(true);
|
|
235
|
+
try {
|
|
236
|
+
const data = await executeGraphQL<{ mtwReportRun: MtwReportRunDetail | null }>(
|
|
237
|
+
graphQLOptions,
|
|
238
|
+
MTW_REPORT_RUN_QUERY,
|
|
239
|
+
{ id: runId, rows: { limit: PREVIEW_ROWS } }
|
|
240
|
+
);
|
|
241
|
+
setRun(data.mtwReportRun);
|
|
242
|
+
} catch (caught) {
|
|
243
|
+
setActionError(message(caught, 'Could not load the report run'));
|
|
244
|
+
} finally {
|
|
245
|
+
setIsRunLoading(false);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
[graphQLOptions]
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
// Load the selected report's run history and its latest run.
|
|
252
|
+
const latestRunId = selected?.latestRun?.id ?? null;
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
setRuns([]);
|
|
255
|
+
setRun(null);
|
|
256
|
+
if (!selectedId) return;
|
|
257
|
+
let cancelled = false;
|
|
258
|
+
executeGraphQL<{ mtwReportRuns: MtwReportRunSummary[] }>(
|
|
259
|
+
graphQLOptions,
|
|
260
|
+
MTW_REPORT_RUNS_QUERY,
|
|
261
|
+
{ reportId: selectedId, pagination: { limit: 30 } }
|
|
262
|
+
)
|
|
263
|
+
.then((data) => {
|
|
264
|
+
if (!cancelled) setRuns(data.mtwReportRuns);
|
|
265
|
+
})
|
|
266
|
+
.catch((caught: unknown) => {
|
|
267
|
+
if (!cancelled) setActionError(message(caught, 'Could not load the run history'));
|
|
268
|
+
});
|
|
269
|
+
if (latestRunId) void loadRun(latestRunId);
|
|
270
|
+
return () => {
|
|
271
|
+
cancelled = true;
|
|
272
|
+
};
|
|
273
|
+
}, [graphQLOptions, selectedId, latestRunId, loadRun]);
|
|
274
|
+
|
|
275
|
+
const generate = async (report: MtwReport) => {
|
|
276
|
+
setBusy(`generate:${report.id}`);
|
|
277
|
+
setActionError(null);
|
|
278
|
+
try {
|
|
279
|
+
const data = await executeGraphQL<{ generateMtwReport: MtwReportRunSummary }>(
|
|
280
|
+
graphQLOptions,
|
|
281
|
+
GENERATE_MTW_REPORT_MUTATION,
|
|
282
|
+
{ id: report.id },
|
|
283
|
+
'SINGLE_ATTEMPT'
|
|
284
|
+
);
|
|
285
|
+
const generated = data.generateMtwReport;
|
|
286
|
+
if (generated.status === 'COMPLETED') notify(`"${report.name}" generated.`);
|
|
287
|
+
else setActionError(generated.error ?? 'The report could not be generated.');
|
|
288
|
+
setSelectedId(report.id);
|
|
289
|
+
reloadReports();
|
|
290
|
+
} catch (caught) {
|
|
291
|
+
setActionError(message(caught, 'Could not generate the report'));
|
|
292
|
+
} finally {
|
|
293
|
+
setBusy(null);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const download = async (runId: string, format: MtwReportFormat) => {
|
|
298
|
+
setBusy(`download:${runId}:${format}`);
|
|
299
|
+
setActionError(null);
|
|
300
|
+
try {
|
|
301
|
+
const data = await executeGraphQL<{ mtwReportRunExport: MtwReportExport }>(
|
|
302
|
+
graphQLOptions,
|
|
303
|
+
MTW_REPORT_RUN_EXPORT_QUERY,
|
|
304
|
+
{ runId, format }
|
|
305
|
+
);
|
|
306
|
+
const file = data.mtwReportRunExport;
|
|
307
|
+
downloadText(file.filename, file.content, file.contentType);
|
|
308
|
+
} catch (caught) {
|
|
309
|
+
setActionError(message(caught, 'Could not download the report'));
|
|
310
|
+
} finally {
|
|
311
|
+
setBusy(null);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const remove = async (report: MtwReport) => {
|
|
316
|
+
setBusy(`delete:${report.id}`);
|
|
317
|
+
setActionError(null);
|
|
318
|
+
try {
|
|
319
|
+
await executeGraphQL<{ deleteMtwReport: boolean }>(
|
|
320
|
+
graphQLOptions,
|
|
321
|
+
DELETE_MTW_REPORT_MUTATION,
|
|
322
|
+
{ id: report.id },
|
|
323
|
+
'SINGLE_ATTEMPT'
|
|
324
|
+
);
|
|
325
|
+
notify(`"${report.name}" deleted.`);
|
|
326
|
+
setDeleting(null);
|
|
327
|
+
if (selectedId === report.id) setSelectedId(null);
|
|
328
|
+
reloadReports();
|
|
329
|
+
} catch (caught) {
|
|
330
|
+
setActionError(message(caught, 'Could not delete the report'));
|
|
331
|
+
} finally {
|
|
332
|
+
setBusy(null);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const save = async (input: MtwReportInput, report: MtwReport | null) => {
|
|
337
|
+
const data = report
|
|
338
|
+
? await executeGraphQL<{ updateMtwReport: MtwReport }>(
|
|
339
|
+
graphQLOptions,
|
|
340
|
+
UPDATE_MTW_REPORT_MUTATION,
|
|
341
|
+
{ id: report.id, input: toServiceInput(input) },
|
|
342
|
+
'SINGLE_ATTEMPT'
|
|
343
|
+
).then((result) => result.updateMtwReport)
|
|
344
|
+
: await executeGraphQL<{ createMtwReport: MtwReport }>(
|
|
345
|
+
graphQLOptions,
|
|
346
|
+
CREATE_MTW_REPORT_MUTATION,
|
|
347
|
+
{ input: toServiceInput(input) },
|
|
348
|
+
'SINGLE_ATTEMPT'
|
|
349
|
+
).then((result) => result.createMtwReport);
|
|
350
|
+
notify(report ? `"${data.name}" saved.` : `"${data.name}" created.`);
|
|
351
|
+
setEditing(null);
|
|
352
|
+
setSelectedId(data.id);
|
|
353
|
+
reloadReports();
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
return (
|
|
357
|
+
<PageLayout
|
|
358
|
+
title="Reports"
|
|
359
|
+
subtitle="Scheduled and on-demand reports over your logistics data"
|
|
360
|
+
icon={<FileBarChart size={24} />}
|
|
361
|
+
maxWidth="full"
|
|
362
|
+
headerActions={
|
|
363
|
+
<div className="flex flex-wrap gap-2">
|
|
364
|
+
<Button variant="outline" onClick={reloadReports}>
|
|
365
|
+
<RefreshCw size={16} className="mr-2" /> Refresh
|
|
366
|
+
</Button>
|
|
367
|
+
{can('create') && (
|
|
368
|
+
<Button onClick={() => setEditing('new')}>
|
|
369
|
+
<Plus size={16} className="mr-2" /> New report
|
|
370
|
+
</Button>
|
|
371
|
+
)}
|
|
372
|
+
</div>
|
|
373
|
+
}
|
|
374
|
+
>
|
|
375
|
+
<PagePurpose icon={<FileBarChart size={18} />}>
|
|
376
|
+
Save the reports you need and generate them whenever you like, or have them generated every
|
|
377
|
+
day, week or month. Each generation keeps its figures and rows so you can compare periods
|
|
378
|
+
and download them as CSV or JSON.
|
|
379
|
+
</PagePurpose>
|
|
380
|
+
|
|
381
|
+
{loadError && <FormError message={loadError} />}
|
|
382
|
+
<FormError message={actionError} />
|
|
383
|
+
<Notice message={notice} />
|
|
384
|
+
|
|
385
|
+
<div className="grid grid-cols-1 gap-6 xl:grid-cols-3">
|
|
386
|
+
<EmphasisPanel className="space-y-3 xl:col-span-1">
|
|
387
|
+
<h2 className="text-base font-semibold text-text-primary">Saved reports</h2>
|
|
388
|
+
{isLoading && reports.length === 0 ? (
|
|
389
|
+
<div className="space-y-3" aria-busy="true">
|
|
390
|
+
<Skeleton className="h-16 w-full" />
|
|
391
|
+
<Skeleton className="h-16 w-full" />
|
|
392
|
+
</div>
|
|
393
|
+
) : reports.length === 0 ? (
|
|
394
|
+
<div className="rounded-lg border border-dashed border-border-default p-6 text-center text-sm text-text-secondary">
|
|
395
|
+
<p>No reports yet.</p>
|
|
396
|
+
{can('create') && (
|
|
397
|
+
<Button className="mt-4" onClick={() => setEditing('new')}>
|
|
398
|
+
<Plus size={16} className="mr-2" /> Create your first report
|
|
399
|
+
</Button>
|
|
400
|
+
)}
|
|
401
|
+
</div>
|
|
402
|
+
) : (
|
|
403
|
+
<ul className="space-y-2" aria-label="Saved reports">
|
|
404
|
+
{reports.map((report) => (
|
|
405
|
+
<li key={report.id}>
|
|
406
|
+
<button
|
|
407
|
+
type="button"
|
|
408
|
+
onClick={() => setSelectedId(report.id)}
|
|
409
|
+
aria-current={report.id === selectedId ? 'true' : undefined}
|
|
410
|
+
className={`w-full rounded-lg border px-3 py-2 text-left transition-colors ${
|
|
411
|
+
report.id === selectedId
|
|
412
|
+
? 'border-border-primary bg-surface-secondary'
|
|
413
|
+
: 'border-border-default hover:bg-surface-secondary'
|
|
414
|
+
}`}
|
|
415
|
+
>
|
|
416
|
+
<span className="flex items-center justify-between gap-2">
|
|
417
|
+
<span className="truncate text-sm font-medium text-text-primary">
|
|
418
|
+
{report.name}
|
|
419
|
+
</span>
|
|
420
|
+
<Badge variant="outline">{reportTypeLabel(report.type)}</Badge>
|
|
421
|
+
</span>
|
|
422
|
+
<span className="mt-1 block text-xs text-text-secondary">
|
|
423
|
+
{scheduleSummary(report)}
|
|
424
|
+
</span>
|
|
425
|
+
<span className="mt-1 block text-xs text-text-tertiary">
|
|
426
|
+
{report.lastGeneratedAt
|
|
427
|
+
? `Last generated ${formatDateTime(report.lastGeneratedAt)}`
|
|
428
|
+
: 'Never generated'}
|
|
429
|
+
</span>
|
|
430
|
+
</button>
|
|
431
|
+
</li>
|
|
432
|
+
))}
|
|
433
|
+
</ul>
|
|
434
|
+
)}
|
|
435
|
+
</EmphasisPanel>
|
|
436
|
+
|
|
437
|
+
<div className="space-y-6 xl:col-span-2">
|
|
438
|
+
{!selected ? (
|
|
439
|
+
!isLoading && (
|
|
440
|
+
<Card>
|
|
441
|
+
<CardContent className="p-6 text-sm text-text-secondary">
|
|
442
|
+
Select a report to see its latest figures and run history.
|
|
443
|
+
</CardContent>
|
|
444
|
+
</Card>
|
|
445
|
+
)
|
|
446
|
+
) : (
|
|
447
|
+
<>
|
|
448
|
+
<Card>
|
|
449
|
+
<CardHeader className="flex flex-row flex-wrap items-start justify-between gap-3">
|
|
450
|
+
<div className="min-w-0 space-y-1">
|
|
451
|
+
<CardTitle className="text-lg">{selected.name}</CardTitle>
|
|
452
|
+
<CardDescription>
|
|
453
|
+
{selected.description ||
|
|
454
|
+
REPORT_TYPE_OPTIONS.find((option) => option.value === selected.type)
|
|
455
|
+
?.description}
|
|
456
|
+
</CardDescription>
|
|
457
|
+
<p className="flex flex-wrap items-center gap-2 text-xs text-text-secondary">
|
|
458
|
+
<CalendarClock size={14} />
|
|
459
|
+
<span>{scheduleSummary(selected)}</span>
|
|
460
|
+
<span>· Covers the last {selected.periodDays} day(s)</span>
|
|
461
|
+
{selected.nextRunAt && (
|
|
462
|
+
<span>· Next run {formatDateTime(selected.nextRunAt)}</span>
|
|
463
|
+
)}
|
|
464
|
+
</p>
|
|
465
|
+
</div>
|
|
466
|
+
<div className="flex flex-wrap gap-2">
|
|
467
|
+
{can('generate') && (
|
|
468
|
+
<Button
|
|
469
|
+
onClick={() => void generate(selected)}
|
|
470
|
+
disabled={busy !== null}
|
|
471
|
+
aria-label={`Generate ${selected.name} now`}
|
|
472
|
+
>
|
|
473
|
+
{busy === `generate:${selected.id}` ? (
|
|
474
|
+
<Loader2 size={16} className="mr-2 animate-spin" />
|
|
475
|
+
) : (
|
|
476
|
+
<Play size={16} className="mr-2" />
|
|
477
|
+
)}
|
|
478
|
+
Generate now
|
|
479
|
+
</Button>
|
|
480
|
+
)}
|
|
481
|
+
{can('update') && (
|
|
482
|
+
<Button
|
|
483
|
+
variant="outline"
|
|
484
|
+
onClick={() => setEditing(selected)}
|
|
485
|
+
disabled={busy !== null}
|
|
486
|
+
>
|
|
487
|
+
<Pencil size={16} className="mr-2" /> Edit
|
|
488
|
+
</Button>
|
|
489
|
+
)}
|
|
490
|
+
{can('delete') && (
|
|
491
|
+
<Button
|
|
492
|
+
variant="outline"
|
|
493
|
+
onClick={() => setDeleting(selected)}
|
|
494
|
+
disabled={busy !== null}
|
|
495
|
+
aria-label={`Delete ${selected.name}`}
|
|
496
|
+
>
|
|
497
|
+
<Trash2 size={16} />
|
|
498
|
+
</Button>
|
|
499
|
+
)}
|
|
500
|
+
</div>
|
|
501
|
+
</CardHeader>
|
|
502
|
+
</Card>
|
|
503
|
+
|
|
504
|
+
<RunDetail
|
|
505
|
+
run={run}
|
|
506
|
+
isLoading={isRunLoading}
|
|
507
|
+
hasRuns={Boolean(selected.latestRun)}
|
|
508
|
+
busy={busy}
|
|
509
|
+
onDownload={(runId, format) => void download(runId, format)}
|
|
510
|
+
/>
|
|
511
|
+
|
|
512
|
+
<Card>
|
|
513
|
+
<CardHeader>
|
|
514
|
+
<CardTitle className="text-base">Run history</CardTitle>
|
|
515
|
+
<CardDescription>
|
|
516
|
+
The latest 30 generations are kept. Select one to preview it.
|
|
517
|
+
</CardDescription>
|
|
518
|
+
</CardHeader>
|
|
519
|
+
<CardContent>
|
|
520
|
+
{runs.length === 0 ? (
|
|
521
|
+
<p className="text-sm text-text-secondary">No runs yet.</p>
|
|
522
|
+
) : (
|
|
523
|
+
<div className="overflow-x-auto">
|
|
524
|
+
<Table>
|
|
525
|
+
<TableHeader>
|
|
526
|
+
<TableRow>
|
|
527
|
+
<TableHead>Generated</TableHead>
|
|
528
|
+
<TableHead>Period</TableHead>
|
|
529
|
+
<TableHead>Trigger</TableHead>
|
|
530
|
+
<TableHead>Status</TableHead>
|
|
531
|
+
<TableHead className="text-right">Rows</TableHead>
|
|
532
|
+
<TableHead className="text-right">Download</TableHead>
|
|
533
|
+
</TableRow>
|
|
534
|
+
</TableHeader>
|
|
535
|
+
<TableBody>
|
|
536
|
+
{runs.map((entry) => (
|
|
537
|
+
<TableRow
|
|
538
|
+
key={entry.id}
|
|
539
|
+
className={entry.id === run?.id ? 'bg-surface-secondary' : undefined}
|
|
540
|
+
>
|
|
541
|
+
<TableCell>
|
|
542
|
+
<button
|
|
543
|
+
type="button"
|
|
544
|
+
className="text-left font-medium text-text-primary underline-offset-2 hover:underline"
|
|
545
|
+
onClick={() => void loadRun(entry.id)}
|
|
546
|
+
>
|
|
547
|
+
{formatDateTime(entry.startedAt)}
|
|
548
|
+
</button>
|
|
549
|
+
</TableCell>
|
|
550
|
+
<TableCell className="whitespace-nowrap text-xs">
|
|
551
|
+
{periodLabel(entry)}
|
|
552
|
+
</TableCell>
|
|
553
|
+
<TableCell>
|
|
554
|
+
{entry.trigger === 'SCHEDULED' ? 'Scheduled' : 'Manual'}
|
|
555
|
+
</TableCell>
|
|
556
|
+
<TableCell>
|
|
557
|
+
<Badge variant={statusVariant(entry.status)}>{entry.status}</Badge>
|
|
558
|
+
</TableCell>
|
|
559
|
+
<TableCell className="text-right">
|
|
560
|
+
{entry.rowCount.toLocaleString()}
|
|
561
|
+
</TableCell>
|
|
562
|
+
<TableCell className="text-right">
|
|
563
|
+
{entry.status === 'COMPLETED' ? (
|
|
564
|
+
<span className="inline-flex gap-1">
|
|
565
|
+
{(['CSV', 'JSON'] as const).map((format) => (
|
|
566
|
+
<Button
|
|
567
|
+
key={format}
|
|
568
|
+
variant="ghost"
|
|
569
|
+
size="sm"
|
|
570
|
+
disabled={busy !== null}
|
|
571
|
+
onClick={() => void download(entry.id, format)}
|
|
572
|
+
>
|
|
573
|
+
{format}
|
|
574
|
+
</Button>
|
|
575
|
+
))}
|
|
576
|
+
</span>
|
|
577
|
+
) : (
|
|
578
|
+
'—'
|
|
579
|
+
)}
|
|
580
|
+
</TableCell>
|
|
581
|
+
</TableRow>
|
|
582
|
+
))}
|
|
583
|
+
</TableBody>
|
|
584
|
+
</Table>
|
|
585
|
+
</div>
|
|
586
|
+
)}
|
|
587
|
+
</CardContent>
|
|
588
|
+
</Card>
|
|
589
|
+
</>
|
|
590
|
+
)}
|
|
591
|
+
</div>
|
|
592
|
+
</div>
|
|
593
|
+
|
|
594
|
+
{editing && (
|
|
595
|
+
<ReportDialog
|
|
596
|
+
report={editing === 'new' ? null : editing}
|
|
597
|
+
defaultTimezone={settings.timezone ?? 'UTC'}
|
|
598
|
+
onClose={() => setEditing(null)}
|
|
599
|
+
onSave={save}
|
|
600
|
+
/>
|
|
601
|
+
)}
|
|
602
|
+
|
|
603
|
+
<Dialog open={deleting !== null} onOpenChange={(open) => !open && setDeleting(null)}>
|
|
604
|
+
<DialogContent>
|
|
605
|
+
<DialogHeader>
|
|
606
|
+
<DialogTitle>Delete this report?</DialogTitle>
|
|
607
|
+
<DialogDescription>
|
|
608
|
+
{deleting
|
|
609
|
+
? `"${deleting.name}" stops being generated and leaves the list. This cannot be undone.`
|
|
610
|
+
: ''}
|
|
611
|
+
</DialogDescription>
|
|
612
|
+
</DialogHeader>
|
|
613
|
+
<DialogFooter>
|
|
614
|
+
<Button variant="outline" onClick={() => setDeleting(null)}>
|
|
615
|
+
Cancel
|
|
616
|
+
</Button>
|
|
617
|
+
<Button
|
|
618
|
+
variant="destructive"
|
|
619
|
+
disabled={busy !== null}
|
|
620
|
+
onClick={() => deleting && void remove(deleting)}
|
|
621
|
+
>
|
|
622
|
+
{busy?.startsWith('delete:') && <Loader2 size={16} className="mr-2 animate-spin" />}
|
|
623
|
+
Delete report
|
|
624
|
+
</Button>
|
|
625
|
+
</DialogFooter>
|
|
626
|
+
</DialogContent>
|
|
627
|
+
</Dialog>
|
|
628
|
+
</PageLayout>
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function RunDetail({
|
|
633
|
+
run,
|
|
634
|
+
isLoading,
|
|
635
|
+
hasRuns,
|
|
636
|
+
busy,
|
|
637
|
+
onDownload,
|
|
638
|
+
}: {
|
|
639
|
+
run: MtwReportRunDetail | null;
|
|
640
|
+
isLoading: boolean;
|
|
641
|
+
hasRuns: boolean;
|
|
642
|
+
busy: string | null;
|
|
643
|
+
onDownload: (runId: string, format: MtwReportFormat) => void;
|
|
644
|
+
}) {
|
|
645
|
+
if (isLoading && !run) {
|
|
646
|
+
return (
|
|
647
|
+
<Card>
|
|
648
|
+
<CardContent className="space-y-3 p-6" aria-busy="true">
|
|
649
|
+
<Skeleton className="h-20 w-full" />
|
|
650
|
+
<Skeleton className="h-40 w-full" />
|
|
651
|
+
</CardContent>
|
|
652
|
+
</Card>
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
if (!run) {
|
|
656
|
+
return (
|
|
657
|
+
<Card>
|
|
658
|
+
<CardContent className="p-6 text-sm text-text-secondary">
|
|
659
|
+
{hasRuns
|
|
660
|
+
? 'Select a run to preview it.'
|
|
661
|
+
: 'This report has not been generated yet. Use "Generate now" to produce the first run.'}
|
|
662
|
+
</CardContent>
|
|
663
|
+
</Card>
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
return (
|
|
667
|
+
<Card data-testid="mtw-report-run">
|
|
668
|
+
<CardHeader className="flex flex-row flex-wrap items-start justify-between gap-3">
|
|
669
|
+
<div className="space-y-1">
|
|
670
|
+
<CardTitle className="text-base">
|
|
671
|
+
{run.trigger === 'SCHEDULED' ? 'Scheduled run' : 'Run'} of{' '}
|
|
672
|
+
{formatDateTime(run.startedAt)}
|
|
673
|
+
</CardTitle>
|
|
674
|
+
<CardDescription>Covers {periodLabel(run)}</CardDescription>
|
|
675
|
+
</div>
|
|
676
|
+
<div className="flex items-center gap-2">
|
|
677
|
+
<Badge variant={statusVariant(run.status)}>{run.status}</Badge>
|
|
678
|
+
{run.status === 'COMPLETED' &&
|
|
679
|
+
(['CSV', 'JSON'] as const).map((format) => (
|
|
680
|
+
<Button
|
|
681
|
+
key={format}
|
|
682
|
+
variant="outline"
|
|
683
|
+
size="sm"
|
|
684
|
+
disabled={busy !== null}
|
|
685
|
+
onClick={() => onDownload(run.id, format)}
|
|
686
|
+
>
|
|
687
|
+
{busy === `download:${run.id}:${format}` ? (
|
|
688
|
+
<Loader2 size={14} className="mr-2 animate-spin" />
|
|
689
|
+
) : (
|
|
690
|
+
<Download size={14} className="mr-2" />
|
|
691
|
+
)}
|
|
692
|
+
{format}
|
|
693
|
+
</Button>
|
|
694
|
+
))}
|
|
695
|
+
</div>
|
|
696
|
+
</CardHeader>
|
|
697
|
+
<CardContent className="space-y-6">
|
|
698
|
+
{run.status === 'FAILED' && <FormError message={run.error ?? 'This run failed.'} />}
|
|
699
|
+
{run.metrics.length > 0 && (
|
|
700
|
+
<dl className="grid grid-cols-2 gap-3 md:grid-cols-3 lg:grid-cols-4">
|
|
701
|
+
{run.metrics.map((metric) => (
|
|
702
|
+
<div key={metric.key} className="rounded-lg border border-border-default px-3 py-2">
|
|
703
|
+
<dt className="text-xs text-text-secondary">{metricLabel(metric)}</dt>
|
|
704
|
+
<dd className="text-lg font-semibold text-text-primary">
|
|
705
|
+
{formatMetric(metric, METRIC_FORMATTERS)}
|
|
706
|
+
</dd>
|
|
707
|
+
</div>
|
|
708
|
+
))}
|
|
709
|
+
</dl>
|
|
710
|
+
)}
|
|
711
|
+
{run.status === 'COMPLETED' &&
|
|
712
|
+
(run.rowCount === 0 ? (
|
|
713
|
+
<p className="text-sm text-text-secondary">The period had no rows for this report.</p>
|
|
714
|
+
) : (
|
|
715
|
+
<div className="space-y-2">
|
|
716
|
+
<p className="text-xs text-text-secondary">
|
|
717
|
+
Showing {Math.min(run.rows.length, run.rowCount).toLocaleString()} of{' '}
|
|
718
|
+
{run.rowCount.toLocaleString()} rows. Download the run for all of them.
|
|
719
|
+
{run.truncated &&
|
|
720
|
+
' The period had more rows than a run keeps (5,000); the figures above still cover all of them.'}
|
|
721
|
+
</p>
|
|
722
|
+
<div className="max-h-[28rem] overflow-auto rounded-lg border border-border-default">
|
|
723
|
+
<Table>
|
|
724
|
+
<TableHeader>
|
|
725
|
+
<TableRow>
|
|
726
|
+
{run.columns.map((column) => (
|
|
727
|
+
<TableHead key={column.key} className="whitespace-nowrap">
|
|
728
|
+
{column.label}
|
|
729
|
+
</TableHead>
|
|
730
|
+
))}
|
|
731
|
+
</TableRow>
|
|
732
|
+
</TableHeader>
|
|
733
|
+
<TableBody>
|
|
734
|
+
{run.rows.map((row, index) => (
|
|
735
|
+
<TableRow key={index}>
|
|
736
|
+
{run.columns.map((column) => (
|
|
737
|
+
<TableCell key={column.key} className="whitespace-nowrap text-xs">
|
|
738
|
+
{column.kind === 'CURRENCY' && typeof row[column.key] === 'number'
|
|
739
|
+
? formatCurrency(
|
|
740
|
+
row[column.key] as number,
|
|
741
|
+
typeof row['currency'] === 'string'
|
|
742
|
+
? (row['currency'] as string)
|
|
743
|
+
: undefined
|
|
744
|
+
)
|
|
745
|
+
: formatCell(row[column.key], column, (value) => formatDate(value))}
|
|
746
|
+
</TableCell>
|
|
747
|
+
))}
|
|
748
|
+
</TableRow>
|
|
749
|
+
))}
|
|
750
|
+
</TableBody>
|
|
751
|
+
</Table>
|
|
752
|
+
</div>
|
|
753
|
+
</div>
|
|
754
|
+
))}
|
|
755
|
+
</CardContent>
|
|
756
|
+
</Card>
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function ReportDialog({
|
|
761
|
+
report,
|
|
762
|
+
defaultTimezone,
|
|
763
|
+
onClose,
|
|
764
|
+
onSave,
|
|
765
|
+
}: {
|
|
766
|
+
report: MtwReport | null;
|
|
767
|
+
defaultTimezone: string;
|
|
768
|
+
onClose: () => void;
|
|
769
|
+
onSave: (input: MtwReportInput, report: MtwReport | null) => Promise<void>;
|
|
770
|
+
}) {
|
|
771
|
+
const [draft, setDraft] = useState<MtwReportInput>(() =>
|
|
772
|
+
report ? reportToInput(report) : newReportInput(defaultTimezone)
|
|
773
|
+
);
|
|
774
|
+
const [periodText, setPeriodText] = useState(String(draft.periodDays));
|
|
775
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
776
|
+
const [error, setError] = useState<string | null>(null);
|
|
777
|
+
|
|
778
|
+
const current = { ...draft, periodDays: Number(periodText) };
|
|
779
|
+
const validation = reportInputError(current);
|
|
780
|
+
|
|
781
|
+
const update = <K extends keyof MtwReportInput>(key: K, value: MtwReportInput[K]) => {
|
|
782
|
+
setError(null);
|
|
783
|
+
setDraft((previous) => ({ ...previous, [key]: value }));
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
const onSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
|
787
|
+
event.preventDefault();
|
|
788
|
+
if (validation) {
|
|
789
|
+
setError(validation);
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
setIsSaving(true);
|
|
793
|
+
setError(null);
|
|
794
|
+
try {
|
|
795
|
+
await onSave(current, report);
|
|
796
|
+
} catch (caught) {
|
|
797
|
+
setError(message(caught, 'Could not save the report'));
|
|
798
|
+
} finally {
|
|
799
|
+
setIsSaving(false);
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
return (
|
|
804
|
+
<Dialog open onOpenChange={(open) => !open && !isSaving && onClose()}>
|
|
805
|
+
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-xl">
|
|
806
|
+
<DialogHeader>
|
|
807
|
+
<DialogTitle>{report ? 'Edit report' : 'New report'}</DialogTitle>
|
|
808
|
+
<DialogDescription>
|
|
809
|
+
Choose what the report covers and, if you like, when it is generated automatically.
|
|
810
|
+
</DialogDescription>
|
|
811
|
+
</DialogHeader>
|
|
812
|
+
<form className="space-y-4" onSubmit={(event) => void onSubmit(event)} aria-label="Report">
|
|
813
|
+
<div className="space-y-2">
|
|
814
|
+
<Label htmlFor="mtw-report-name">Name</Label>
|
|
815
|
+
<Input
|
|
816
|
+
id="mtw-report-name"
|
|
817
|
+
value={draft.name}
|
|
818
|
+
maxLength={120}
|
|
819
|
+
onChange={(event) => update('name', event.target.value)}
|
|
820
|
+
placeholder="Weekly operations review"
|
|
821
|
+
/>
|
|
822
|
+
</div>
|
|
823
|
+
<div className="space-y-2">
|
|
824
|
+
<Label htmlFor="mtw-report-type">Report type</Label>
|
|
825
|
+
<Select
|
|
826
|
+
value={draft.type}
|
|
827
|
+
onValueChange={(value: string) => {
|
|
828
|
+
const option = REPORT_TYPE_OPTIONS.find((candidate) => candidate.value === value);
|
|
829
|
+
if (option) update('type', option.value as MtwReportType);
|
|
830
|
+
}}
|
|
831
|
+
>
|
|
832
|
+
<SelectTrigger id="mtw-report-type" aria-label="Report type">
|
|
833
|
+
<SelectValue />
|
|
834
|
+
</SelectTrigger>
|
|
835
|
+
<SelectContent>
|
|
836
|
+
{REPORT_TYPE_OPTIONS.map((option) => (
|
|
837
|
+
<SelectItem key={option.value} value={option.value}>
|
|
838
|
+
{option.label}
|
|
839
|
+
</SelectItem>
|
|
840
|
+
))}
|
|
841
|
+
</SelectContent>
|
|
842
|
+
</Select>
|
|
843
|
+
<p className="text-xs text-text-secondary">
|
|
844
|
+
{REPORT_TYPE_OPTIONS.find((option) => option.value === draft.type)?.description}
|
|
845
|
+
</p>
|
|
846
|
+
</div>
|
|
847
|
+
<div className="space-y-2">
|
|
848
|
+
<Label htmlFor="mtw-report-description">Description (optional)</Label>
|
|
849
|
+
<Textarea
|
|
850
|
+
id="mtw-report-description"
|
|
851
|
+
value={draft.description}
|
|
852
|
+
maxLength={1000}
|
|
853
|
+
rows={2}
|
|
854
|
+
onChange={(event) => update('description', event.target.value)}
|
|
855
|
+
/>
|
|
856
|
+
</div>
|
|
857
|
+
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
858
|
+
<div className="space-y-2">
|
|
859
|
+
<Label htmlFor="mtw-report-frequency">Generate</Label>
|
|
860
|
+
<Select
|
|
861
|
+
value={draft.frequency}
|
|
862
|
+
onValueChange={(value: string) => {
|
|
863
|
+
const option = FREQUENCY_OPTIONS.find((candidate) => candidate.value === value);
|
|
864
|
+
if (!option) return;
|
|
865
|
+
update('frequency', option.value as MtwReportFrequency);
|
|
866
|
+
if (!report) setPeriodText(String(suggestedPeriodDays(option.value)));
|
|
867
|
+
}}
|
|
868
|
+
>
|
|
869
|
+
<SelectTrigger id="mtw-report-frequency" aria-label="Generate">
|
|
870
|
+
<SelectValue />
|
|
871
|
+
</SelectTrigger>
|
|
872
|
+
<SelectContent>
|
|
873
|
+
{FREQUENCY_OPTIONS.map((option) => (
|
|
874
|
+
<SelectItem key={option.value} value={option.value}>
|
|
875
|
+
{option.label}
|
|
876
|
+
</SelectItem>
|
|
877
|
+
))}
|
|
878
|
+
</SelectContent>
|
|
879
|
+
</Select>
|
|
880
|
+
</div>
|
|
881
|
+
<div className="space-y-2">
|
|
882
|
+
<Label htmlFor="mtw-report-period">Covers the last (days)</Label>
|
|
883
|
+
<Input
|
|
884
|
+
id="mtw-report-period"
|
|
885
|
+
type="number"
|
|
886
|
+
inputMode="numeric"
|
|
887
|
+
min={PERIOD_DAYS_MIN}
|
|
888
|
+
max={PERIOD_DAYS_MAX}
|
|
889
|
+
step={1}
|
|
890
|
+
value={periodText}
|
|
891
|
+
onChange={(event) => {
|
|
892
|
+
setError(null);
|
|
893
|
+
setPeriodText(event.target.value);
|
|
894
|
+
}}
|
|
895
|
+
/>
|
|
896
|
+
</div>
|
|
897
|
+
</div>
|
|
898
|
+
|
|
899
|
+
{draft.frequency !== 'NONE' && (
|
|
900
|
+
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
|
|
901
|
+
{draft.frequency === 'WEEKLY' && (
|
|
902
|
+
<div className="space-y-2">
|
|
903
|
+
<Label htmlFor="mtw-report-weekday">Day</Label>
|
|
904
|
+
<Select
|
|
905
|
+
value={String(draft.runWeekday)}
|
|
906
|
+
onValueChange={(value: string) => update('runWeekday', Number(value))}
|
|
907
|
+
>
|
|
908
|
+
<SelectTrigger id="mtw-report-weekday" aria-label="Day">
|
|
909
|
+
<SelectValue />
|
|
910
|
+
</SelectTrigger>
|
|
911
|
+
<SelectContent>
|
|
912
|
+
{WEEKDAY_LABELS.map((label, index) => (
|
|
913
|
+
<SelectItem key={label} value={String(index + 1)}>
|
|
914
|
+
{label}
|
|
915
|
+
</SelectItem>
|
|
916
|
+
))}
|
|
917
|
+
</SelectContent>
|
|
918
|
+
</Select>
|
|
919
|
+
</div>
|
|
920
|
+
)}
|
|
921
|
+
{draft.frequency === 'MONTHLY' && (
|
|
922
|
+
<div className="space-y-2">
|
|
923
|
+
<Label htmlFor="mtw-report-monthday">Day of month</Label>
|
|
924
|
+
<Select
|
|
925
|
+
value={String(draft.runMonthDay)}
|
|
926
|
+
onValueChange={(value: string) => update('runMonthDay', Number(value))}
|
|
927
|
+
>
|
|
928
|
+
<SelectTrigger id="mtw-report-monthday" aria-label="Day of month">
|
|
929
|
+
<SelectValue />
|
|
930
|
+
</SelectTrigger>
|
|
931
|
+
<SelectContent className="max-h-72">
|
|
932
|
+
{Array.from({ length: 28 }, (_, index) => (
|
|
933
|
+
<SelectItem key={index + 1} value={String(index + 1)}>
|
|
934
|
+
{index + 1}
|
|
935
|
+
</SelectItem>
|
|
936
|
+
))}
|
|
937
|
+
</SelectContent>
|
|
938
|
+
</Select>
|
|
939
|
+
</div>
|
|
940
|
+
)}
|
|
941
|
+
<div className="space-y-2">
|
|
942
|
+
<Label htmlFor="mtw-report-hour">Time</Label>
|
|
943
|
+
<Select
|
|
944
|
+
value={String(draft.runHour)}
|
|
945
|
+
onValueChange={(value: string) => update('runHour', Number(value))}
|
|
946
|
+
>
|
|
947
|
+
<SelectTrigger id="mtw-report-hour" aria-label="Time">
|
|
948
|
+
<SelectValue />
|
|
949
|
+
</SelectTrigger>
|
|
950
|
+
<SelectContent className="max-h-72">
|
|
951
|
+
{Array.from({ length: 24 }, (_, hour) => (
|
|
952
|
+
<SelectItem key={hour} value={String(hour)}>
|
|
953
|
+
{`${String(hour).padStart(2, '0')}:00`}
|
|
954
|
+
</SelectItem>
|
|
955
|
+
))}
|
|
956
|
+
</SelectContent>
|
|
957
|
+
</Select>
|
|
958
|
+
</div>
|
|
959
|
+
<div className="space-y-2">
|
|
960
|
+
<Label htmlFor="mtw-report-timezone">Time zone</Label>
|
|
961
|
+
<Input
|
|
962
|
+
id="mtw-report-timezone"
|
|
963
|
+
value={draft.timezone}
|
|
964
|
+
onChange={(event) => update('timezone', event.target.value)}
|
|
965
|
+
placeholder="Asia/Kolkata"
|
|
966
|
+
/>
|
|
967
|
+
</div>
|
|
968
|
+
</div>
|
|
969
|
+
)}
|
|
970
|
+
|
|
971
|
+
{draft.frequency !== 'NONE' && (
|
|
972
|
+
<div className="flex items-center justify-between gap-3 rounded-lg border border-border-default px-3 py-2">
|
|
973
|
+
<Label htmlFor="mtw-report-active" className="text-sm">
|
|
974
|
+
Generate automatically
|
|
975
|
+
</Label>
|
|
976
|
+
<Switch
|
|
977
|
+
id="mtw-report-active"
|
|
978
|
+
checked={draft.isActive}
|
|
979
|
+
onCheckedChange={(checked: boolean) => update('isActive', checked)}
|
|
980
|
+
/>
|
|
981
|
+
</div>
|
|
982
|
+
)}
|
|
983
|
+
|
|
984
|
+
<FormError message={error} />
|
|
985
|
+
|
|
986
|
+
<DialogFooter>
|
|
987
|
+
<Button type="button" variant="outline" onClick={onClose} disabled={isSaving}>
|
|
988
|
+
Cancel
|
|
989
|
+
</Button>
|
|
990
|
+
<Button type="submit" disabled={isSaving}>
|
|
991
|
+
{isSaving && <Loader2 size={16} className="mr-2 animate-spin" />}
|
|
992
|
+
{report ? 'Save report' : 'Create report'}
|
|
993
|
+
</Button>
|
|
994
|
+
</DialogFooter>
|
|
995
|
+
</form>
|
|
996
|
+
</DialogContent>
|
|
997
|
+
</Dialog>
|
|
998
|
+
);
|
|
999
|
+
}
|