@burdenoff/microfe-movethewheels 2026.1030.1 → 2026.1031.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.
Files changed (44) hide show
  1. package/dist/components/ExportStatusBanner.js +53 -0
  2. package/dist/components/ShipmentRiskDialog.js +228 -0
  3. package/dist/components/TrackingAlertList.js +149 -0
  4. package/dist/generated/tracking-quality-operations.d.ts +1070 -2
  5. package/dist/generated/wspace-types.d.ts +2895 -50
  6. package/dist/hooks/useEntityExport.js +85 -0
  7. package/dist/hooks/useShipmentRisk.js +72 -0
  8. package/dist/hooks/useTracking.js +96 -82
  9. package/dist/movethewheels/components/ExportStatusBanner.d.ts +7 -0
  10. package/dist/movethewheels/components/ShipmentRiskDialog.d.ts +20 -0
  11. package/dist/movethewheels/components/TrackingAlertList.d.ts +14 -0
  12. package/dist/movethewheels/hooks/useEntityExport.d.ts +32 -0
  13. package/dist/movethewheels/hooks/useShipmentRisk.d.ts +41 -0
  14. package/dist/movethewheels/types/index.d.ts +15 -1
  15. package/dist/movethewheels/utils/entityExport.d.ts +64 -0
  16. package/dist/movethewheels/utils/trackingAlerts.d.ts +36 -0
  17. package/dist/pages/CustomersPage.js +64 -58
  18. package/dist/pages/DashboardPage.js +147 -151
  19. package/dist/pages/DriversPage.js +113 -107
  20. package/dist/pages/LiveTrackingPage.js +169 -169
  21. package/dist/pages/OrdersListPage.js +85 -79
  22. package/dist/pages/ProductsPage.js +63 -57
  23. package/dist/pages/VehiclesPage.js +91 -85
  24. package/dist/utils/entityExport.js +54 -0
  25. package/dist/utils/trackingAlerts.js +86 -0
  26. package/package.json +4 -2
  27. package/src/generated/tracking-quality-operations.ts +1409 -13
  28. package/src/generated/wspace-types.ts +3248 -51
  29. package/src/movethewheels/components/ExportStatusBanner.tsx +78 -0
  30. package/src/movethewheels/components/ShipmentRiskDialog.tsx +315 -0
  31. package/src/movethewheels/components/TrackingAlertList.tsx +188 -0
  32. package/src/movethewheels/hooks/useEntityExport.ts +130 -0
  33. package/src/movethewheels/hooks/useShipmentRisk.ts +195 -0
  34. package/src/movethewheels/hooks/useTracking.ts +66 -22
  35. package/src/movethewheels/pages/CustomersPage.tsx +11 -2
  36. package/src/movethewheels/pages/DashboardPage.tsx +10 -20
  37. package/src/movethewheels/pages/DriversPage.tsx +11 -2
  38. package/src/movethewheels/pages/LiveTrackingPage.tsx +20 -22
  39. package/src/movethewheels/pages/OrdersListPage.tsx +13 -2
  40. package/src/movethewheels/pages/ProductsPage.tsx +11 -2
  41. package/src/movethewheels/pages/VehiclesPage.tsx +11 -2
  42. package/src/movethewheels/types/index.ts +16 -1
  43. package/src/movethewheels/utils/entityExport.ts +140 -0
  44. package/src/movethewheels/utils/trackingAlerts.ts +151 -0
