@linzjs/step-ag-grid 14.6.0 → 14.7.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": "14.6.0",
5
+ "version": "14.7.1",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -121,6 +121,15 @@ export const Grid = ({
121
121
  needsAutoSize.current = true;
122
122
  return;
123
123
  }
124
+
125
+ const headerCellCount = gridDivRef.current?.getElementsByClassName("ag-header-cell-label")?.length;
126
+ if (headerCellCount != params.columnDefs.length) {
127
+ // Don't resize grids until all the columns are visible
128
+ // as `autoSizeColumns` will fail silently in this case
129
+ needsAutoSize.current = true;
130
+ return;
131
+ }
132
+
124
133
  const skipHeader = sizeColumns === "auto-skip-headers" && !isEmpty(params.rowData);
125
134
  if (sizeColumns === "auto" || skipHeader) {
126
135
  const result = autoSizeColumns({ skipHeader, userSizedColIds: userSizedColIds.current });
@@ -68,6 +68,13 @@ describe("TextInputValidator", () => {
68
68
  ["1.1", "Must be a whole number"],
69
69
  ],
70
70
  },
71
+ {
72
+ numberFormat: { notZero: true },
73
+ tests: [
74
+ ["1", null],
75
+ ["0", "Must not be 0"],
76
+ ],
77
+ },
71
78
  {
72
79
  required: true,
73
80
  tests: [
@@ -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 != "") {
@@ -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
- const regexp = /^-?\d*(\.\d+)?$/;
13
- return regexp.test(value);
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 {