@olenbetong/synergi-react 5.4.0 → 5.6.0

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 (133) hide show
  1. package/dist/styles/styles.css +1 -1
  2. package/dist/styles/styles.css.map +1 -1
  3. package/es/charts/CallOffDeliveries/TicketScanDialog.d.ts +7 -0
  4. package/es/charts/CallOffDeliveries/TicketScanDialog.js +47 -0
  5. package/es/charts/CallOffDeliveries/chartOptions.d.ts +8 -0
  6. package/es/charts/CallOffDeliveries/chartOptions.js +138 -0
  7. package/es/charts/CallOffDeliveries/data.d.ts +35 -0
  8. package/es/charts/CallOffDeliveries/data.js +30 -0
  9. package/es/charts/CallOffDeliveries/index.css +1 -0
  10. package/es/charts/CallOffDeliveries/index.d.ts +24 -0
  11. package/es/charts/CallOffDeliveries/index.js +115 -0
  12. package/es/charts/CallOffDeliveries/model.d.ts +37 -0
  13. package/es/charts/CallOffDeliveries/model.js +59 -0
  14. package/es/charts/ProductionPlan/PlanValueDialog.d.ts +14 -0
  15. package/es/charts/ProductionPlan/PlanValueDialog.js +47 -0
  16. package/es/charts/ProductionPlan/chartOptions.d.ts +20 -0
  17. package/es/charts/ProductionPlan/chartOptions.js +353 -0
  18. package/es/charts/ProductionPlan/data.d.ts +105 -0
  19. package/es/charts/ProductionPlan/data.js +61 -0
  20. package/es/charts/ProductionPlan/index.css +1 -0
  21. package/es/charts/ProductionPlan/index.d.ts +31 -0
  22. package/es/charts/ProductionPlan/index.js +203 -0
  23. package/es/charts/ProductionPlan/model.d.ts +29 -0
  24. package/es/charts/ProductionPlan/model.js +65 -0
  25. package/es/charts/Pumping/chartOptions.d.ts +12 -0
  26. package/es/charts/Pumping/chartOptions.js +197 -0
  27. package/es/charts/Pumping/data.d.ts +65 -0
  28. package/es/charts/Pumping/data.js +20 -0
  29. package/es/charts/Pumping/index.css +1 -0
  30. package/es/charts/Pumping/index.d.ts +27 -0
  31. package/es/charts/Pumping/index.js +124 -0
  32. package/es/charts/Pumping/model.d.ts +34 -0
  33. package/es/charts/Pumping/model.js +88 -0
  34. package/es/charts/UnboundPreview/chartOptions.d.ts +3 -0
  35. package/es/charts/UnboundPreview/chartOptions.js +126 -0
  36. package/es/charts/UnboundPreview/index.css +1 -0
  37. package/es/charts/UnboundPreview/index.d.ts +20 -0
  38. package/es/charts/UnboundPreview/index.js +55 -0
  39. package/es/charts/UnboundPreview/model.d.ts +49 -0
  40. package/es/charts/UnboundPreview/model.js +67 -0
  41. package/es/charts/VehicleDeliveries/chartOptions.d.ts +13 -0
  42. package/es/charts/VehicleDeliveries/chartOptions.js +270 -0
  43. package/es/charts/VehicleDeliveries/data.d.ts +71 -0
  44. package/es/charts/VehicleDeliveries/data.js +20 -0
  45. package/es/charts/VehicleDeliveries/deliveryXRange.d.ts +4 -0
  46. package/es/charts/VehicleDeliveries/deliveryXRange.js +62 -0
  47. package/es/charts/VehicleDeliveries/index.css +1 -0
  48. package/es/charts/VehicleDeliveries/index.d.ts +24 -0
  49. package/es/charts/VehicleDeliveries/index.js +129 -0
  50. package/es/charts/VehicleDeliveries/model.d.ts +24 -0
  51. package/es/charts/VehicleDeliveries/model.js +106 -0
  52. package/es/charts/format.d.ts +12 -0
  53. package/es/charts/format.js +34 -0
  54. package/es/charts/index.d.ts +5 -0
  55. package/es/charts/index.js +5 -0
  56. package/es/charts/storage.d.ts +5 -0
  57. package/es/charts/storage.js +35 -0
  58. package/es/chrome/assistant.d.ts +75 -0
  59. package/es/chrome/assistant.js +116 -0
  60. package/es/components/ColorCard/index.css +8 -8
  61. package/es/index.css +1 -1
  62. package/es/index.d.ts +1 -0
  63. package/es/index.js +1 -0
  64. package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.d.ts +4 -0
  65. package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.js +51 -0
  66. package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.d.ts +99 -0
  67. package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.js +499 -0
  68. package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.d.ts +13 -0
  69. package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.js +69 -0
  70. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.d.ts +33 -0
  71. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.js +164 -0
  72. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.d.ts +15 -0
  73. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.js +80 -0
  74. package/es/vehicles/VehicleInfoDialog/formatting.d.ts +13 -0
  75. package/es/vehicles/VehicleInfoDialog/formatting.js +48 -0
  76. package/es/vehicles/VehicleInfoDialog/index.css +1 -0
  77. package/es/vehicles/VehicleInfoDialog/index.d.ts +11 -0
  78. package/es/vehicles/VehicleInfoDialog/index.js +46 -0
  79. package/es/vehicles/VehicleInfoDialog/tabs.d.ts +6 -0
  80. package/es/vehicles/VehicleInfoDialog/tabs.js +85 -0
  81. package/es/vehicles/index.d.ts +1 -0
  82. package/es/vehicles/index.js +1 -0
  83. package/package.json +17 -8
  84. package/src/charts/CallOffDeliveries/TicketScanDialog.tsx +79 -0
  85. package/src/charts/CallOffDeliveries/chartOptions.ts +160 -0
  86. package/src/charts/CallOffDeliveries/data.ts +67 -0
  87. package/src/charts/CallOffDeliveries/index.scss +51 -0
  88. package/src/charts/CallOffDeliveries/index.tsx +217 -0
  89. package/src/charts/CallOffDeliveries/model.test.ts +90 -0
  90. package/src/charts/CallOffDeliveries/model.ts +87 -0
  91. package/src/charts/ProductionPlan/PlanValueDialog.tsx +107 -0
  92. package/src/charts/ProductionPlan/chartOptions.ts +406 -0
  93. package/src/charts/ProductionPlan/data.ts +170 -0
  94. package/src/charts/ProductionPlan/index.scss +148 -0
  95. package/src/charts/ProductionPlan/index.tsx +432 -0
  96. package/src/charts/ProductionPlan/model.test.ts +132 -0
  97. package/src/charts/ProductionPlan/model.ts +102 -0
  98. package/src/charts/Pumping/chartOptions.ts +224 -0
  99. package/src/charts/Pumping/data.ts +91 -0
  100. package/src/charts/Pumping/index.scss +42 -0
  101. package/src/charts/Pumping/index.tsx +222 -0
  102. package/src/charts/Pumping/model.test.ts +122 -0
  103. package/src/charts/Pumping/model.ts +104 -0
  104. package/src/charts/UnboundPreview/chartOptions.ts +137 -0
  105. package/src/charts/UnboundPreview/index.scss +17 -0
  106. package/src/charts/UnboundPreview/index.tsx +100 -0
  107. package/src/charts/UnboundPreview/model.test.ts +129 -0
  108. package/src/charts/UnboundPreview/model.ts +110 -0
  109. package/src/charts/VehicleDeliveries/chartOptions.ts +311 -0
  110. package/src/charts/VehicleDeliveries/data.ts +98 -0
  111. package/src/charts/VehicleDeliveries/deliveryXRange.ts +80 -0
  112. package/src/charts/VehicleDeliveries/index.scss +43 -0
  113. package/src/charts/VehicleDeliveries/index.tsx +262 -0
  114. package/src/charts/VehicleDeliveries/model.test.ts +117 -0
  115. package/src/charts/VehicleDeliveries/model.ts +139 -0
  116. package/src/charts/format.ts +38 -0
  117. package/src/charts/index.ts +20 -0
  118. package/src/charts/storage.ts +36 -0
  119. package/src/chrome/assistant.test.tsx +106 -0
  120. package/src/chrome/assistant.ts +178 -0
  121. package/src/components/ColorCard/index.css +8 -8
  122. package/src/index.ts +9 -0
  123. package/src/vehicles/VehicleInfoDialog/OutOfServiceForm.tsx +127 -0
  124. package/src/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.ts +600 -0
  125. package/src/vehicles/VehicleInfoDialog/data/dsDriverStatus.ts +84 -0
  126. package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfo.ts +198 -0
  127. package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.ts +97 -0
  128. package/src/vehicles/VehicleInfoDialog/formatting.test.ts +57 -0
  129. package/src/vehicles/VehicleInfoDialog/formatting.ts +58 -0
  130. package/src/vehicles/VehicleInfoDialog/index.scss +131 -0
  131. package/src/vehicles/VehicleInfoDialog/index.tsx +106 -0
  132. package/src/vehicles/VehicleInfoDialog/tabs.tsx +188 -0
  133. package/src/vehicles/index.ts +1 -0