@@ -39,6 +39,8 @@ import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
39
39
  import { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';
40
40
  import { formatCurrency, formatDate } from '../utils/formatters';
41
41
  import { joinPath } from '../utils/navigation';
42
+ import { useEntityExport } from '../hooks/useEntityExport';
43
+ import { ExportStatusBanner } from '../components/ExportStatusBanner';
42
44
  import type { Order, OrderStatus } from '../types';
43
45
 
44
46
  export default function OrdersListPage() {
@@ -48,6 +50,12 @@ export default function OrdersListPage() {
48
50
  return value === key ? fallback : value;
49
51
  };
50
52
  const { basePath, navigate } = useMoveTheWheels();
53
+ const {
54
+ state: exportState,
55
+ isExporting,
56
+ startExport,
57
+ dismiss: dismissExport,
58
+ } = useEntityExport('orders', 'order');
51
59
  const [statusFilter, setStatusFilter] = useState<OrderStatus | 'all'>('all');
52
60
  const [unassignedOnly, setUnassignedOnly] = useState(false);
53
61
  const [page, setPage] = useState(0);
@@ -219,9 +227,11 @@ export default function OrdersListPage() {
219
227
  onSelect: () => refetch(),
220
228
  },
221
229
  {
222
- label: t('movethewheels.orders.actions.export', 'Export'),
230
+ label: isExporting
231
+ ? t('movethewheels.orders.actions.exporting', 'Exporting…')
232
+ : t('movethewheels.orders.actions.export', 'Export'),
223
233
  icon: <Download size={16} />,
224
- onSelect: () => goTo('import-export'),
234
+ onSelect: startExport,
225
235
  },
226
236
  ]}
227
237
  />
@@ -233,6 +243,7 @@ export default function OrdersListPage() {
233
243
  'Every delivery job lives here — their status, priority and value. Use this list to find an order, filter by status, and open one to assign a driver, track it, or update fulfilment.'
234
244
  )}
235
245
  </PagePurpose>
246
+ <ExportStatusBanner state={exportState} onDismiss={dismissExport} />
236
247
 
237
248
  {/* Pipeline at a glance — premium stat cards */}
238
249
  <div>
@@ -14,10 +14,18 @@ import { useDebouncedValue } from '../hooks/useDebouncedValue';
14
14
  import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
15
15
  import { formatCurrency } from '../utils/formatters';
16
16
  import { joinPath } from '../utils/navigation';
17
+ import { useEntityExport } from '../hooks/useEntityExport';
18
+ import { ExportStatusBanner } from '../components/ExportStatusBanner';
17
19
  import type { Product } from '../types';
18
20
 
