@linzjs/step-ag-grid 7.7.0 → 7.8.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "7.7.0",
5
+ "version": "7.8.1",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -88,6 +88,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
88
88
  { id: 1001, bearing: "0E-12", bearingCorrection: 240 },
89
89
  { id: 1002, bearing: null, bearingCorrection: 355.1 },
90
90
  { id: 1003, bearing: null, bearingCorrection: 0 },
91
+ { id: 1004, bearing: 5.0, bearingCorrection: 50.0 },
91
92
  ] as ITestRow[]);
92
93
 
93
94
  return (
@@ -16,7 +16,7 @@ export const bearingCorrectionValueFormatter = (params: ValueFormatterParams): s
16
16
  if (typeof value === "string") {
17
17
  return convertDDToDMS(bearingNumberParser(value), true, true);
18
18
  }
19
- return convertDDToDMS(value, true, true);
19
+ return convertDDToDMS(value, true, false);
20
20
  };
21
21
 
22
22
  export const bearingNumberParser = (value: string): number | null => {
@@ -41,16 +41,28 @@ describe("TextInputValidator", () => {
41
41
  ],
42
42
  },
43
43
  {
44
- numberFormat: { precision: 2 },
44
+ numberFormat: { precision: 3 },
45
45
  tests: [
46
46
  ["x", "Must be a valid number"],
47
47
  ["", null],
48
48
  ["1.22", null],
49
+ ["0.122", null],
50
+ ["1.123", "Must have no more than 3 digits precision"],
51
+ ["0.1234", "Must have no more than 3 digits precision"],
52
+ ],
53
+ },
54
+ {
55
+ numberFormat: { scale: 2 },
56
+ tests: [
57
+ ["x", "Must be a valid number"],
58
+ ["", null],
59
+ ["1.22", null],
60
+ ["0.122", "Must have no more than 2 decimal places"],
49
61
  ["1.123", "Must have no more than 2 decimal places"],
50
62
  ],
51
63
  },
52
64
  {
53
- numberFormat: { precision: 0 },
65
+ numberFormat: { scale: 0 },
54
66
  tests: [
55
67
  ["1", null],
56
68
  ["1.1", "Must be a whole number"],
@@ -8,6 +8,7 @@ export interface TextInputValidatorProps<RowType extends GridBaseRow> {
8
8
  invalid?: (value: string, data: RowType, context: any) => JSX.Element | string | null;
9
9
  numberFormat?: {
10
10
  precision?: number;
11
+ scale?: number;
11
12
  gtMin?: number;
12
13
  geMin?: number;
13
14
  ltMax?: number;
@@ -41,22 +42,31 @@ export const TextInputValidator = <RowType extends GridBaseRow>(
41
42
  if (value != "" && !isFloat(value)) {
42
43
  return `Must be a valid number`;
43
44
  }
44
- const number = parseFloat(value);
45
- if (nf.gtMin != null && number <= nf.gtMin) {
46
- return `Must be greater than ${nf.gtMin}`;
47
- }
48
- if (nf.geMin != null && number < nf.geMin) {
49
- return `Must not be less than ${nf.geMin}`;
50
- }
51
- if (nf.ltMax != null && number >= nf.ltMax) {
52
- return `Must be less than ${nf.ltMax}`;
53
- }
54
- if (nf.leMax != null && number > nf.leMax) {
55
- return `Must not be greater than ${nf.leMax}`;
56
- }
57
- if (nf.precision != null && value != "") {
58
- if (parseFloat(number.toPrecision(nf.precision + 1)) != number) {
59
- return nf.precision == 0 ? `Must be a whole number` : `Must have no more than ${nf.precision} decimal places`;
45
+ if (value != "") {
46
+ const number = parseFloat(value);
47
+ if (nf.gtMin != null && number <= nf.gtMin) {
48
+ return `Must be greater than ${nf.gtMin}`;
49
+ }
50
+ if (nf.geMin != null && number < nf.geMin) {
51
+ return `Must not be less than ${nf.geMin}`;
52
+ }
53
+ if (nf.ltMax != null && number >= nf.ltMax) {
54
+ return `Must be less than ${nf.ltMax}`;
55
+ }
56
+ if (nf.leMax != null && number > nf.leMax) {
57
+ return `Must not be greater than ${nf.leMax}`;
58
+ }
59
+
60
+ if (nf.precision != null && value != "") {
61
+ if (parseFloat(number.toPrecision(nf.precision)) != number) {
62
+ return `Must have no more than ${nf.precision} digits precision`;
63
+ }
64
+ }
65
+
66
+ if (nf.scale != null && value != "") {
67
+ if (parseFloat(number.toFixed(nf.scale)) != number) {
68
+ return nf.scale == 0 ? `Must be a whole number` : `Must have no more than ${nf.scale} decimal places`;
69
+ }
60
70
  }
61
71
  }
62
72
  }