@@ -0,0 +1,122 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import type { PumpBookingRecord, PumpBookingsResult, PumpRecord } from "./data.js";
4
+ import { comparePumps, getBookingPlant, getChartData, getPumpFeature, getPumpHome } from "./model.js";
5
+
6
+ function pump(ObjectNo: number, extra: Partial<PumpRecord> = {}): PumpRecord {
7
+ return {
8
+ LocationID: 1,
9
+ ObjectNo,
10
+ Model: null,
11
+ MixerCapacity: 8,
12
+ BoomLength: null,
13
+ IsTruck: true,
14
+ IsPump: true,
15
+ BigPump: false,
16
+ Telescopic: false,
17
+ ConveyorBelt: false,
18
+ ...extra,
19
+ };
20
+ }
21
+
22
+ function booking(PlantID: number, ObjectNo: number, extra: Partial<PumpBookingRecord> = {}): PumpBookingRecord {
23
+ return {
24
+ PlantID,
25
+ CallOffID: 1,
26
+ ObjectNo,
27
+ IndirectBooking: false,
28
+ IndirectPlantID: null,
29
+ CustomerName: null,
30
+ Qty: null,
31
+ DeliveredQty: null,
32
+ Site: null,
33
+ SiteAddress: null,
34
+ SiteCity: null,
35
+ SitePosition: null,
36
+ PumpStart: new Date(0),
37
+ PumpEnd: new Date(1),
38
+ Comment: null,
39
+ HoseLength: null,
40
+ ContactInfo: null,
41
+ ...extra,
42
+ };
43
+ }
44
+
45
+ function result(pumps: PumpRecord[], bookings: PumpBookingRecord[]): PumpBookingsResult {
46
+ return {
47
+ Table: [
48
+ { PlantID: 1, Description: "One" },
49
+ { PlantID: 2, Description: "Two" },
50
+ ],
51
+ Table1: pumps,
52
+ Table2: bookings,
53
+ Table3: [{ ObjectNo: 30, ObjectID: 1, FromDateTime: new Date(0), ToDateTime: new Date(1), Comment: null }],
54
+ };
55
+ }
56
+
57
+ describe("comparePumps", () => {
58
+ it("lists the pumps with a mixer before the big pumps, each by number", () => {
59
+ let sorted = [pump(4, { BigPump: true }), pump(3), pump(1, { BigPump: true }), pump(2)].toSorted(comparePumps);
60
+
61
+ expect(sorted.map((p) => p.ObjectNo)).toEqual([2, 3, 1, 4]);
62
+ });
63
+ });
64
+
65
+ describe("getChartData", () => {
66
+ it("gives each plant its pumps, those it has booked and their out-of-service periods", () => {
67
+ let charts = getChartData(
68
+ result([pump(10), pump(20, { LocationID: 2 }), pump(30, { LocationID: 2 })], [booking(1, 30)]),
69
+ [1, 2],
70
+ false,
71
+ );
72
+
73
+ expect(charts.map((chart) => chart.pumps.map((p) => p.ObjectNo))).toEqual([
74
+ [10, 30],
75
+ [20, 30],
76
+ ]);
77
+ expect(charts[0].bookings).toHaveLength(1);
78
+ expect(charts[1].bookings).toHaveLength(0);
79
+ expect(charts.map((chart) => chart.outOfService.length)).toEqual([1, 1]);
80
+ });
81
+
82
+ it("leaves out a plant without pumps", () => {
83
+ let charts = getChartData(result([pump(10)], []), [1, 2], false);
84
+
85
+ expect(charts.map((chart) => chart.key)).toEqual(["1"]);
86
+ });
87
+
88
+ it("keeps one chart in merged mode", () => {
89
+ let charts = getChartData(result([pump(10), pump(20, { LocationID: 2 })], [booking(1, 20)]), [1, 2], true);
90
+
91
+ expect(charts).toHaveLength(1);
92
+ expect(charts[0].plants).toHaveLength(2);
93
+ expect(charts[0].pumps).toHaveLength(2);
94
+ });
95
+
96
+ it("draws nothing without pumps", () => {
97
+ expect(getChartData(result([], []), [1], false)).toEqual([]);
98
+ });
99
+ });
100
+
101
+ describe("labels", () => {
102
+ let plants = [{ PlantID: 1, Description: "One" }];
103
+
104
+ it("names the home of a pump from elsewhere, and of every pump when merged", () => {
105
+ expect(getPumpHome({ LocationID: 1 }, plants, false)).toEqual({ show: false, home: 1 });
106
+ expect(getPumpHome({ LocationID: 2 }, plants, false)).toEqual({ show: true, home: 2 });
107
+ expect(getPumpHome({ LocationID: null }, plants, false)).toEqual({ show: true, home: null });
108
+ expect(getPumpHome({ LocationID: 1 }, plants, true)).toEqual({ show: true, home: 1 });
109
+ });
110
+
111
+ it("names the plant of a booking from another plant, and of every booking when merged", () => {
112
+ expect(getBookingPlant(booking(1, 10), false)).toBeNull();
113
+ expect(getBookingPlant(booking(1, 10, { IndirectBooking: true, IndirectPlantID: 5 }), false)).toBe(5);
114
+ expect(getBookingPlant(booking(1, 10), true)).toBe(1);
115
+ expect(getBookingPlant(booking(1, 10, { IndirectBooking: true, IndirectPlantID: 5 }), true)).toBe(5);
116
+ });
117
+
118
+ it("marks pumps and big pumps with the boom length", () => {
119
+ expect(getPumpFeature(pump(1, { BoomLength: 36 }))).toEqual({ label: "P 36m", color: "#DDDDFF" });
120
+ expect(getPumpFeature(pump(1, { BigPump: true, BoomLength: 52 }))?.label).toBe("S 52m");
121
+ });
122
+ });
@@ -0,0 +1,104 @@
1
+ import type { OutOfServiceRecord, PlantRecord, PumpBookingRecord, PumpBookingsResult, PumpRecord } from "./data.js";
2
+
3
+ export type ChartData = {
4
+ key: string;
5
+ plants: PlantRecord[];
6
+ pumps: PumpRecord[];
7
+ bookings: PumpBookingRecord[];
8
+ outOfService: OutOfServiceRecord[];
9
+ merged: boolean;
10
+ /** Index into the palette for each plant, stable however the charts are split. */
11
+ colorIndex: Map<number, number>;
12
+ };
13
+
14
+ /** Pumps with a mixer first, then the big pumps, each by number. */
15
+ export function comparePumps(a: PumpRecord, z: PumpRecord) {
16
+ if (!!a.BigPump !== !!z.BigPump) return a.BigPump ? 1 : -1;
17
+ return a.ObjectNo - z.ObjectNo;
18
+ }
19
+
20
+ /**
21
+ * One chart per selected plant, with the pumps based there and those booked by it, or a single
22
+ * chart for all of them. In merged mode the procedure already leaves out the indirect bookings of
23
+ * call-offs from the selected plants, so nothing is shown twice.
24
+ */
25
+ export function getChartData(result: PumpBookingsResult, selectedPlants: number[], merged: boolean): ChartData[] {
26
+ let { Table: plants, Table1: pumps, Table2: bookings, Table3: outOfService } = result;
27
+ let colorIndex = new Map(selectedPlants.map((plantId, index) => [plantId, index]));
28
+
29
+ if (plants.length === 0 || pumps.length === 0) return [];
30
+
31
+ if (merged) {
32
+ return [
33
+ {
34
+ key: "merged",
35
+ plants,
36
+ pumps: pumps.toSorted(comparePumps),
37
+ bookings,
38
+ outOfService,
39
+ merged,
40
+ colorIndex,
41
+ },
42
+ ];
43
+ }
44
+
45
+ return selectedPlants.flatMap((plantId) => {
46
+ let plant = plants.find((candidate) => candidate.PlantID === plantId);
47
+ if (!plant) return [];
48
+
49
+ let plantBookings = bookings.filter((booking) => booking.PlantID === plantId);
50
+ let bookedPumps = new Set(plantBookings.map((booking) => booking.ObjectNo));
51
+ let plantPumps = pumps.filter((pump) => pump.LocationID === plantId || bookedPumps.has(pump.ObjectNo));
52
+ if (plantPumps.length === 0) return [];
53
+
54
+ let pumpIds = new Set(plantPumps.map((pump) => pump.ObjectNo));
55
+
56
+ return [
57
+ {
58
+ key: String(plantId),
59
+ plants: [plant],
60
+ pumps: plantPumps.toSorted(comparePumps),
61
+ bookings: plantBookings,
62
+ outOfService: outOfService.filter((entry) => pumpIds.has(entry.ObjectNo)),
63
+ merged,
64
+ colorIndex,
65
+ },
66
+ ];
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Where a pump is based, when the chart should say so: always with several plants in one chart,
72
+ * otherwise only for a pump from somewhere else. `null` home means an external pump.
73
+ */
74
+ export function getPumpHome(pump: Pick<PumpRecord, "LocationID">, plants: PlantRecord[], merged: boolean) {
75
+ let isHome = plants.some((plant) => plant.PlantID === pump.LocationID);
76
+ return { show: merged || !isHome, home: pump.LocationID };
77
+ }
78
+
79
+ /** The plant to name in a booking's tooltip, or `null` when the chart's own plant goes without saying. */
80
+ export function getBookingPlant(booking: PumpBookingRecord, merged: boolean) {
81
+ if (merged) return booking.IndirectPlantID ?? booking.PlantID;
82
+ if (booking.IndirectBooking) return booking.IndirectPlantID;
83
+ return null;
84
+ }
85
+
86
+ export function getPumpFeature(pump: PumpRecord) {
87
+ let feature: { label: string; color: string } | null = null;
88
+
89
+ if (pump.BigPump) feature = { label: "S", color: "#FFE4C4" };
90
+ else if (pump.IsPump) feature = { label: "P", color: "#DDDDFF" };
91
+ else if (pump.Telescopic) feature = { label: "T", color: "#D1FFDB" };
92
+ else if (pump.ConveyorBelt) feature = { label: "B", color: "#DDDDDD" };
93
+ else if (!pump.IsTruck) feature = { label: "A", color: "#EEEEEE" };
94
+
95
+ if (feature && pump.BoomLength && pump.BoomLength > 0) {
96
+ return { ...feature, label: `${feature.label} ${pump.BoomLength}m` };
97
+ }
98
+
99
+ return feature;
100
+ }
101
+
102
+ export function getChartHeight(pumpCount: number, merged: boolean) {
103
+ return pumpCount * 26 + 45 + (merged ? 120 : 70);
104
+ }
@@ -0,0 +1,137 @@
1
+ import Highcharts from "highcharts";
2
+
3
+ import { getLocalizedString } from "../../i18n.js";
4
+ import { type PreviewData, cropCaption, getChartHeight, getStatusTimes } from "./model.js";
5
+ import { formatTime, escapeHtml } from "../format.js";
6
+
7
+ const HOUR = 3600000;
8
+
9
+ // The colours the dialog has always used: the first of the old Highcharts palette for the plan,
10
+ // red for what other call-offs already have booked.
11
+ const PLANNED_COLOR = "#7cb5ec";
12
+ const OTHER_COLOR = "#ff0000";
13
+
14
+ function fill(color: string, opacity: number) {
15
+ return Highcharts.color(color).setOpacity(opacity).get("rgba") as string;
16
+ }
17
+
18
+ function timesHtml(point: any) {
19
+ let body = `${formatTime(point.x)} - ${formatTime(point.x2)}`;
20
+ if (point.driverID) body += `<br>${getLocalizedString("Driver")}: ${escapeHtml(point.driverID)}`;
21
+
22
+ return `<div style="color:var(--ds-color-info-text-subtle)">${body}</div>`;
23
+ }
24
+
25
+ function otherHtml(point: any) {
26
+ return `<div>${getLocalizedString("Call-off")}: ${point.callOffID}</div>
27
+ <div>${escapeHtml(point.customer)}</div>
28
+ <div style="color:var(--ds-color-neutral-text-subtle)">${escapeHtml(point.buildSite)}</div>`;
29
+ }
30
+
31
+ export function getChartOptions(data: PreviewData, date: Date): Highcharts.Options {
32
+ let midnight = date.getTime();
33
+ let min = midnight - 2 * HOUR;
34
+ let max = midnight + 28 * HOUR;
35
+ let categories = data.vehicles;
36
+
37
+ let planned = data.planned.map((row) => ({
38
+ y: categories.indexOf(row.VehicleID),
39
+ x: row.StartTime.getTime(),
40
+ x2: row.EndTime.getTime(),
41
+ ...getStatusTimes(row),
42
+ color: fill(PLANNED_COLOR, 0.6),
43
+ caption: formatTime(row.StartTime),
44
+ driverID: row.DriverID,
45
+ }));
46
+
47
+ let other = data.other.map((row) => ({
48
+ y: categories.indexOf(row.VehicleID),
49
+ x: row.StartTime.getTime(),
50
+ x2: row.EndTime.getTime(),
51
+ color: fill(OTHER_COLOR, 0.35),
52
+ caption: "",
53
+ driverID: row.DriverID,
54
+ callOffID: row.CallOffID,
55
+ customer: row.CustomerAdr1,
56
+ buildSite: row.BuildSiteAdr1,
57
+ }));
58
+
59
+ let band = (from: number, to: number) => ({ color: "var(--ds-color-neutral-background-tinted)", from, to });
60
+
61
+ return {
62
+ chart: {
63
+ type: "deliveryxrange",
64
+ backgroundColor: "transparent",
65
+ zooming: { type: "x" },
66
+ height: getChartHeight(categories.length),
67
+ marginTop: 50,
68
+ marginBottom: 10,
69
+ },
70
+ accessibility: { enabled: false },
71
+ credits: { enabled: false },
72
+ title: { text: undefined },
73
+ xAxis: {
74
+ type: "datetime",
75
+ title: { text: undefined },
76
+ opposite: true,
77
+ min,
78
+ max,
79
+ dateTimeLabelFormats: { hour: "%H", day: "%d.%m" },
80
+ tickInterval: HOUR,
81
+ minorTickInterval: 0.5 * HOUR,
82
+ plotBands: [band(min - 24 * HOUR, midnight + 6 * HOUR), band(midnight + 18 * HOUR, max + 24 * HOUR)],
83
+ },
84
+ yAxis: {
85
+ categories: categories.map(String),
86
+ reversed: true,
87
+ min: 0,
88
+ // Every vehicle gets a row, also one whose loads are all outside the zoom.
89
+ max: categories.length - 1,
90
+ tickInterval: 1,
91
+ title: { text: "" },
92
+ gridLineColor: "var(--ds-color-neutral-border-subtle)",
93
+ labels: {
94
+ useHTML: true,
95
+ formatter(this: any) {
96
+ let vehicleId = Number(this.value);
97
+ return `<div style="min-width:40px"><a href="#vehicle-${vehicleId}">${vehicleId}</a></div>`;
98
+ },
99
+ },
100
+ },
101
+ tooltip: {
102
+ useHTML: true,
103
+ formatter(this: any) {
104
+ let content = this.series.name === "OtherDeliveries" ? otherHtml(this.point) : "";
105
+ return `<div style="font-size:10px">${content}${timesHtml(this.point)}</div>`;
106
+ },
107
+ },
108
+ plotOptions: {
109
+ deliveryxrange: {
110
+ animation: false,
111
+ grouping: false,
112
+ groupPadding: 0.1,
113
+ colorByPoint: false,
114
+ borderWidth: 1,
115
+ borderColor: "#888",
116
+ borderRadius: 0,
117
+ dataLabels: {
118
+ enabled: true,
119
+ useHTML: false,
120
+ color: "var(--ds-color-neutral-text-default)",
121
+ align: "left",
122
+ y: 2,
123
+ style: { fontWeight: "normal", fontSize: "10px", textOutline: "none" },
124
+ formatter(this: any) {
125
+ return cropCaption(this.point.caption ?? "", this.point.shapeArgs.width / 6 - 3);
126
+ },
127
+ },
128
+ },
129
+ series: { states: { inactive: { opacity: 1 } } },
130
+ } as Highcharts.PlotOptions,
131
+ legend: { enabled: false },
132
+ series: [
133
+ { type: "deliveryxrange", name: "Deliveries", data: planned },
134
+ { type: "deliveryxrange", name: "OtherDeliveries", data: other },
135
+ ] as unknown as Highcharts.SeriesOptionsType[],
136
+ };
137
+ }
@@ -0,0 +1,17 @@
1
+ .ObUnboundPreview {
2
+ padding-block: 0.5rem;
3
+ }
4
+
5
+ // Highcharts sets `light dark` here, which follows the OS instead of the colour scheme of the site.
6
+ .ObUnboundPreview-chart .highcharts-container {
7
+ color-scheme: inherit;
8
+ }
9
+
10
+ .ObUnboundPreview-chart a {
11
+ color: var(--ds-color-info-text-subtle);
12
+ }
13
+
14
+ .ObUnboundPreview-empty {
15
+ color: var(--ds-color-neutral-text-subtle);
16
+ padding-inline: 0.75rem;
17
+ }
@@ -0,0 +1,100 @@
1
+ import { Paragraph } from "@digdir/designsystemet-react";
2
+ import Highcharts from "highcharts";
3
+ import { useLayoutEffect, useMemo, useRef, useState } from "react";
4
+
5
+ import { getLocalizedString } from "../../i18n.js";
6
+ import { VehicleInfoDialog } from "../../vehicles/VehicleInfoDialog/index.js";
7
+ import { registerDeliveryXRange } from "../VehicleDeliveries/deliveryXRange.js";
8
+ import { getChartOptions } from "./chartOptions.js";
9
+ import { type OtherDelivery, type PlannedDelivery, getChartHeight, getPreviewData } from "./model.js";
10
+
11
+ import "./index.scss";
12
+
13
+ registerDeliveryXRange();
14
+
15
+ export type { OtherDelivery, PlannedDelivery } from "./model.js";
16
+ export { parseOtherDeliveries, parsePlannedDeliveries } from "./model.js";
17
+
18
+ export type UnboundPreviewProps = {
19
+ /** Midnight UTC of the day to show. */
20
+ date: Date;
21
+ /** The plan being edited. Nothing is drawn while this is null, before the first plan arrives. */
22
+ deliveries: PlannedDelivery[] | null;
23
+ /** Loads from other call-offs. Only those on vehicles in the plan are shown. */
24
+ otherDeliveries?: OtherDelivery[];
25
+ /** Called after the chart has drawn, when the height of the page may have changed. */
26
+ onRendered?: () => void;
27
+ };
28
+
29
+ const NO_DELIVERIES: OtherDelivery[] = [];
30
+
31
+ /**
32
+ * A preview of a delivery plan that is not saved yet: the planned loads per vehicle through the
33
+ * day, with the loads the same vehicles already have for other call-offs. The data comes from the
34
+ * caller; the chart reads nothing itself.
35
+ */
36
+ export function UnboundPreview({ date, deliveries, otherDeliveries = NO_DELIVERIES, onRendered }: UnboundPreviewProps) {
37
+ let container = useRef<HTMLDivElement>(null);
38
+ let zoom = useRef<{ min: number; max: number } | null>(null);
39
+ let [vehicleId, setVehicleId] = useState<number | null>(null);
40
+
41
+ let data = useMemo(
42
+ () => (deliveries ? getPreviewData(deliveries, otherDeliveries) : null),
43
+ [deliveries, otherDeliveries],
44
+ );
45
+ let dateKey = date.getTime();
46
+ let options = useMemo(
47
+ () => (data?.vehicles.length ? getChartOptions(data, new Date(dateKey)) : null),
48
+ [data, dateKey],
49
+ );
50
+
51
+ useLayoutEffect(() => {
52
+ if (!options) {
53
+ onRendered?.();
54
+ return;
55
+ }
56
+
57
+ let chart = new Highcharts.Chart(container.current as HTMLElement, options);
58
+
59
+ // The plan is sent again on every change in the dialog; the zoom stays.
60
+ if (zoom.current) {
61
+ chart.xAxis[0].setExtremes(zoom.current.min, zoom.current.max, true, false);
62
+ chart.showResetZoom();
63
+ }
64
+
65
+ onRendered?.();
66
+
67
+ return () => {
68
+ let { userMin, userMax } = chart.xAxis[0].getExtremes();
69
+ zoom.current = userMin !== undefined && userMax !== undefined ? { min: userMin, max: userMax } : null;
70
+ chart.destroy();
71
+ };
72
+ }, [options, onRendered]);
73
+
74
+ if (!data) return null;
75
+
76
+ return (
77
+ <div className="ObUnboundPreview">
78
+ {data.vehicles.length === 0 ? (
79
+ <Paragraph data-size="sm" className="ObUnboundPreview-empty">
80
+ {getLocalizedString("No planned loads")}
81
+ </Paragraph>
82
+ ) : (
83
+ <div
84
+ ref={container}
85
+ className="ObUnboundPreview-chart"
86
+ // Reserved up front, so the page keeps its scroll position while the chart is replaced.
87
+ style={{ minHeight: getChartHeight(data.vehicles.length) }}
88
+ onClick={(event) => {
89
+ let link = (event.target as Element).closest<HTMLAnchorElement>('a[href^="#vehicle-"]');
90
+ if (link) {
91
+ event.preventDefault();
92
+ setVehicleId(Number(link.hash.replace("#vehicle-", "")));
93
+ }
94
+ }}
95
+ />
96
+ )}
97
+ <VehicleInfoDialog vehicleId={vehicleId} date={date} onClose={() => setVehicleId(null)} />
98
+ </div>
99
+ );
100
+ }
@@ -0,0 +1,129 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import {
4
+ cropCaption,
5
+ getChartHeight,
6
+ getPreviewData,
7
+ getStatusTimes,
8
+ getVehicles,
9
+ parseOtherDeliveries,
10
+ parsePlannedDeliveries,
11
+ parseTime,
12
+ } from "./model.js";
13
+
14
+ const planned = JSON.stringify([
15
+ {
16
+ VehicleID: 254,
17
+ StartTime: "2023-11-02T08:30:00Z",
18
+ LoadTime: 10,
19
+ DriveToSiteTime: 20,
20
+ WaitTime: 5,
21
+ UnloadTime: 10,
22
+ DriveFromSiteTime: 35,
23
+ EndTime: "2023-11-02T09:50:00Z",
24
+ DriverID: "tfr",
25
+ },
26
+ {
27
+ VehicleID: 9001,
28
+ StartTime: "2023-11-02T09:00:00Z",
29
+ LoadTime: 10,
30
+ DriveToSiteTime: 20,
31
+ WaitTime: 0,
32
+ UnloadTime: 10,
33
+ DriveFromSiteTime: 35,
34
+ EndTime: "2023-11-02T10:15:00Z",
35
+ DriverID: "",
36
+ },
37
+ {
38
+ VehicleID: 254,
39
+ StartTime: "2023-11-02T10:00:00Z",
40
+ LoadTime: 10,
41
+ DriveToSiteTime: 20,
42
+ WaitTime: 0,
43
+ UnloadTime: 10,
44
+ DriveFromSiteTime: 35,
45
+ EndTime: "2023-11-02T11:15:00Z",
46
+ DriverID: "tfr",
47
+ },
48
+ ]);
49
+
50
+ const other = JSON.stringify([
51
+ {
52
+ VehicleID: 254,
53
+ StartTime: "2023-11-02T04:44:59Z",
54
+ EndTime: "2023-11-02T05:24:59Z",
55
+ DriverID: "",
56
+ CallOffID: 759279,
57
+ CustomerAdr1: "Nilsen & Sture Betong AS",
58
+ BuildSiteAdr1: "Industrihall",
59
+ },
60
+ {
61
+ VehicleID: 12,
62
+ StartTime: "2023-11-02T10:50:24Z",
63
+ EndTime: "2023-11-02T11:30:24Z",
64
+ DriverID: "abc",
65
+ CallOffID: 759889,
66
+ CustomerAdr1: "LAB Entreprenør AS",
67
+ BuildSiteAdr1: "BUS 2",
68
+ },
69
+ ]);
70
+
71
+ describe("parseTime", () => {
72
+ it("keeps the wall clock as UTC", () => {
73
+ expect(parseTime("2023-11-02T08:30:00Z").toISOString()).toBe("2023-11-02T08:30:00.000Z");
74
+ expect(parseTime("2023-11-02T08:30:00").toISOString()).toBe("2023-11-02T08:30:00.000Z");
75
+ expect(parseTime("2023-11-02T08:30:00+01:00").toISOString()).toBe("2023-11-02T07:30:00.000Z");
76
+ });
77
+ });
78
+
79
+ describe("parsePlannedDeliveries", () => {
80
+ it("reads the plan the dialog sends", () => {
81
+ let rows = parsePlannedDeliveries(planned);
82
+
83
+ expect(rows).toHaveLength(3);
84
+ expect(rows[0].StartTime.toISOString()).toBe("2023-11-02T08:30:00.000Z");
85
+ expect(rows[0].DriverID).toBe("tfr");
86
+ expect(rows[1].DriverID).toBeNull();
87
+ });
88
+
89
+ it("reads nothing from an empty value", () => {
90
+ expect(parsePlannedDeliveries("")).toEqual([]);
91
+ expect(parsePlannedDeliveries(undefined)).toEqual([]);
92
+ expect(parsePlannedDeliveries("[]")).toEqual([]);
93
+ });
94
+ });
95
+
96
+ describe("getPreviewData", () => {
97
+ it("lists each vehicle once, in plan order", () => {
98
+ expect(getVehicles(parsePlannedDeliveries(planned))).toEqual([254, 9001]);
99
+ });
100
+
101
+ it("leaves out other loads on vehicles not in the plan", () => {
102
+ let data = getPreviewData(parsePlannedDeliveries(planned), parseOtherDeliveries(other));
103
+
104
+ expect(data.other.map((row) => row.CallOffID)).toEqual([759279]);
105
+ expect(data.other[0].DriverID).toBeNull();
106
+ });
107
+ });
108
+
109
+ describe("getStatusTimes", () => {
110
+ it("adds the minutes up from the start", () => {
111
+ let [row] = parsePlannedDeliveries(planned);
112
+ let { m1, m2, m3 } = getStatusTimes(row);
113
+
114
+ expect(new Date(m1).toISOString()).toBe("2023-11-02T09:00:00.000Z");
115
+ expect(new Date(m2).toISOString()).toBe("2023-11-02T09:05:00.000Z");
116
+ expect(new Date(m3).toISOString()).toBe("2023-11-02T09:15:00.000Z");
117
+ });
118
+ });
119
+
120
+ describe("helpers", () => {
121
+ it("sizes the chart by vehicle", () => {
122
+ expect(getChartHeight(2)).toBe(125);
123
+ });
124
+
125
+ it("crops a caption to fit the bar", () => {
126
+ expect(cropCaption("09:30", 10)).toBe("09:30");
127
+ expect(cropCaption("09:30", 2)).toBe("09...");
128
+ });
129
+ });