@geops/rvf-mobility-web-component 0.1.78 → 0.1.80

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@geops/rvf-mobility-web-component",
3
3
  "license": "UNLICENSED",
4
4
  "description": "Web components for rvf in the domains of mobility and logistics.",
5
- "version": "0.1.78",
5
+ "version": "0.1.80",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -12,7 +12,7 @@
12
12
  "jspdf": "^3.0.3",
13
13
  "lodash.debounce": "^4.0.8",
14
14
  "maplibre-gl": "^5.10.0",
15
- "mobility-toolbox-js": "3.4.6",
15
+ "mobility-toolbox-js": "3.4.7",
16
16
  "ol": "^10.6.1",
17
17
  "preact": "^10.27.2",
18
18
  "preact-custom-element": "^4.5.1",
@@ -1,4 +1,5 @@
1
1
  import { MocoAPI } from "mobility-toolbox-js/ol";
2
+ import { SeverityEnumeration } from "mobility-toolbox-js/types";
2
3
  import { memo, useEffect, useState } from "preact/compat";
3
4
 
4
5
  import SituationDetails from "../SituationDetails";
@@ -19,6 +20,17 @@ export type MobilityNotificationsProps = Record<
19
20
  null | string | undefined
20
21
  >;
21
22
 
23
+ const severityOrder = {
24
+ [SeverityEnumeration.NoImpact]: 2,
25
+ [SeverityEnumeration.Normal]: 5,
26
+ [SeverityEnumeration.Severe]: 6,
27
+ [SeverityEnumeration.Slight]: 4,
28
+ [SeverityEnumeration.Undefined]: 1,
29
+ [SeverityEnumeration.Unknown]: 0,
30
+ [SeverityEnumeration.VerySevere]: 7,
31
+ [SeverityEnumeration.VerySlight]: 3,
32
+ };
33
+
22
34
  function MobilityNotifications({
23
35
  apikey,
24
36
  lang,
@@ -59,20 +71,53 @@ function MobilityNotifications({
59
71
  <I18nContext.Provider value={i18n}>
60
72
  <style>{tailwind}</style>
61
73
  <div className="flex w-full flex-col gap-6">
62
- {situations?.map((situation) => {
63
- return (
64
- <SituationDetails
65
- canToggle={true}
66
- headerClassName="text-rvf-h3 font-semibold"
67
- iconClassName="w-8 h-8 text-red"
68
- key={situation.id}
69
- reasonClassName="hidden"
70
- situation={situation}
71
- timeIntervalClassName="pl-1 text-base py-3 font-semibold text-balance"
72
- useShortMonth={false}
73
- ></SituationDetails>
74
- );
75
- })}
74
+ {situations
75
+ ?.sort((a, b) => {
76
+ // sort by startDate
77
+ const startDateA = a.affectedTimeIntervalsStart;
78
+ const startDateB = b.affectedTimeIntervalsStart;
79
+ if (startDateA && startDateB) {
80
+ // If they start the same day we sort by severity
81
+ if (startDateA.split("T")[0] === startDateB.split("T")[0]) {
82
+ // Sort by severity;
83
+ const severityA =
84
+ a.publications.find((pub) => {
85
+ return !!pub.severity;
86
+ })?.severity || 0;
87
+ const severityB =
88
+ b.publications.find((pub) => {
89
+ return !!pub.severity;
90
+ })?.severity || 0;
91
+ return severityOrder[severityA] > severityOrder[severityB]
92
+ ? -1
93
+ : 1;
94
+ }
95
+ return startDateA < startDateB ? -1 : 1;
96
+ }
97
+
98
+ if (!startDateA) {
99
+ return 1;
100
+ }
101
+
102
+ if (!startDateB) {
103
+ return -1;
104
+ }
105
+ })
106
+ .map((situation) => {
107
+ console.log("Rendering situation", situation.id, situation.title);
108
+ return (
109
+ <SituationDetails
110
+ canToggle={true}
111
+ headerClassName="text-rvf-h3 font-semibold"
112
+ iconClassName="w-8 h-8 text-red"
113
+ key={situation.id}
114
+ reasonClassName="hidden"
115
+ situation={situation}
116
+ timeIntervalClassName="pl-1 text-base py-3 font-semibold text-balance"
117
+ useShortMonth={false}
118
+ ></SituationDetails>
119
+ );
120
+ })}
76
121
  </div>
77
122
  </I18nContext.Provider>
78
123
  );