@mtes-mct/monitor-ui 8.8.0 → 9.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # [9.0.0](https://github.com/MTES-MCT/monitor-ui/compare/v8.8.0...v9.0.0) (2023-08-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **utils:** fix getCoordinates rounding ([622d9fc](https://github.com/MTES-MCT/monitor-ui/commit/622d9fc887b663a92a30b74bd8a64bfb56acf40d))
7
+
8
+
9
+ * feat(utils)!: add prop to getOptionsFromLabelledEnum function for sorted or not the options ([4ff53fe](https://github.com/MTES-MCT/monitor-ui/commit/4ff53fe398f3ac2d24a858f2f4c305d7880a22d0))
10
+
11
+
12
+ ### BREAKING CHANGES
13
+
14
+ * - add mustSort prop with default value to false for sorted or not the options
15
+
16
+ # [8.8.0](https://github.com/MTES-MCT/monitor-ui/compare/v8.7.0...v8.8.0) (2023-08-22)
17
+
18
+
19
+ ### Features
20
+
21
+ * **utils:** add pluralize() ([57663f7](https://github.com/MTES-MCT/monitor-ui/commit/57663f78110e0ea66771a74699c712eb757431d1))
22
+ * **utils:** expose cleanString() & normalizeString() ([41a6a6f](https://github.com/MTES-MCT/monitor-ui/commit/41a6a6f936e403aa66bf999664f0e5ad1f7c63fd))
23
+
1
24
  # [8.7.0](https://github.com/MTES-MCT/monitor-ui/compare/v8.6.1...v8.7.0) (2023-08-22)
2
25
 
3
26
 
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![License][img-license]][lnk-license] [![CI Status][img-github]][lnk-github] [![NPM Version][img-npm]][lnk-npm]
4
4
 
5
- > Common React components, hooks, utilities and CSS stylesheets for [Monitorfish][lnk-github-monitorfish] and
6
- > [Monitorenv][lnk-github-monitorenv].
5
+ > Common React components, hooks, utilities and CSS stylesheets for [MonitorFish][lnk-github-monitorfish],
6
+ > [MonitorEnv][lnk-github-monitorenv] and [RapportNav][lnk-github-rapportnav].
7
7
 
8
8
  ## Usage
9
9
 
@@ -63,6 +63,7 @@ Please read the [contributing document](CONTRIBUTING.md) for setup and contribut
63
63
  [lnk-github]: https://github.com/MTES-MCT/monitor-ui/actions?query=branch%3Amain++
64
64
  [lnk-github-monitorenv]: https://github.com/MTES-MCT/monitorenv
65
65
  [lnk-github-monitorfish]: https://github.com/MTES-MCT/monitorfish
66
+ [lnk-github-rapportnav]: https://github.com/MTES-MCT/rapportnav2
66
67
  [lnk-license]: https://github.com/MTES-MCT/monitor-ui/blob/main/LICENSE
67
68
  [lnk-npm]: https://www.npmjs.com/package/@mtes-mct/monitor-ui
68
69
  [lnk-storybook]: https://mtes-mct.github.io/monitor-ui/
package/index.js CHANGED
@@ -2350,7 +2350,9 @@ function Item({ accent, Icon, ...originalProps }) {
2350
2350
  const SecondaryDropdownItem = styled(Dropdown$1.Item) `
2351
2351
  background-color: ${p => p.theme.color.cultured};
2352
2352
  border: 1px solid ${p => p.theme.color.lightGray};
2353
- padding: 5px 7px;
2353
+ padding: 4px;
2354
+ width: 30px;
2355
+ height: 30px;
2354
2356
  :hover {
2355
2357
  background-color: ${p => p.theme.color.cultured};
2356
2358
  border: 1px solid ${p => p.theme.color.lightGray};
@@ -35985,28 +35987,44 @@ function getDMSCoordinates(transformedCoordinates) {
35985
35987
  }
35986
35988
  function getDMDFromDecimal(dd, latitudeOrLongitude) {
35987
35989
  const hemisphere = getHemisphere(dd, latitudeOrLongitude);
35988
- const absDD = Math.abs(dd);
35989
- const degrees = truncate(absDD);
35990
- const minutes = truncate((absDD - degrees) * 60);
35991
- let decimal = (absDD - degrees) * 60;
35992
- decimal -= Math.floor(decimal);
35993
- decimal = Math.round(decimal * 1000);
35990
+ // Get the decimal degrees as an absolute value
35991
+ const absoluteDecimalDegrees = Math.abs(dd);
35992
+ const degrees = truncate(absoluteDecimalDegrees);
35993
+ const [minutesInteger, minuteDecimals] = getMinutes(absoluteDecimalDegrees, degrees);
35994
35994
  const formattedDegrees = getPaddedDegrees(degrees, latitudeOrLongitude);
35995
- const formattedMinutes = minutes.toString().padStart(2, '0');
35996
- const formattedDecimal = decimal.toString().padStart(3, '0').substring(0, 3);
35995
+ const formattedMinutes = minutesInteger.padStart(2, '0');
35996
+ const formattedDecimal = minuteDecimals.padStart(3, '0').substring(0, 3);
35997
35997
  return `${formattedDegrees}° ${formattedMinutes}.${formattedDecimal}′ ${hemisphere}`;
35998
35998
  }
35999
35999
  function getDMSFromDecimal(dd, latitudeOrLongitude) {
36000
36000
  const hemisphere = getHemisphere(dd, latitudeOrLongitude);
36001
- const absDD = Math.abs(dd);
36002
- const degrees = truncate(absDD);
36003
- const minutes = truncate((absDD - degrees) * 60);
36004
- const seconds = (Math.round((((absDD - degrees) * 60 - minutes) * 60 + Number.EPSILON) * 100) / 100).toFixed(0);
36001
+ // Get the decimal degrees as an absolute value
36002
+ const absoluteDecimalDegrees = Math.abs(dd);
36003
+ const degrees = truncate(absoluteDecimalDegrees);
36004
+ const [minutesInteger, minutesDecimal] = getMinutes(absoluteDecimalDegrees, degrees);
36005
+ // Get the seconds by multiplying the decimal part by 60
36006
+ const seconds = (Number(minutesDecimal) * 1e-3 * 60).toFixed(0);
36005
36007
  const formattedDegrees = getPaddedDegrees(degrees, latitudeOrLongitude);
36006
- const formattedMinutes = minutes.toString().padStart(2, '0');
36008
+ const formattedMinutes = minutesInteger.padStart(2, '0');
36007
36009
  const formattedSeconds = seconds.toString().padStart(2, '0');
36008
36010
  return `${formattedDegrees}° ${formattedMinutes}′ ${formattedSeconds}″${hemisphere ? ` ${hemisphere}` : ''}`;
36009
36011
  }
36012
+ /**
36013
+ * Get the minutes
36014
+ * @return - the minutes as an array of [minutesInteger, minuteDecimals]
36015
+ */
36016
+ const getMinutes = (absoluteDecimalDegrees, degrees) => {
36017
+ // Get the minutes by multiplying the decimal part by 60
36018
+ let minutes = Number((absoluteDecimalDegrees - degrees) * 60).toFixed(3);
36019
+ if (minutes.split('.').length < 1) {
36020
+ minutes += '.000';
36021
+ }
36022
+ const [minutesInteger, minuteDecimals] = minutes.split('.');
36023
+ if (!minutesInteger || !minuteDecimals) {
36024
+ throw new Error('`minutesInteger` or `minuteDecimals` are undefined.');
36025
+ }
36026
+ return [minutesInteger, minuteDecimals];
36027
+ };
36010
36028
  const getHemisphere = (dd, latitudeOrLongitude) => {
36011
36029
  if (dd === 0) {
36012
36030
  return '';
@@ -36034,6 +36052,12 @@ const getPaddedDegrees = (degrees, latitudeOrLongitude) => {
36034
36052
  return '';
36035
36053
  }
36036
36054
  };
36055
+ /**
36056
+ * If n > 0
36057
+ * - Get the largest integer less than or equal to n
36058
+ * - Else, rounds n to the next largest integer.
36059
+ * @param n - number
36060
+ */
36037
36061
  function truncate(n) {
36038
36062
  return n > 0 ? Math.floor(n) : Math.ceil(n);
36039
36063
  }
@@ -36637,11 +36661,15 @@ function getOptionsFromIdAndName(collection) {
36637
36661
  }));
36638
36662
  }
36639
36663
 
36640
- function getOptionsFromLabelledEnum(labelledEnum) {
36641
- return fp.sortBy(['label'], Object.entries(labelledEnum).map(([value, label]) => ({
36664
+ function getOptionsFromLabelledEnum(labelledEnum, mustSort = false) {
36665
+ const formattedOptions = Object.entries(labelledEnum).map(([value, label]) => ({
36642
36666
  label,
36643
36667
  value
36644
- })));
36668
+ }));
36669
+ if (mustSort) {
36670
+ return fp.sortBy(['label'], formattedOptions);
36671
+ }
36672
+ return formattedOptions;
36645
36673
  }
36646
36674
 
36647
36675
  function isArray(value) {