@burdenoff/microfe-movethewheels 2026.1108.5 → 2026.1109.1
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/generated/wspace-operations.d.ts +91 -0
- package/dist/generated/wspace-types.d.ts +43259 -9124
- package/dist/hooks/useRoutes.js +91 -52
- package/dist/movethewheels/hooks/useRoutes.d.ts +3 -2
- package/dist/movethewheels/types/index.d.ts +21 -1
- package/dist/pages/RouteDetailsPage.js +344 -274
- package/dist/utils/formatters.js +6 -1
- package/package.json +1 -1
- package/src/generated/wspace-operations.ts +13 -12
- package/src/generated/wspace-types.ts +43737 -9125
- package/src/movethewheels/hooks/useRoutes.ts +37 -10
- package/src/movethewheels/pages/RouteDetailsPage.tsx +107 -10
- package/src/movethewheels/types/index.ts +27 -1
- package/src/operations/wspace/movethewheels/fragments/core.graphql +15 -0
- package/src/operations/wspace/movethewheels/mutations/logistics.graphql +2 -2
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
Route,
|
|
5
|
+
RouteOptimizationStrategy,
|
|
6
|
+
RouteOptimizationSummary,
|
|
7
|
+
RouteStop,
|
|
8
|
+
} from '../types';
|
|
4
9
|
import { executeGraphQL } from '../utils/graphqlClient';
|
|
5
10
|
|
|
6
11
|
interface UseRoutesOptions {
|
|
@@ -32,7 +37,7 @@ interface UseRoutesResult {
|
|
|
32
37
|
}
|
|
33
38
|
) => Promise<Route>;
|
|
34
39
|
deleteRoute: (id: string) => Promise<void>;
|
|
35
|
-
optimizeRoute: (routeId: string) => Promise<Route>;
|
|
40
|
+
optimizeRoute: (routeId: string, strategy?: RouteOptimizationStrategy) => Promise<Route>;
|
|
36
41
|
updateStopStatus: (
|
|
37
42
|
routeId: string,
|
|
38
43
|
stopId: string,
|
|
@@ -53,9 +58,28 @@ interface ApiRoute {
|
|
|
53
58
|
fuelCost?: number | null;
|
|
54
59
|
actualDistance?: number | null;
|
|
55
60
|
actualDuration?: number | null;
|
|
61
|
+
lastOptimization?: RouteOptimizationSummary | null;
|
|
56
62
|
createdAt: string;
|
|
57
63
|
}
|
|
58
64
|
|
|
65
|
+
const LAST_OPTIMIZATION_FIELDS = `
|
|
66
|
+
lastOptimization {
|
|
67
|
+
strategy
|
|
68
|
+
ranAt
|
|
69
|
+
waypointCount
|
|
70
|
+
distanceBeforeKm
|
|
71
|
+
distanceAfterKm
|
|
72
|
+
distanceSavedKm
|
|
73
|
+
durationAfterMinutes
|
|
74
|
+
feasible
|
|
75
|
+
violations {
|
|
76
|
+
code
|
|
77
|
+
message
|
|
78
|
+
sequence
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
|
|
59
83
|
const LIST_ROUTES_QUERY = `
|
|
60
84
|
query ListRoutes($filter: RouteFilterInput, $pagination: PaginationInput) {
|
|
61
85
|
routes(filter: $filter, pagination: $pagination) {
|
|
@@ -93,6 +117,7 @@ const GET_ROUTE_QUERY = `
|
|
|
93
117
|
actualDistance
|
|
94
118
|
actualDuration
|
|
95
119
|
createdAt
|
|
120
|
+
${LAST_OPTIMIZATION_FIELDS}
|
|
96
121
|
}
|
|
97
122
|
}
|
|
98
123
|
`;
|
|
@@ -144,8 +169,8 @@ const DELETE_ROUTE_MUTATION = `
|
|
|
144
169
|
`;
|
|
145
170
|
|
|
146
171
|
const OPTIMIZE_ROUTE_MUTATION = `
|
|
147
|
-
mutation OptimizeRoute($id: ID
|
|
148
|
-
optimizeRoute(id: $id) {
|
|
172
|
+
mutation OptimizeRoute($id: ID!, $input: OptimizeRouteInput) {
|
|
173
|
+
optimizeRoute(id: $id, input: $input) {
|
|
149
174
|
id
|
|
150
175
|
name
|
|
151
176
|
status
|
|
@@ -159,6 +184,7 @@ const OPTIMIZE_ROUTE_MUTATION = `
|
|
|
159
184
|
actualDistance
|
|
160
185
|
actualDuration
|
|
161
186
|
createdAt
|
|
187
|
+
${LAST_OPTIMIZATION_FIELDS}
|
|
162
188
|
}
|
|
163
189
|
}
|
|
164
190
|
`;
|
|
@@ -247,10 +273,10 @@ export function mapRoute(route: ApiRoute): Route {
|
|
|
247
273
|
estimatedDuration: route.estimatedDuration ?? 0,
|
|
248
274
|
fuelCost: route.fuelCost ?? undefined,
|
|
249
275
|
actualDuration: route.actualDuration ?? undefined,
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
|
|
276
|
+
// `lastOptimization` is the persisted proof that the optimize mutation ran;
|
|
277
|
+
// `estimatedDistance` alone is only a measurement.
|
|
278
|
+
optimized: route.lastOptimization ? true : undefined,
|
|
279
|
+
lastOptimization: route.lastOptimization ?? undefined,
|
|
254
280
|
createdAt: new Date(route.createdAt),
|
|
255
281
|
};
|
|
256
282
|
}
|
|
@@ -440,15 +466,16 @@ export function useRoutes(options: UseRoutesOptions = {}): UseRoutesResult {
|
|
|
440
466
|
);
|
|
441
467
|
|
|
442
468
|
const optimizeRoute = useCallback(
|
|
443
|
-
async (routeId: string): Promise<Route> => {
|
|
469
|
+
async (routeId: string, strategy?: RouteOptimizationStrategy): Promise<Route> => {
|
|
444
470
|
const data = await executeGraphQL<{ optimizeRoute: ApiRoute }>(
|
|
445
471
|
graphQLOptions,
|
|
446
472
|
OPTIMIZE_ROUTE_MUTATION,
|
|
447
473
|
{
|
|
448
474
|
id: routeId,
|
|
475
|
+
input: strategy ? { strategy } : undefined,
|
|
449
476
|
}
|
|
450
477
|
);
|
|
451
|
-
const optimized =
|
|
478
|
+
const optimized = mapRoute(data.optimizeRoute);
|
|
452
479
|
setRoutes((previous) => previous.map((item) => (item.id === routeId ? optimized : item)));
|
|
453
480
|
return optimized;
|
|
454
481
|
},
|
|
@@ -58,12 +58,23 @@ import { useRefetchOnLeaveEdit } from '../hooks/useRefetchOnLeaveEdit';
|
|
|
58
58
|
import { AssignmentSuggestions } from '../components/AssignmentSuggestions';
|
|
59
59
|
import { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';
|
|
60
60
|
import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
|
|
61
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
formatDate,
|
|
63
|
+
formatAddress,
|
|
64
|
+
formatCurrency,
|
|
65
|
+
formatDistance,
|
|
66
|
+
formatDuration,
|
|
67
|
+
} from '../utils/formatters';
|
|
62
68
|
import { joinPath } from '../utils/navigation';
|
|
63
69
|
import { ROUTE_STATUS_COLORS } from '../constants';
|
|
64
70
|
import { FormError } from '../components/FormError';
|
|
65
71
|
import { Notice, useNotice } from '../components/Notice';
|
|
66
|
-
import type {
|
|
72
|
+
import type {
|
|
73
|
+
Route as RouteType,
|
|
74
|
+
RouteOptimizationStrategy,
|
|
75
|
+
RouteOptimizationSummary,
|
|
76
|
+
RouteStop,
|
|
77
|
+
} from '../types';
|
|
67
78
|
|
|
68
79
|
const ROUTE_STATUS_OPTIONS: { value: RouteType['status']; label: string }[] = [
|
|
69
80
|
{ value: 'planned', label: 'Planned' },
|
|
@@ -433,6 +444,65 @@ function NewRouteForm({ editId }: { editId?: string }) {
|
|
|
433
444
|
);
|
|
434
445
|
}
|
|
435
446
|
|
|
447
|
+
function OptimizationSummaryCard({ summary }: { summary: RouteOptimizationSummary }) {
|
|
448
|
+
const ranAt = new Date(summary.ranAt);
|
|
449
|
+
const when = Number.isNaN(ranAt.getTime())
|
|
450
|
+
? summary.ranAt
|
|
451
|
+
: ranAt.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
|
452
|
+
return (
|
|
453
|
+
<Card className="mb-6">
|
|
454
|
+
<CardHeader>
|
|
455
|
+
<CardTitle className="flex items-center gap-2">
|
|
456
|
+
<Zap size={16} />
|
|
457
|
+
Last optimization
|
|
458
|
+
<Badge variant={summary.feasible ? 'default' : 'secondary'}>
|
|
459
|
+
{summary.feasible ? 'Feasible' : `${summary.violations.length} warning(s)`}
|
|
460
|
+
</Badge>
|
|
461
|
+
</CardTitle>
|
|
462
|
+
</CardHeader>
|
|
463
|
+
<CardContent className="space-y-2 text-sm">
|
|
464
|
+
<div className="flex flex-wrap gap-x-6 gap-y-1">
|
|
465
|
+
<span>
|
|
466
|
+
Strategy: <strong>{summary.strategy}</strong>
|
|
467
|
+
</span>
|
|
468
|
+
<span>
|
|
469
|
+
Run: <strong>{when}</strong>
|
|
470
|
+
</span>
|
|
471
|
+
{summary.distanceAfterKm != null && (
|
|
472
|
+
<span>
|
|
473
|
+
Distance: <strong>{formatDistance(summary.distanceAfterKm)}</strong>
|
|
474
|
+
</span>
|
|
475
|
+
)}
|
|
476
|
+
{summary.distanceSavedKm != null && summary.distanceSavedKm > 0 && (
|
|
477
|
+
<span>
|
|
478
|
+
Saved: <strong>{formatDistance(summary.distanceSavedKm)}</strong> vs recorded order
|
|
479
|
+
</span>
|
|
480
|
+
)}
|
|
481
|
+
{summary.durationAfterMinutes != null && (
|
|
482
|
+
<span>
|
|
483
|
+
Drive time: <strong>{formatDuration(summary.durationAfterMinutes)}</strong>
|
|
484
|
+
</span>
|
|
485
|
+
)}
|
|
486
|
+
</div>
|
|
487
|
+
{summary.violations.length > 0 && (
|
|
488
|
+
<ul className="list-disc pl-5 space-y-1">
|
|
489
|
+
{summary.violations.map((violation, index) => (
|
|
490
|
+
<li key={`${violation.code}-${index}`}>
|
|
491
|
+
{violation.message}
|
|
492
|
+
{violation.sequence != null && (
|
|
493
|
+
<Badge variant="outline" className="ml-2">
|
|
494
|
+
stop {violation.sequence}
|
|
495
|
+
</Badge>
|
|
496
|
+
)}
|
|
497
|
+
</li>
|
|
498
|
+
))}
|
|
499
|
+
</ul>
|
|
500
|
+
)}
|
|
501
|
+
</CardContent>
|
|
502
|
+
</Card>
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
436
506
|
export default function RouteDetailsPage() {
|
|
437
507
|
const { routeId } = useParams<{ routeId: string }>();
|
|
438
508
|
const isEditRoute = useLocation().pathname.endsWith('/edit');
|
|
@@ -449,6 +519,7 @@ export default function RouteDetailsPage() {
|
|
|
449
519
|
const { message: notice, notify } = useNotice();
|
|
450
520
|
const [optimizeError, setOptimizeError] = useState<string | null>(null);
|
|
451
521
|
const [optimizing, setOptimizing] = useState(false);
|
|
522
|
+
const [optimizeStrategy, setOptimizeStrategy] = useState<RouteOptimizationStrategy>('AUTO');
|
|
452
523
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
|
453
524
|
const [deleting, setDeleting] = useState(false);
|
|
454
525
|
const [deleteError, setDeleteError] = useState<string | null>(null);
|
|
@@ -475,8 +546,15 @@ export default function RouteDetailsPage() {
|
|
|
475
546
|
setOptimizing(true);
|
|
476
547
|
setOptimizeError(null);
|
|
477
548
|
try {
|
|
478
|
-
await optimizeRoute(routeId);
|
|
479
|
-
|
|
549
|
+
const updated = await optimizeRoute(routeId, optimizeStrategy);
|
|
550
|
+
const summary = updated.lastOptimization;
|
|
551
|
+
if (summary && !summary.feasible) {
|
|
552
|
+
notify(
|
|
553
|
+
`Route optimized with ${summary.violations.length} constraint warning(s) — see the optimization panel below.`
|
|
554
|
+
);
|
|
555
|
+
} else {
|
|
556
|
+
notify('Route optimized — stops resequenced for the shortest feasible run.');
|
|
557
|
+
}
|
|
480
558
|
refetch();
|
|
481
559
|
} catch (e) {
|
|
482
560
|
setOptimizeError(e instanceof Error ? e.message : 'Failed to optimize route.');
|
|
@@ -534,10 +612,27 @@ export default function RouteDetailsPage() {
|
|
|
534
612
|
<Button variant="outline" onClick={goBack}>
|
|
535
613
|
<ArrowLeft size={16} /> Back
|
|
536
614
|
</Button>
|
|
537
|
-
{
|
|
538
|
-
|
|
539
|
-
<
|
|
540
|
-
|
|
615
|
+
{(route.status === 'planned' || route.status === 'in_progress') && (
|
|
616
|
+
<>
|
|
617
|
+
<Select
|
|
618
|
+
value={optimizeStrategy}
|
|
619
|
+
onValueChange={(value) => setOptimizeStrategy(value as RouteOptimizationStrategy)}
|
|
620
|
+
>
|
|
621
|
+
<SelectTrigger className="w-44" aria-label="Optimization strategy">
|
|
622
|
+
<SelectValue />
|
|
623
|
+
</SelectTrigger>
|
|
624
|
+
<SelectContent>
|
|
625
|
+
<SelectItem value="AUTO">Auto (windows + 2-opt)</SelectItem>
|
|
626
|
+
<SelectItem value="NEAREST_NEIGHBOUR">Nearest neighbour</SelectItem>
|
|
627
|
+
<SelectItem value="TIME_WINDOW">Time windows</SelectItem>
|
|
628
|
+
<SelectItem value="TWO_OPT">Shortest tour (2-opt)</SelectItem>
|
|
629
|
+
</SelectContent>
|
|
630
|
+
</Select>
|
|
631
|
+
<Button variant="outline" onClick={handleOptimize} disabled={optimizing}>
|
|
632
|
+
<Zap size={16} />{' '}
|
|
633
|
+
{optimizing ? 'Optimizing…' : route.optimized ? 'Re-optimize' : 'Optimize & start'}
|
|
634
|
+
</Button>
|
|
635
|
+
</>
|
|
541
636
|
)}
|
|
542
637
|
<Button onClick={() => navigate?.(joinPath(basePath, `routes/${routeId}/edit`))}>
|
|
543
638
|
<Edit size={16} /> Edit
|
|
@@ -566,11 +661,11 @@ export default function RouteDetailsPage() {
|
|
|
566
661
|
<NextSteps
|
|
567
662
|
storageKey="movethewheels-route-details"
|
|
568
663
|
steps={[
|
|
569
|
-
...(
|
|
664
|
+
...(route.status === 'planned' || route.status === 'in_progress'
|
|
570
665
|
? [
|
|
571
666
|
{
|
|
572
667
|
id: 'optimize',
|
|
573
|
-
label: 'Optimize & start this route',
|
|
668
|
+
label: route.optimized ? 'Re-optimize this route' : 'Optimize & start this route',
|
|
574
669
|
description:
|
|
575
670
|
'Reorder stops to cut distance and driving time, then mark the route In Progress.',
|
|
576
671
|
icon: <Zap size={16} />,
|
|
@@ -606,6 +701,8 @@ export default function RouteDetailsPage() {
|
|
|
606
701
|
</div>
|
|
607
702
|
)}
|
|
608
703
|
|
|
704
|
+
{route.lastOptimization && <OptimizationSummaryCard summary={route.lastOptimization} />}
|
|
705
|
+
|
|
609
706
|
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
|
610
707
|
<div className="lg:col-span-2 space-y-6">
|
|
611
708
|
<Card>
|
|
@@ -498,6 +498,30 @@ export interface TrafficCondition {
|
|
|
498
498
|
location: string;
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
+
// Route optimization types (svc RouteOptimizationSummary)
|
|
502
|
+
export type RouteOptimizationStrategy = 'AUTO' | 'NEAREST_NEIGHBOUR' | 'TIME_WINDOW' | 'TWO_OPT';
|
|
503
|
+
|
|
504
|
+
export type RouteOptimizationViolationCode =
|
|
505
|
+
'WINDOW_MISSED' | 'OVER_CAPACITY' | 'OVER_DRIVER_HOURS' | 'NO_COORDINATES';
|
|
506
|
+
|
|
507
|
+
export interface RouteOptimizationViolation {
|
|
508
|
+
code: RouteOptimizationViolationCode;
|
|
509
|
+
message: string;
|
|
510
|
+
sequence?: number | null;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export interface RouteOptimizationSummary {
|
|
514
|
+
strategy: RouteOptimizationStrategy;
|
|
515
|
+
ranAt: string;
|
|
516
|
+
waypointCount: number;
|
|
517
|
+
distanceBeforeKm?: number | null;
|
|
518
|
+
distanceAfterKm?: number | null;
|
|
519
|
+
distanceSavedKm?: number | null;
|
|
520
|
+
durationAfterMinutes?: number | null;
|
|
521
|
+
feasible: boolean;
|
|
522
|
+
violations: RouteOptimizationViolation[];
|
|
523
|
+
}
|
|
524
|
+
|
|
501
525
|
// Route type
|
|
502
526
|
export interface Route {
|
|
503
527
|
id: string;
|
|
@@ -511,8 +535,10 @@ export interface Route {
|
|
|
511
535
|
/** Estimated fuel cost for the route (svc MtwRoute.fuelCost). */
|
|
512
536
|
fuelCost?: number;
|
|
513
537
|
actualDuration?: number;
|
|
514
|
-
/**
|
|
538
|
+
/** True once the backend reports a persisted optimization summary. */
|
|
515
539
|
optimized?: boolean;
|
|
540
|
+
/** Summary of the most recent optimizeRoute run, when one has run. */
|
|
541
|
+
lastOptimization?: RouteOptimizationSummary;
|
|
516
542
|
createdAt: Date;
|
|
517
543
|
}
|
|
518
544
|
|
|
@@ -135,6 +135,21 @@ fragment RouteCore on MtwRoute {
|
|
|
135
135
|
actualDistance
|
|
136
136
|
actualDuration
|
|
137
137
|
fuelCost
|
|
138
|
+
lastOptimization {
|
|
139
|
+
strategy
|
|
140
|
+
ranAt
|
|
141
|
+
waypointCount
|
|
142
|
+
distanceBeforeKm
|
|
143
|
+
distanceAfterKm
|
|
144
|
+
distanceSavedKm
|
|
145
|
+
durationAfterMinutes
|
|
146
|
+
feasible
|
|
147
|
+
violations {
|
|
148
|
+
code
|
|
149
|
+
message
|
|
150
|
+
sequence
|
|
151
|
+
}
|
|
152
|
+
}
|
|
138
153
|
createdAt
|
|
139
154
|
updatedAt
|
|
140
155
|
}
|
|
@@ -48,8 +48,8 @@ mutation UpdateRoute($id: ID!, $input: UpdateRouteInput!) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
mutation OptimizeRoute($id: ID
|
|
52
|
-
optimizeRoute(id: $id) {
|
|
51
|
+
mutation OptimizeRoute($id: ID!, $input: OptimizeRouteInput) {
|
|
52
|
+
optimizeRoute(id: $id, input: $input) {
|
|
53
53
|
...RouteCore
|
|
54
54
|
}
|
|
55
55
|
}
|