19
21
  export default function ProductsPage() {
20
22
  const { basePath, navigate } = useMoveTheWheels();
23
+ const {
24
+ state: exportState,
25
+ isExporting,
26
+ startExport,
27
+ dismiss: dismissExport,
28
+ } = useEntityExport('products', 'product');
21
29
  const [page, setPage] = useState(0);
22
30
  const [pageSize, setPageSize] = useState(25);
23
31
  const [search, setSearch] = useState('');
@@ -127,9 +135,9 @@ export default function ProductsPage() {
127
135
  actions={[
128
136
  { label: 'Refresh', icon: <RefreshCw size={16} />, onSelect: () => refetch() },
129
137
  {
130
- label: 'Export',
138
+ label: isExporting ? 'Exporting…' : 'Export',
131
139
  icon: <Download size={16} />,
132
- onSelect: () => goTo('import-export'),
140
+ onSelect: startExport,
133
141
  },
134
142
  ]}
135
143
  />
@@ -140,6 +148,7 @@ export default function ProductsPage() {
140
148
  flags (fragile, hazardous, temperature-controlled) drive how it&apos;s packed, priced and
141
149
  routed — keep them accurate so shipments are quoted and handled correctly.
142
150
  </PagePurpose>
151
+ <ExportStatusBanner state={exportState} onDismiss={dismissExport} />
143
152
 
144
153
  {/* Catalog at a glance — premium stat cards */}
145
154
  <div>
@@ -33,6 +33,8 @@ import { useVehicles, useFleetStats } from '../hooks/useFleet';
33
33
  import { useDebouncedValue } from '../hooks/useDebouncedValue';
34
34
  import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
35
35
  import { joinPath } from '../utils/navigation';
36
+ import { useEntityExport } from '../hooks/useEntityExport';
37
+ import { ExportStatusBanner } from '../components/ExportStatusBanner';
36
38
  import { VEHICLE_STATUS_LABELS } from '../constants';
37
39
  import type { Vehicle, VehicleStatus } from '../types';
38
40
 
@@ -45,6 +47,12 @@ const STATUS_OPTIONS: Array<{ value: VehicleStatus | 'all'; label: string }> = [
45
47
 
46
48
  export default function VehiclesPage() {
47
49
  const { basePath, navigate } = useMoveTheWheels();
50
+ const {
51
+ state: exportState,
52
+ isExporting,
53
+ startExport,
54
+ dismiss: dismissExport,
55
+ } = useEntityExport('vehicles', 'vehicle');
48
56
  const [page, setPage] = useState(0);
49
57
  const [pageSize, setPageSize] = useState(25);
50
58
  const [search, setSearch] = useState('');
@@ -156,9 +164,9 @@ export default function VehiclesPage() {
156
164
  actions={[
157
165
  { label: 'Refresh', icon: <RefreshCw size={16} />, onSelect: () => refetch() },
158
166
  {
159
- label: 'Export',
167
+ label: isExporting ? 'Exporting…' : 'Export',
160
168
  icon: <Download size={16} />,
161
- onSelect: () => goTo('import-export'),
169
+ onSelect: startExport,
162
170
  },
163
171
  ]}
164
172
  />
@@ -169,6 +177,7 @@ export default function VehiclesPage() {
169
177
  maintenance status here so you always know which vehicles are road-ready before dispatching
170
178
  an order.
171
179
  </PagePurpose>
180
+ <ExportStatusBanner state={exportState} onDismiss={dismissExport} />
172
181
 
173
182
  {/* Fleet at a glance — premium stat cards */}
174
183
  <div>
@@ -513,14 +513,29 @@ export interface Route {
513
513
  }
514
514
 
515
515
  // Tracking alert type
516
+ export type TrackingAlertSeverity = 'low' | 'medium' | 'high' | 'critical';
517
+
516
518
  export interface TrackingAlert {
517
519
  id: string;
518
520
  type: 'delay' | 'deviation' | 'temperature' | 'damage' | 'security';
519
- severity: 'low' | 'medium' | 'high' | 'critical';
521
+ severity: TrackingAlertSeverity;
520
522
  message: string;
521
523
  timestamp?: Date;
522
524
  acknowledged: boolean;
523
525
  resolvedAt?: Date;
526
+ /** Server alert kind for shipment alerts (BOFF-10397). */
527
+ kind?: 'DELAYED' | 'AT_RISK';
528
+ shipmentId?: string;
529
+ shipmentNumber?: string;
530
+ /** 0–100 forecast risk score; AT_RISK alerts only. */
531
+ riskScore?: number;
532
+ /** The shipment's promised delivery the alert was raised against. */
533
+ promisedDelivery?: Date;
534
+ /** Earliest forecast delivery time; AT_RISK alerts only. */
535
+ predictedDelivery?: Date;
536
+ /** Contributing risk signal codes; AT_RISK alerts only. */
537
+ signals?: string[];
538
+ acknowledgedAt?: Date;
524
539
  }
525
540
 
526
541
  // Tracking type
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Entity export — starts a MoveTheWheels export job and waits for its archive.
3
+ *
4
+ * `exportMtwEntities` hands the request to wspace-export-svc, which builds a
5
+ * ZIP of the workspace's records in the background. The job is read back with
6
+ * `getExportJob` until it reports COMPLETED (with a presigned `downloadUrl`),
7
+ * FAILED/CANCELLED/EXPIRED, or the wait budget runs out. A job that is still
8
+ * running when the budget is spent keeps going server side and stays
9
+ * downloadable from the shared Exports page.
10
+ *
11
+ * Kept free of React so the polling contract can be unit-tested.
12
+ */
13
+
14
+ /** List pages that offer an export, mapped to wspace-export-svc entity types. */
15
+ export const MTW_EXPORT_ENTITY_TYPES = {
16
+ customers: 'movethewheels_customers',
17
+ drivers: 'movethewheels_drivers',
18
+ orders: 'movethewheels_delivery_jobs',
19
+ products: 'movethewheels_cargo_items',
20
+ vehicles: 'movethewheels_vehicles',
21
+ } as const;
22
+
23
+ export type MtwExportEntity = keyof typeof MTW_EXPORT_ENTITY_TYPES;
24
+
25
+ export const START_MTW_EXPORT_MUTATION = `
26
+ mutation StartMovethewheelsEntityExport($input: ExportMtwEntitiesInput!) {
27
+ exportMtwEntities(input: $input) {
28
+ id
29
+ status
30
+ downloadUrl
31
+ }
32
+ }
33
+ `;
34
+
35
+ export const GET_MTW_EXPORT_JOB_QUERY = `
36
+ query GetMovethewheelsExportJob($id: ID!) {
37
+ getExportJob(id: $id) {
38
+ id
39
+ status
40
+ progress
41
+ downloadUrl
42
+ errorMessage
43
+ }
44
+ }
45
+ `;
46
+
47
+ export interface ExportJobSnapshot {
48
+ id: string;
49
+ status: string;
50
+ progress?: number | null;
51
+ downloadUrl?: string | null;
52
+ errorMessage?: string | null;
53
+ }
54
+
55
+ export type ExportJobOutcome =
56
+ | { kind: 'ready'; jobId: string; downloadUrl: string }
57
+ | { kind: 'failed'; jobId: string; message: string }
58
+ | { kind: 'pending'; jobId: string };
59
+
60
+ const TERMINAL_FAILURES = new Set(['FAILED', 'CANCELLED', 'EXPIRED']);
61
+
62
+ /** Classify one job snapshot; `null` means keep waiting. */
63
+ export function classifyExportJob(job: ExportJobSnapshot): ExportJobOutcome | null {
64
+ if (job.status === 'COMPLETED') {
65
+ if (job.downloadUrl) return { kind: 'ready', jobId: job.id, downloadUrl: job.downloadUrl };
66
+ return {
67
+ kind: 'failed',
68
+ jobId: job.id,
69
+ message: 'The export finished without a download link.',
70
+ };
71
+ }
72
+ if (TERMINAL_FAILURES.has(job.status)) {
73
+ return {
74
+ kind: 'failed',
75
+ jobId: job.id,
76
+ message: job.errorMessage?.trim() || `The export was ${job.status.toLowerCase()}.`,
77
+ };
78
+ }
79
+ return null;
80
+ }
81
+
82
+ export interface WaitForExportOptions {
83
+ /** Delay between reads of the job. */
84
+ intervalMs?: number;
85
+ /** Total time to wait before reporting the job as still pending. */
86
+ timeoutMs?: number;
87
+ /** Injectable for tests. */
88
+ sleep?: (ms: number) => Promise<void>;
89
+ /** Injectable for tests. */
90
+ now?: () => number;
91
+ /** Stops waiting (e.g. the page unmounted); resolves as pending. */
92
+ signal?: AbortSignal;
93
+ }
94
+
95
+ const defaultSleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
96
+
97
+ /**
98
+ * Read the job until it settles or the wait budget is spent. `initial` is the
99
+ * snapshot returned by the start mutation, so an already-finished job resolves
100
+ * without another round trip.
101
+ */
102
+ export async function waitForExportJob(
103
+ initial: ExportJobSnapshot,
104
+ fetchJob: (id: string) => Promise<ExportJobSnapshot | null>,
105
+ {
106
+ intervalMs = 2000,
107
+ timeoutMs = 90000,
108
+ sleep = defaultSleep,
109
+ now = Date.now,
110
+ signal,
111
+ }: WaitForExportOptions = {}
112
+ ): Promise<ExportJobOutcome> {
113
+ const settled = classifyExportJob(initial);
114
+ if (settled) return settled;
115
+
116
+ const deadline = now() + timeoutMs;
117
+ while (now() < deadline) {
118
+ if (signal?.aborted) break;
119
+ await sleep(intervalMs);
120
+ if (signal?.aborted) break;
121
+ const job = await fetchJob(initial.id);
122
+ if (!job) {
123
+ return { kind: 'failed', jobId: initial.id, message: 'The export job could not be found.' };
124
+ }
125
+ const outcome = classifyExportJob(job);
126
+ if (outcome) return outcome;
127
+ }
128
+ return { kind: 'pending', jobId: initial.id };
129
+ }
130
+
131
+ /** Start the archive download in the current tab without navigating away. */
132
+ export function triggerUrlDownload(url: string): void {
133
+ if (typeof document === 'undefined') return;
134
+ const anchor = document.createElement('a');
135
+ anchor.href = url;
136
+ anchor.rel = 'noopener';
137
+ document.body.appendChild(anchor);
138
+ anchor.click();
139
+ anchor.remove();
140
+ }
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Tracking alert mapping (BOFF-10397).
3
+ *
4
+ * `trackingAlerts` returns two kinds of alert: `DELAYED` once a shipment's
5
+ * promised delivery has passed, and the predictive `AT_RISK` alert raised
6
+ * while the promise is still ahead but the deterministic forecast says it
7
+ * will be missed. These helpers turn the API rows into the UI model: a
8
+ * severity, the predicted window and the contributing signals.
9
+ */
10
+
11
+ import type { TrackingAlert, TrackingAlertSeverity } from '../types';
12
+
13
+ export type RiskSignalCode =
14
+ | 'LEG_SLIP'
15
+ | 'OPEN_LEG_OVERDUE'
16
+ | 'ROUTE_DURATION_OVERRUN'
17
+ | 'EXCESS_DWELL'
18
+ | 'TRACKING_STALE'
19
+ | 'VEHICLE_UNAVAILABLE'
20
+ | 'CARRIER_LATE_HISTORY';
21
+
22
+ export type TrackingAlertKind = 'DELAYED' | 'AT_RISK';
23
+
24
+ export interface ApiTrackingAlert {
25
+ id: string;
26
+ shipmentId: string;
27
+ shipmentNumber: string;
28
+ alertType: string;
29
+ message: string;
30
+ riskScore?: number | null;
31
+ promisedDelivery?: string | null;
32
+ predictedDelivery?: string | null;
33
+ signals?: RiskSignalCode[] | null;
34
+ acknowledged: boolean;
35
+ acknowledgedAt?: string | null;
36
+ }
37
+
38
+ /** Risk score at or above which an AT_RISK alert is shown as high severity (matches the backend HIGH level). */
39
+ export const HIGH_RISK_SCORE = 70;
40
+
41
+ /**
42
+ * DELAYED is always high: the promise is already broken. AT_RISK follows the
43
+ * forecast's risk score; the backend only raises AT_RISK at MEDIUM or above,
44
+ * so anything below the HIGH band is medium.
45
+ */
46
+ export function trackingAlertSeverity(
47
+ alertType: string,
48
+ riskScore: number | null | undefined
49
+ ): TrackingAlertSeverity {
50
+ if (alertType === 'DELAYED') return 'high';
51
+ if (alertType === 'AT_RISK') {
52
+ return typeof riskScore === 'number' && riskScore >= HIGH_RISK_SCORE ? 'high' : 'medium';
53
+ }
54
+ return 'medium';
55
+ }
56
+
57
+ const toDate = (value: string | null | undefined): Date | undefined => {
58
+ if (!value) return undefined;
59
+ const date = new Date(value);
60
+ return Number.isNaN(date.getTime()) ? undefined : date;
61
+ };
62
+
63
+ export function mapTrackingAlert(alert: ApiTrackingAlert): TrackingAlert {
64
+ const kind: TrackingAlertKind = alert.alertType === 'AT_RISK' ? 'AT_RISK' : 'DELAYED';
65
+ return {
66
+ id: alert.id,
67
+ type: 'delay',
68
+ kind,
69
+ severity: trackingAlertSeverity(alert.alertType, alert.riskScore),
70
+ message: alert.message,
71
+ shipmentId: alert.shipmentId,
72
+ shipmentNumber: alert.shipmentNumber,
73
+ riskScore: alert.riskScore ?? undefined,
74
+ promisedDelivery: toDate(alert.promisedDelivery),
75
+ predictedDelivery: toDate(alert.predictedDelivery),
76
+ signals: alert.signals ?? [],
77
+ acknowledged: alert.acknowledged,
78
+ acknowledgedAt: toDate(alert.acknowledgedAt),
79
+ };
80
+ }
81
+
82
+ /** Highest severity first, then highest risk score; stable otherwise. */
83
+ const SEVERITY_RANK: Record<TrackingAlertSeverity, number> = {
84
+ critical: 0,
85
+ high: 1,
86
+ medium: 2,
87
+ low: 3,
88
+ };
89
+
90
+ export function sortTrackingAlerts(alerts: TrackingAlert[]): TrackingAlert[] {
91
+ return [...alerts].sort(
92
+ (a, b) =>
93
+ SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] ||
94
+ (b.riskScore ?? -1) - (a.riskScore ?? -1)
95
+ );
96
+ }
97
+
98
+ /** Translation key + English fallback for each risk signal code. */
99
+ export const RISK_SIGNAL_LABELS: Record<RiskSignalCode, { key: string; fallback: string }> = {
100
+ LEG_SLIP: { key: 'movethewheels.risk.signals.legSlip', fallback: 'Leg running late' },
101
+ OPEN_LEG_OVERDUE: { key: 'movethewheels.risk.signals.openLegOverdue', fallback: 'Leg overdue' },
102
+ ROUTE_DURATION_OVERRUN: {
103
+ key: 'movethewheels.risk.signals.routeOverrun',
104
+ fallback: 'Route taking longer than planned',
105
+ },
106
+ EXCESS_DWELL: { key: 'movethewheels.risk.signals.excessDwell', fallback: 'Long stop' },
107
+ TRACKING_STALE: {
108
+ key: 'movethewheels.risk.signals.trackingStale',
109
+ fallback: 'No recent tracking',
110
+ },
111
+ VEHICLE_UNAVAILABLE: {
112
+ key: 'movethewheels.risk.signals.vehicleUnavailable',
113
+ fallback: 'Vehicle unavailable',
114
+ },
115
+ CARRIER_LATE_HISTORY: {
116
+ key: 'movethewheels.risk.signals.carrierLateHistory',
117
+ fallback: 'Carrier often late',
118
+ },
119
+ };
120
+
121
+ export function riskSignalLabel(
122
+ code: string,
123
+ t: (key: string, fallback: string) => string
124
+ ): string {
125
+ const label = RISK_SIGNAL_LABELS[code as RiskSignalCode];
126
+ return label ? t(label.key, label.fallback) : code;
127
+ }
128
+
129
+ /** Minutes between the promise and the predicted delivery, or null when unknown / not late. */
130
+ export function predictedSlipMinutes(
131
+ alert: Pick<TrackingAlert, 'promisedDelivery' | 'predictedDelivery'>
132
+ ): number | null {
133
+ if (!alert.promisedDelivery || !alert.predictedDelivery) return null;
134
+ const minutes = Math.round(
135
+ (alert.predictedDelivery.getTime() - alert.promisedDelivery.getTime()) / 60_000
136
+ );
137
+ return minutes > 0 ? minutes : null;
138
+ }
139
+
140
+ /** "45 min", "3 h 20 min", "2 d 4 h" — compact duration for alert cards. */
141
+ export function formatSlip(minutes: number): string {
142
+ if (minutes < 60) return `${minutes} min`;
143
+ const hours = Math.floor(minutes / 60);
144
+ if (hours < 24) {
145
+ const rest = minutes % 60;
146
+ return rest > 0 ? `${hours} h ${rest} min` : `${hours} h`;
147
+ }
148
+ const days = Math.floor(hours / 24);
149
+ const restHours = hours % 24;
150
+ return restHours > 0 ? `${days} d ${restHours} h` : `${days} d`;
151
+ }