@linzjs/step-ag-grid 14.5.1 → 14.7.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.
- package/dist/src/utils/bearing.d.ts +13 -1
- package/dist/src/utils/textValidator.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +38 -16
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx +1 -1
- package/src/utils/bearing.test.ts +24 -19
- package/src/utils/bearing.ts +18 -10
- package/src/utils/textValidator.test.ts +7 -0
- package/src/utils/textValidator.ts +8 -4
- package/src/utils/util.test.ts +12 -1
- package/src/utils/util.ts +11 -2
package/package.json
CHANGED
package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx
CHANGED
|
@@ -54,7 +54,7 @@ GridFormEditBearingCorrectionInteractions_.play = async ({ canvasElement }) => {
|
|
|
54
54
|
// Test formatting a bearing
|
|
55
55
|
expect(inputField).toBeInTheDocument();
|
|
56
56
|
userEvent.type(inputField, "1.2345");
|
|
57
|
-
expect(await canvas.findByText("+1° 23' 45
|
|
57
|
+
expect(await canvas.findByText("+1° 23' 45\"")).toBeInTheDocument();
|
|
58
58
|
|
|
59
59
|
// Test enter to save
|
|
60
60
|
updateValue.mockClear();
|
|
@@ -7,30 +7,35 @@ import {
|
|
|
7
7
|
|
|
8
8
|
describe("bearing", () => {
|
|
9
9
|
test("convertDDToDMS converts decimal-ish degrees to DMS", () => {
|
|
10
|
-
expect(convertDDToDMS(-0.001, false
|
|
11
|
-
expect(convertDDToDMS(-10.001, false
|
|
12
|
-
expect(convertDDToDMS(-370.001, false
|
|
13
|
-
expect(convertDDToDMS(359.595999, false,
|
|
14
|
-
expect(convertDDToDMS(
|
|
15
|
-
expect(convertDDToDMS(
|
|
16
|
-
expect(convertDDToDMS(
|
|
17
|
-
expect(convertDDToDMS(
|
|
18
|
-
expect(convertDDToDMS(
|
|
19
|
-
expect(convertDDToDMS(5
|
|
20
|
-
expect(convertDDToDMS(5
|
|
10
|
+
expect(convertDDToDMS(-0.001, false)).toBe("-0° 00' 10\"");
|
|
11
|
+
expect(convertDDToDMS(-10.001, false)).toBe("-10° 00' 10\"");
|
|
12
|
+
expect(convertDDToDMS(-370.001, false)).toBe("-10° 00' 10\"");
|
|
13
|
+
expect(convertDDToDMS(359.595999, false, 2)).toBe("0° 00'");
|
|
14
|
+
expect(convertDDToDMS(359.595999, false, 4)).toBe("0° 00' 00\"");
|
|
15
|
+
expect(convertDDToDMS(359.595999, false, 5)).toBe("0° 00' 00.0\"");
|
|
16
|
+
expect(convertDDToDMS(369.696999, false)).toBe("10° 10' 10\"");
|
|
17
|
+
expect(convertDDToDMS(369.696999, false, 4)).toBe("10° 10' 10\"");
|
|
18
|
+
expect(convertDDToDMS(221.555999, false, 2)).toBe("221° 56'");
|
|
19
|
+
expect(convertDDToDMS(221.555999, false, 5)).toBe("221° 56' 00.0\"");
|
|
20
|
+
expect(convertDDToDMS(5, true, 5)).toBe("+5° 00' 00.0\"");
|
|
21
|
+
expect(convertDDToDMS(5.0, true, 5)).toBe("+5° 00' 00.0\"");
|
|
22
|
+
expect(convertDDToDMS(5.00001, true, 5)).toBe("+5° 00' 00.1\"");
|
|
23
|
+
expect(convertDDToDMS(5.1, true, 5)).toBe("+5° 10' 00.0\"");
|
|
21
24
|
expect(convertDDToDMS(5.12345)).toBe("+5° 12' 34.5\"");
|
|
22
25
|
expect(convertDDToDMS(5.12345, false)).toBe("5° 12' 34.5\"");
|
|
23
|
-
|
|
24
|
-
expect(convertDDToDMS(300)).toBe("+300° 00' 00.0\"");
|
|
25
|
-
expect(convertDDToDMS(300.0)).toBe("+300° 00' 00.0\"");
|
|
26
|
+
expect(convertDDToDMS(5.12345, false, 2)).toBe("5° 12' 34.5\"");
|
|
27
|
+
expect(convertDDToDMS(300, true, 5)).toBe("+300° 00' 00.0\"");
|
|
28
|
+
expect(convertDDToDMS(300.0, true, 5)).toBe("+300° 00' 00.0\"");
|
|
26
29
|
expect(convertDDToDMS(300.00001)).toBe("+300° 00' 00.1\"");
|
|
27
|
-
expect(convertDDToDMS(300.1)).toBe("+300° 10' 00.0\"");
|
|
30
|
+
expect(convertDDToDMS(300.1, true, 5)).toBe("+300° 10' 00.0\"");
|
|
28
31
|
expect(convertDDToDMS(300.12345)).toBe("+300° 12' 34.5\"");
|
|
29
32
|
expect(convertDDToDMS(300.12345, false)).toBe("300° 12' 34.5\"");
|
|
30
|
-
|
|
31
|
-
expect(convertDDToDMS(300, false,
|
|
32
|
-
expect(convertDDToDMS(
|
|
33
|
-
expect(convertDDToDMS(0, false)).toBe("0° 00'");
|
|
33
|
+
expect(convertDDToDMS(300, false, 2)).toBe("300° 00'");
|
|
34
|
+
expect(convertDDToDMS(300.1, false, 2)).toBe("300° 10'");
|
|
35
|
+
expect(convertDDToDMS(0, false, 2)).toBe("0° 00'");
|
|
36
|
+
expect(convertDDToDMS(0.0, false)).toBe("0° 00'");
|
|
37
|
+
expect(convertDDToDMS(0.0, false, 4)).toBe("0° 00' 00\"");
|
|
38
|
+
expect(convertDDToDMS(0.0, false, 5)).toBe("0° 00' 00.0\"");
|
|
34
39
|
});
|
|
35
40
|
|
|
36
41
|
test("bearingStringValidator", () => {
|
package/src/utils/bearing.ts
CHANGED
|
@@ -3,7 +3,7 @@ export const bearingValueFormatter = (value: any): string => {
|
|
|
3
3
|
if (safeValue == null) {
|
|
4
4
|
return "–";
|
|
5
5
|
}
|
|
6
|
-
return convertDDToDMS(safeValue, false
|
|
6
|
+
return convertDDToDMS(safeValue, false);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export const bearingCorrectionValueFormatter = (value: any): string => {
|
|
@@ -12,9 +12,9 @@ export const bearingCorrectionValueFormatter = (value: any): string => {
|
|
|
12
12
|
return "–";
|
|
13
13
|
}
|
|
14
14
|
if (typeof safeValue === "string") {
|
|
15
|
-
return convertDDToDMS(bearingNumberParser(safeValue), true,
|
|
15
|
+
return convertDDToDMS(bearingNumberParser(safeValue), true, 4);
|
|
16
16
|
}
|
|
17
|
-
return convertDDToDMS(safeValue, true,
|
|
17
|
+
return convertDDToDMS(safeValue, true, 4);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export const bearingNumberParser = (value: string): number | null => {
|
|
@@ -40,12 +40,21 @@ export const bearingStringValidator = (
|
|
|
40
40
|
return customInvalid ? customInvalid(bearing) : null;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
*Decimal-ish degrees to Degrees Minutes Seconds converter
|
|
45
|
+
*
|
|
46
|
+
* @param dd Decimal-ish degrees
|
|
47
|
+
* @param showPositiveSymbol whether the + sign appears before the number
|
|
48
|
+
* @param trailingZeroDp 2 | 4 | 5
|
|
49
|
+
* Example:
|
|
50
|
+
* 2 = 300° 00'
|
|
51
|
+
* 4 = 300° 00' 00"
|
|
52
|
+
* 5 = 300° 00' 00.0"
|
|
53
|
+
* @returns Degrees Minutes Seconds
|
|
54
|
+
*/
|
|
55
|
+
export const convertDDToDMS = (dd: number | null, showPositiveSymbol = true, trailingZeroDp: 2 | 4 | 5 = 2): string => {
|
|
45
56
|
if (dd == null) return "–";
|
|
46
57
|
|
|
47
|
-
if (dd === 0) addTrailingZeros = false;
|
|
48
|
-
|
|
49
58
|
// toFixed rounds parts up greater than 60, which has to be corrected below
|
|
50
59
|
const [bearingWholeString, bearingDecimalString] = dd.toFixed(5).split(".");
|
|
51
60
|
|
|
@@ -71,14 +80,13 @@ export const convertDDToDMS = (dd: number | null, showPositiveSymbol = true, add
|
|
|
71
80
|
const deciSecString = bearingDecimalString?.substring(4, 5);
|
|
72
81
|
|
|
73
82
|
let dmsString = `${showPositiveSymbol && dd > 0 ? "+" : ""}${dd < 0 ? "-" : ""}${bearingWhole}°`;
|
|
74
|
-
if (
|
|
83
|
+
if (trailingZeroDp === 5 || deciSecString != "0") {
|
|
75
84
|
dmsString += `\xa0${minString}'\xa0${secString}.${deciSecString}"`; // "\xa0" is here for non-breaking space
|
|
76
|
-
} else if (secNumeric != 0) {
|
|
85
|
+
} else if (trailingZeroDp === 4 || secNumeric != 0) {
|
|
77
86
|
dmsString += `\xa0${minString}'\xa0${secString}"`;
|
|
78
87
|
} else {
|
|
79
88
|
dmsString += `\xa0${minString}'`;
|
|
80
89
|
}
|
|
81
|
-
|
|
82
90
|
return dmsString;
|
|
83
91
|
};
|
|
84
92
|
|
|
@@ -13,6 +13,7 @@ export interface TextInputValidatorProps<RowType extends GridBaseRow> {
|
|
|
13
13
|
geMin?: number;
|
|
14
14
|
ltMax?: number;
|
|
15
15
|
leMax?: number;
|
|
16
|
+
notZero?: boolean;
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -44,17 +45,20 @@ export const TextInputValidator = <RowType extends GridBaseRow>(
|
|
|
44
45
|
}
|
|
45
46
|
if (value != "") {
|
|
46
47
|
const number = parseFloat(value);
|
|
48
|
+
if (nf.notZero && number === 0) {
|
|
49
|
+
return `Must not be 0`;
|
|
50
|
+
}
|
|
47
51
|
if (nf.gtMin != null && number <= nf.gtMin) {
|
|
48
|
-
return `Must be greater than ${nf.gtMin}`;
|
|
52
|
+
return `Must be greater than ${nf.gtMin.toLocaleString()}`;
|
|
49
53
|
}
|
|
50
54
|
if (nf.geMin != null && number < nf.geMin) {
|
|
51
|
-
return `Must not be less than ${nf.geMin}`;
|
|
55
|
+
return `Must not be less than ${nf.geMin.toLocaleString()}`;
|
|
52
56
|
}
|
|
53
57
|
if (nf.ltMax != null && number >= nf.ltMax) {
|
|
54
|
-
return `Must be less than ${nf.ltMax}`;
|
|
58
|
+
return `Must be less than ${nf.ltMax.toLocaleString()}`;
|
|
55
59
|
}
|
|
56
60
|
if (nf.leMax != null && number > nf.leMax) {
|
|
57
|
-
return `Must not be greater than ${nf.leMax}`;
|
|
61
|
+
return `Must not be greater than ${nf.leMax.toLocaleString()}`;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
if (nf.precision != null && value != "") {
|
package/src/utils/util.test.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { sanitiseFileName } from "./util";
|
|
1
|
+
import { isFloat, sanitiseFileName } from "./util";
|
|
2
2
|
|
|
3
3
|
describe("sanitiseFileName", () => {
|
|
4
|
+
test("isFloat", () => {
|
|
5
|
+
expect(isFloat("")).toBe(false);
|
|
6
|
+
expect(isFloat("x")).toBe(false);
|
|
7
|
+
expect(isFloat("1e10")).toBe(false);
|
|
8
|
+
expect(isFloat("1x")).toBe(false);
|
|
9
|
+
expect(isFloat("1.x")).toBe(false);
|
|
10
|
+
expect(isFloat("x.1")).toBe(false);
|
|
11
|
+
expect(isFloat("1")).toBe(true);
|
|
12
|
+
expect(isFloat("1.")).toBe(true);
|
|
13
|
+
expect(isFloat(".1")).toBe(true);
|
|
14
|
+
});
|
|
4
15
|
test("sanitiseFileName", () => {
|
|
5
16
|
expect(sanitiseFileName(" LT 1235/543 &%//*$ ")).toBe("LT_1235-543_&%-$");
|
|
6
17
|
expect(sanitiseFileName(" @filename here!!! ")).toBe("@filename_here!!!");
|
package/src/utils/util.ts
CHANGED
|
@@ -8,9 +8,18 @@ export const wait = (timeoutMs: number) =>
|
|
|
8
8
|
setTimeout(resolve, timeoutMs);
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
// This regexp only works if you parseFloat first, it won't validate a float on its own
|
|
12
|
+
// It prevents scientific 1e10, or trailing decimal 1.2.3, or trailing garbage 1.2xyz
|
|
13
|
+
const isFloatRegExp = /^-?\d*\.?\d*$/;
|
|
11
14
|
export const isFloat = (value: string) => {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
try {
|
|
16
|
+
// Just checking it's not scientific notation or "NaN" here.
|
|
17
|
+
// Also parse float will parse up to the first invalid character,
|
|
18
|
+
// so we need to check there's no remaining invalids e.g. "1.2xyz" would parse as 1.2
|
|
19
|
+
return !Number.isNaN(parseFloat(value)) && isFloatRegExp.test(value);
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
14
23
|
};
|
|
15
24
|
|
|
16
25
|
export const findParentWithClass = function (className: string, child: Node): HTMLElement | null {
|