@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,419 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reports — client side of wspace-movethewheels-svc's saved reports
|
|
3
|
+
* (BOFF-3989).
|
|
4
|
+
*
|
|
5
|
+
* The service owns validation, scheduling and generation; this module holds
|
|
6
|
+
* the GraphQL documents, the form model and the display helpers for report
|
|
7
|
+
* runs. Kept free of React so the contract can be unit-tested against the
|
|
8
|
+
* subgraph schema.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type MtwReportType = 'OPERATIONS' | 'FINANCE' | 'FLEET' | 'CUSTOMERS' | 'INVENTORY';
|
|
12
|
+
export type MtwReportFrequency = 'NONE' | 'DAILY' | 'WEEKLY' | 'MONTHLY';
|
|
13
|
+
export type MtwReportFormat = 'CSV' | 'JSON';
|
|
14
|
+
export type MtwReportCell = string | number | boolean | null;
|
|
15
|
+
|
|
16
|
+
export interface MtwReportColumn {
|
|
17
|
+
key: string;
|
|
18
|
+
label: string;
|
|
19
|
+
kind: 'TEXT' | 'NUMBER' | 'CURRENCY' | 'DATE' | 'BOOLEAN' | string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MtwReportMetric {
|
|
23
|
+
key: string;
|
|
24
|
+
label: string;
|
|
25
|
+
value: number | null;
|
|
26
|
+
kind: 'NUMBER' | 'CURRENCY' | 'PERCENT' | 'DISTANCE' | 'WEIGHT' | string;
|
|
27
|
+
currency: string | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MtwReportRunSummary {
|
|
31
|
+
id: string;
|
|
32
|
+
reportId: string;
|
|
33
|
+
reportType: MtwReportType;
|
|
34
|
+
trigger: 'MANUAL' | 'SCHEDULED' | string;
|
|
35
|
+
status: 'RUNNING' | 'COMPLETED' | 'FAILED' | string;
|
|
36
|
+
periodStart: string;
|
|
37
|
+
periodEnd: string;
|
|
38
|
+
rowCount: number;
|
|
39
|
+
truncated: boolean;
|
|
40
|
+
error: string | null;
|
|
41
|
+
durationMs: number | null;
|
|
42
|
+
startedAt: string;
|
|
43
|
+
finishedAt: string | null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface MtwReportRunDetail extends MtwReportRunSummary {
|
|
47
|
+
metrics: MtwReportMetric[];
|
|
48
|
+
columns: MtwReportColumn[];
|
|
49
|
+
rows: Record<string, MtwReportCell>[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface MtwReport {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description: string | null;
|
|
56
|
+
type: MtwReportType;
|
|
57
|
+
periodDays: number;
|
|
58
|
+
frequency: MtwReportFrequency;
|
|
59
|
+
runHour: number;
|
|
60
|
+
runWeekday: number;
|
|
61
|
+
runMonthDay: number;
|
|
62
|
+
timezone: string;
|
|
63
|
+
isActive: boolean;
|
|
64
|
+
nextRunAt: string | null;
|
|
65
|
+
lastGeneratedAt: string | null;
|
|
66
|
+
lastRunStatus: string | null;
|
|
67
|
+
lastError: string | null;
|
|
68
|
+
updatedAt: string;
|
|
69
|
+
latestRun: MtwReportRunSummary | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface MtwReportExport {
|
|
73
|
+
filename: string;
|
|
74
|
+
contentType: string;
|
|
75
|
+
content: string;
|
|
76
|
+
rowCount: number;
|
|
77
|
+
truncated: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** What the create/edit form sends; the service fills in the rest. */
|
|
81
|
+
export interface MtwReportInput {
|
|
82
|
+
name: string;
|
|
83
|
+
type: MtwReportType;
|
|
84
|
+
description: string;
|
|
85
|
+
periodDays: number;
|
|
86
|
+
frequency: MtwReportFrequency;
|
|
87
|
+
runHour: number;
|
|
88
|
+
runWeekday: number;
|
|
89
|
+
runMonthDay: number;
|
|
90
|
+
timezone: string;
|
|
91
|
+
isActive: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Mirrors the service limits. */
|
|
95
|
+
export const NAME_MAX = 120;
|
|
96
|
+
export const DESCRIPTION_MAX = 1000;
|
|
97
|
+
export const PERIOD_DAYS_MIN = 1;
|
|
98
|
+
export const PERIOD_DAYS_MAX = 366;
|
|
99
|
+
/** Rows shown in the in-page preview; the download holds every stored row. */
|
|
100
|
+
export const PREVIEW_ROWS = 50;
|
|
101
|
+
|
|
102
|
+
export const REPORT_TYPE_OPTIONS: ReadonlyArray<{
|
|
103
|
+
value: MtwReportType;
|
|
104
|
+
label: string;
|
|
105
|
+
description: string;
|
|
106
|
+
}> = [
|
|
107
|
+
{
|
|
108
|
+
value: 'OPERATIONS',
|
|
109
|
+
label: 'Operations',
|
|
110
|
+
description:
|
|
111
|
+
'Shipments booked in the period: status, lanes, on-time delivery and freight cost.',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: 'FINANCE',
|
|
115
|
+
label: 'Finance',
|
|
116
|
+
description:
|
|
117
|
+
'Order revenue, delivered and outstanding amounts, and freight cost, per currency.',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
value: 'FLEET',
|
|
121
|
+
label: 'Fleet',
|
|
122
|
+
description: 'Every vehicle with its orders, completed routes, distance, fuel cost and CO2e.',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
value: 'CUSTOMERS',
|
|
126
|
+
label: 'Customers',
|
|
127
|
+
description: 'Every customer with their orders, deliveries and revenue in the period.',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
value: 'INVENTORY',
|
|
131
|
+
label: 'Inventory',
|
|
132
|
+
description: 'Every stock line with its levels, value and movements in the period.',
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
export const FREQUENCY_OPTIONS: ReadonlyArray<{ value: MtwReportFrequency; label: string }> = [
|
|
137
|
+
{ value: 'NONE', label: 'Only when I generate it' },
|
|
138
|
+
{ value: 'DAILY', label: 'Every day' },
|
|
139
|
+
{ value: 'WEEKLY', label: 'Every week' },
|
|
140
|
+
{ value: 'MONTHLY', label: 'Every month' },
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
export const WEEKDAY_LABELS = [
|
|
144
|
+
'Monday',
|
|
145
|
+
'Tuesday',
|
|
146
|
+
'Wednesday',
|
|
147
|
+
'Thursday',
|
|
148
|
+
'Friday',
|
|
149
|
+
'Saturday',
|
|
150
|
+
'Sunday',
|
|
151
|
+
] as const;
|
|
152
|
+
|
|
153
|
+
const RUN_FIELDS = `
|
|
154
|
+
id
|
|
155
|
+
reportId
|
|
156
|
+
reportType
|
|
157
|
+
trigger
|
|
158
|
+
status
|
|
159
|
+
periodStart
|
|
160
|
+
periodEnd
|
|
161
|
+
rowCount
|
|
162
|
+
truncated
|
|
163
|
+
error
|
|
164
|
+
durationMs
|
|
165
|
+
startedAt
|
|
166
|
+
finishedAt
|
|
167
|
+
`;
|
|
168
|
+
|
|
169
|
+
const REPORT_FIELDS = `
|
|
170
|
+
id
|
|
171
|
+
name
|
|
172
|
+
description
|
|
173
|
+
type
|
|
174
|
+
periodDays
|
|
175
|
+
frequency
|
|
176
|
+
runHour
|
|
177
|
+
runWeekday
|
|
178
|
+
runMonthDay
|
|
179
|
+
timezone
|
|
180
|
+
isActive
|
|
181
|
+
nextRunAt
|
|
182
|
+
lastGeneratedAt
|
|
183
|
+
lastRunStatus
|
|
184
|
+
lastError
|
|
185
|
+
updatedAt
|
|
186
|
+
latestRun {
|
|
187
|
+
${RUN_FIELDS}
|
|
188
|
+
}
|
|
189
|
+
`;
|
|
190
|
+
|
|
191
|
+
export const MTW_REPORTS_QUERY = `
|
|
192
|
+
query MtwReports($pagination: PaginationInput) {
|
|
193
|
+
mtwReports(pagination: $pagination) {
|
|
194
|
+
${REPORT_FIELDS}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
`;
|
|
198
|
+
|
|
199
|
+
export const MTW_REPORT_RUNS_QUERY = `
|
|
200
|
+
query MtwReportRuns($reportId: ID!, $pagination: PaginationInput) {
|
|
201
|
+
mtwReportRuns(reportId: $reportId, pagination: $pagination) {
|
|
202
|
+
${RUN_FIELDS}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
`;
|
|
206
|
+
|
|
207
|
+
export const MTW_REPORT_RUN_QUERY = `
|
|
208
|
+
query MtwReportRun($id: ID!, $rows: PaginationInput) {
|
|
209
|
+
mtwReportRun(id: $id) {
|
|
210
|
+
${RUN_FIELDS}
|
|
211
|
+
metrics {
|
|
212
|
+
key
|
|
213
|
+
label
|
|
214
|
+
value
|
|
215
|
+
kind
|
|
216
|
+
currency
|
|
217
|
+
}
|
|
218
|
+
columns {
|
|
219
|
+
key
|
|
220
|
+
label
|
|
221
|
+
kind
|
|
222
|
+
}
|
|
223
|
+
rows(pagination: $rows)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
`;
|
|
227
|
+
|
|
228
|
+
export const MTW_REPORT_RUN_EXPORT_QUERY = `
|
|
229
|
+
query MtwReportRunExport($runId: ID!, $format: MtwReportFormat!) {
|
|
230
|
+
mtwReportRunExport(runId: $runId, format: $format) {
|
|
231
|
+
filename
|
|
232
|
+
contentType
|
|
233
|
+
content
|
|
234
|
+
rowCount
|
|
235
|
+
truncated
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
`;
|
|
239
|
+
|
|
240
|
+
export const CREATE_MTW_REPORT_MUTATION = `
|
|
241
|
+
mutation CreateMtwReport($input: MtwCreateReportInput!) {
|
|
242
|
+
createMtwReport(input: $input) {
|
|
243
|
+
${REPORT_FIELDS}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
`;
|
|
247
|
+
|
|
248
|
+
export const UPDATE_MTW_REPORT_MUTATION = `
|
|
249
|
+
mutation UpdateMtwReport($id: ID!, $input: MtwUpdateReportInput!) {
|
|
250
|
+
updateMtwReport(id: $id, input: $input) {
|
|
251
|
+
${REPORT_FIELDS}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
`;
|
|
255
|
+
|
|
256
|
+
export const DELETE_MTW_REPORT_MUTATION = `
|
|
257
|
+
mutation DeleteMtwReport($id: ID!) {
|
|
258
|
+
deleteMtwReport(id: $id)
|
|
259
|
+
}
|
|
260
|
+
`;
|
|
261
|
+
|
|
262
|
+
export const GENERATE_MTW_REPORT_MUTATION = `
|
|
263
|
+
mutation GenerateMtwReport($id: ID!) {
|
|
264
|
+
generateMtwReport(id: $id) {
|
|
265
|
+
${RUN_FIELDS}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
`;
|
|
269
|
+
|
|
270
|
+
/** The form's starting point for a new report. */
|
|
271
|
+
export function newReportInput(timezone: string): MtwReportInput {
|
|
272
|
+
return {
|
|
273
|
+
name: '',
|
|
274
|
+
type: 'OPERATIONS',
|
|
275
|
+
description: '',
|
|
276
|
+
periodDays: 30,
|
|
277
|
+
frequency: 'NONE',
|
|
278
|
+
runHour: 6,
|
|
279
|
+
runWeekday: 1,
|
|
280
|
+
runMonthDay: 1,
|
|
281
|
+
timezone,
|
|
282
|
+
isActive: true,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function reportToInput(report: MtwReport): MtwReportInput {
|
|
287
|
+
return {
|
|
288
|
+
name: report.name,
|
|
289
|
+
type: report.type,
|
|
290
|
+
description: report.description ?? '',
|
|
291
|
+
periodDays: report.periodDays,
|
|
292
|
+
frequency: report.frequency,
|
|
293
|
+
runHour: report.runHour,
|
|
294
|
+
runWeekday: report.runWeekday,
|
|
295
|
+
runMonthDay: report.runMonthDay,
|
|
296
|
+
timezone: report.timezone,
|
|
297
|
+
isActive: report.isActive,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** The look-back window that matches a frequency: the gap between two runs. */
|
|
302
|
+
export function suggestedPeriodDays(frequency: MtwReportFrequency): number {
|
|
303
|
+
if (frequency === 'DAILY') return 1;
|
|
304
|
+
if (frequency === 'WEEKLY') return 7;
|
|
305
|
+
return 30;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** The first problem with the form, or null when the service would accept it. */
|
|
309
|
+
export function reportInputError(input: MtwReportInput): string | null {
|
|
310
|
+
const name = input.name.trim();
|
|
311
|
+
if (!name) return 'Give the report a name.';
|
|
312
|
+
if (name.length > NAME_MAX) return `The name can be at most ${NAME_MAX} characters.`;
|
|
313
|
+
if (input.description.trim().length > DESCRIPTION_MAX)
|
|
314
|
+
return `The description can be at most ${DESCRIPTION_MAX} characters.`;
|
|
315
|
+
if (
|
|
316
|
+
!Number.isInteger(input.periodDays) ||
|
|
317
|
+
input.periodDays < PERIOD_DAYS_MIN ||
|
|
318
|
+
input.periodDays > PERIOD_DAYS_MAX
|
|
319
|
+
)
|
|
320
|
+
return `The period must be a whole number of days from ${PERIOD_DAYS_MIN} to ${PERIOD_DAYS_MAX}.`;
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** The input sent to createMtwReport / updateMtwReport. */
|
|
325
|
+
export function toServiceInput(input: MtwReportInput): Record<string, unknown> {
|
|
326
|
+
return {
|
|
327
|
+
name: input.name.trim(),
|
|
328
|
+
type: input.type,
|
|
329
|
+
description: input.description.trim(),
|
|
330
|
+
periodDays: input.periodDays,
|
|
331
|
+
frequency: input.frequency,
|
|
332
|
+
runHour: input.runHour,
|
|
333
|
+
runWeekday: input.runWeekday,
|
|
334
|
+
runMonthDay: input.runMonthDay,
|
|
335
|
+
timezone: input.timezone,
|
|
336
|
+
isActive: input.isActive,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function reportTypeLabel(type: string): string {
|
|
341
|
+
return REPORT_TYPE_OPTIONS.find((option) => option.value === type)?.label ?? type;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function hourLabel(hour: number): string {
|
|
345
|
+
return `${String(hour).padStart(2, '0')}:00`;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function ordinal(day: number): string {
|
|
349
|
+
const suffix =
|
|
350
|
+
day % 10 === 1 && day !== 11
|
|
351
|
+
? 'st'
|
|
352
|
+
: day % 10 === 2 && day !== 12
|
|
353
|
+
? 'nd'
|
|
354
|
+
: day % 10 === 3 && day !== 13
|
|
355
|
+
? 'rd'
|
|
356
|
+
: 'th';
|
|
357
|
+
return `${day}${suffix}`;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** "Every Monday at 06:00 (Asia/Kolkata)", "Paused", or "On demand". */
|
|
361
|
+
export function scheduleSummary(
|
|
362
|
+
report: Pick<
|
|
363
|
+
MtwReport,
|
|
364
|
+
'frequency' | 'runHour' | 'runWeekday' | 'runMonthDay' | 'timezone' | 'isActive'
|
|
365
|
+
>
|
|
366
|
+
): string {
|
|
367
|
+
if (report.frequency === 'NONE') return 'On demand';
|
|
368
|
+
const zone = report.timezone.replace(/_/g, ' ');
|
|
369
|
+
const at = `at ${hourLabel(report.runHour)} (${zone})`;
|
|
370
|
+
let when: string;
|
|
371
|
+
if (report.frequency === 'DAILY') when = `Every day ${at}`;
|
|
372
|
+
else if (report.frequency === 'WEEKLY')
|
|
373
|
+
when = `Every ${WEEKDAY_LABELS[report.runWeekday - 1] ?? 'week'} ${at}`;
|
|
374
|
+
else when = `On the ${ordinal(report.runMonthDay)} of every month ${at}`;
|
|
375
|
+
return report.isActive ? when : `Paused · ${when}`;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface MetricFormatters {
|
|
379
|
+
currency: (amount: number, currency?: string) => string;
|
|
380
|
+
distance: (km: number) => string;
|
|
381
|
+
weight: (kg: number) => string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Display value for one headline metric, in the workspace's units. */
|
|
385
|
+
export function formatMetric(metric: MtwReportMetric, format: MetricFormatters): string {
|
|
386
|
+
if (metric.value === null || metric.value === undefined) return '—';
|
|
387
|
+
switch (metric.kind) {
|
|
388
|
+
case 'PERCENT':
|
|
389
|
+
return `${(metric.value * 100).toFixed(1)}%`;
|
|
390
|
+
case 'CURRENCY':
|
|
391
|
+
return format.currency(metric.value, metric.currency ?? undefined);
|
|
392
|
+
case 'DISTANCE':
|
|
393
|
+
return format.distance(metric.value);
|
|
394
|
+
case 'WEIGHT':
|
|
395
|
+
return format.weight(metric.value);
|
|
396
|
+
default:
|
|
397
|
+
return metric.value.toLocaleString();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** A metric's label with its currency, so per-currency figures stay apart. */
|
|
402
|
+
export function metricLabel(metric: MtwReportMetric): string {
|
|
403
|
+
return metric.kind === 'CURRENCY' && metric.currency
|
|
404
|
+
? `${metric.label} (${metric.currency})`
|
|
405
|
+
: metric.label;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Display value for one detail cell. */
|
|
409
|
+
export function formatCell(
|
|
410
|
+
value: MtwReportCell | undefined,
|
|
411
|
+
column: MtwReportColumn,
|
|
412
|
+
formatDate: (value: string) => string
|
|
413
|
+
): string {
|
|
414
|
+
if (value === null || value === undefined || value === '') return '—';
|
|
415
|
+
if (column.kind === 'BOOLEAN' || typeof value === 'boolean') return value ? 'Yes' : 'No';
|
|
416
|
+
if (column.kind === 'DATE' && typeof value === 'string') return formatDate(value);
|
|
417
|
+
if (typeof value === 'number') return value.toLocaleString();
|
|
418
|
+
return String(value);
|
|
419
|
+
}
|