@linzjs/step-ag-grid 8.4.0 → 8.4.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/dist/src/components/GridCell.d.ts +2 -1
- package/dist/src/components/GridCell.test.d.ts +1 -0
- package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +4 -0
- package/dist/step-ag-grid.esm.js +30 -7
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/GridCell.test.tsx +33 -0
- package/src/components/GridCell.tsx +38 -8
- package/src/components/gridRender/GridRenderGenericCell.tsx +4 -0
- package/src/stories/grid/GridPopoutBearing.stories.tsx +1 -0
- package/dist/src/setupTests.d.ts +0 -1
- package/src/setupTests.ts +0 -5
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": "8.4.
|
|
5
|
+
"version": "8.4.1",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"aggrid",
|
|
8
8
|
"ag-grid",
|
|
@@ -122,6 +122,7 @@
|
|
|
122
122
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
123
123
|
"eslint-plugin-testing-library": "^5.9.1",
|
|
124
124
|
"jest": "^29.3.1",
|
|
125
|
+
"jest-canvas-mock": "^2.4.0",
|
|
125
126
|
"jest-environment-jsdom": "^29.3.1",
|
|
126
127
|
"jest-expect-message": "^1.1.3",
|
|
127
128
|
"mkdirp": "^1.0.4",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { GridBaseRow } from "./Grid";
|
|
2
|
+
import { generateFilterGetter } from "./GridCell";
|
|
3
|
+
import { RowValueGetterParams } from "./gridRender/GridRenderGenericCell";
|
|
4
|
+
|
|
5
|
+
describe("GridCell", () => {
|
|
6
|
+
test("generateFilterGetter returns passed filterValueGetter", () => {
|
|
7
|
+
const filterValueGetter = () => "a";
|
|
8
|
+
expect(generateFilterGetter(undefined, filterValueGetter, () => "b")).toBe(filterValueGetter);
|
|
9
|
+
expect(generateFilterGetter("xxx", filterValueGetter, undefined)).toBe(filterValueGetter);
|
|
10
|
+
expect(generateFilterGetter(undefined, filterValueGetter, undefined)).toBe(filterValueGetter);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("generateFilterGetter", () => {
|
|
14
|
+
expect(generateFilterGetter("xxx", undefined, undefined)).toBeUndefined();
|
|
15
|
+
|
|
16
|
+
const tests = [
|
|
17
|
+
{ formatted: "f1", value: "v1", expected: "f1 v1" },
|
|
18
|
+
{ formatted: "f2", value: {}, expected: "f2" },
|
|
19
|
+
{ formatted: "", value: "v3", expected: "v3" },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
tests.forEach((test) => {
|
|
23
|
+
const field = "xxx";
|
|
24
|
+
const valueFormatter = test.formatted == null ? undefined : () => test.formatted;
|
|
25
|
+
const filterGetter = generateFilterGetter(field, undefined, valueFormatter);
|
|
26
|
+
expect(typeof filterGetter).toBe("function");
|
|
27
|
+
if (typeof filterGetter !== "function") return;
|
|
28
|
+
expect(filterGetter({ getValue: () => test.value } as any as RowValueGetterParams<GridBaseRow>)).toBe(
|
|
29
|
+
test.expected,
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -2,8 +2,13 @@ import { forwardRef, useContext } from "react";
|
|
|
2
2
|
import { GridBaseRow } from "./Grid";
|
|
3
3
|
import { GridUpdatingContext } from "../contexts/GridUpdatingContext";
|
|
4
4
|
import { GridCellMultiSelectClassRules } from "./GridCellMultiSelectClassRules";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
GenericCellColDef,
|
|
7
|
+
GenericCellRendererParams,
|
|
8
|
+
RowValueFormatterParams,
|
|
9
|
+
RowValueGetterParams,
|
|
10
|
+
} from "./gridRender/GridRenderGenericCell";
|
|
11
|
+
import { ColDef, ICellEditorParams, ICellRendererParams } from "ag-grid-community";
|
|
7
12
|
import { GridLoadableCell } from "./GridLoadableCell";
|
|
8
13
|
import { GridIcon } from "./GridIcon";
|
|
9
14
|
import { SuppressKeyboardEventParams, ValueFormatterParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
@@ -36,13 +41,13 @@ export const GridCellRenderer = (props: ICellRendererParams) => {
|
|
|
36
41
|
)}
|
|
37
42
|
{!!infoText && <GridIcon icon={"ic_info_outline"} title={typeof infoText === "string" ? infoText : "Info"} />}
|
|
38
43
|
<div style={{ display: "flex", flex: 1, overflow: "hidden" }}>
|
|
39
|
-
{colDef
|
|
44
|
+
{colDef.cellRendererParams?.originalCellRenderer ? (
|
|
40
45
|
<colDef.cellRendererParams.originalCellRenderer {...props} />
|
|
41
46
|
) : (
|
|
42
47
|
<span title={props.valueFormatted}>{props.valueFormatted}</span>
|
|
43
48
|
)}
|
|
44
49
|
</div>
|
|
45
|
-
{fnOrVar(
|
|
50
|
+
{fnOrVar(colDef.editable, props) && rendererParams?.rightHoverElement && (
|
|
46
51
|
<div style={{ display: "flex", alignItems: "center" }}>{rendererParams?.rightHoverElement}</div>
|
|
47
52
|
)}
|
|
48
53
|
</>
|
|
@@ -70,6 +75,28 @@ export const suppressCellKeyboardEvents = (e: SuppressKeyboardEventParams) => {
|
|
|
70
75
|
);
|
|
71
76
|
};
|
|
72
77
|
|
|
78
|
+
export const generateFilterGetter = <RowType extends GridBaseRow>(
|
|
79
|
+
field: string | undefined,
|
|
80
|
+
filterValueGetter: string | ((params: RowValueGetterParams<RowType>) => string) | undefined,
|
|
81
|
+
valueFormatter: string | ((params: RowValueFormatterParams<RowType>) => string) | undefined,
|
|
82
|
+
) => {
|
|
83
|
+
if (filterValueGetter) return filterValueGetter;
|
|
84
|
+
// aggrid will default to valueGetter
|
|
85
|
+
if (typeof valueFormatter !== "function" || !field) return undefined;
|
|
86
|
+
|
|
87
|
+
return (params: RowValueGetterParams<RowType>) => {
|
|
88
|
+
const value = params.getValue(field);
|
|
89
|
+
let formattedValue = valueFormatter({ ...params, value });
|
|
90
|
+
// Search for null values using standard dash
|
|
91
|
+
if (formattedValue === "–") formattedValue += " -";
|
|
92
|
+
// Search by raw value as well as formatted
|
|
93
|
+
const gotValue = ["string", "number"].includes(typeof value) ? value : undefined;
|
|
94
|
+
return (formattedValue + (gotValue != null && formattedValue != gotValue ? " " + gotValue : "")) //
|
|
95
|
+
.replaceAll(/\s+/g, " ")
|
|
96
|
+
.trim();
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
73
100
|
/*
|
|
74
101
|
* All cells should use this.
|
|
75
102
|
*/
|
|
@@ -81,6 +108,12 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
81
108
|
editorParams?: Props;
|
|
82
109
|
},
|
|
83
110
|
): ColDefT<RowType> => {
|
|
111
|
+
// Generate a default filter value getter which uses the formatted value plus
|
|
112
|
+
// the editable value if it's a string and different from the formatted value.
|
|
113
|
+
// This is so that e.g. bearings can be searched for by DMS or raw number.
|
|
114
|
+
const valueFormatter = props.valueFormatter;
|
|
115
|
+
const filterValueGetter = generateFilterGetter(props.field, props.filterValueGetter, valueFormatter);
|
|
116
|
+
|
|
84
117
|
return {
|
|
85
118
|
colId: props.field,
|
|
86
119
|
sortable: !!(props?.field || props?.valueGetter),
|
|
@@ -96,10 +129,7 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
96
129
|
cellEditorParams: { ...custom.editorParams, multiEdit: custom.multiEdit },
|
|
97
130
|
}),
|
|
98
131
|
// If there's a valueFormatter and no filterValueGetter then create a filterValueGetter
|
|
99
|
-
|
|
100
|
-
!props.filterValueGetter && {
|
|
101
|
-
filterValueGetter: props.valueFormatter as string | ValueGetterFunc,
|
|
102
|
-
}),
|
|
132
|
+
filterValueGetter,
|
|
103
133
|
// Default value formatter, otherwise react freaks out on objects
|
|
104
134
|
valueFormatter: (params: ValueFormatterParams) => {
|
|
105
135
|
if (params.value == null) return "–";
|
|
@@ -19,6 +19,9 @@ export interface RowEditableCallbackParams<RowType extends GridBaseRow> extends
|
|
|
19
19
|
export interface RowValueFormatterParams<RowType extends GridBaseRow> extends ValueFormatterParams {
|
|
20
20
|
data: RowType;
|
|
21
21
|
}
|
|
22
|
+
export interface RowValueGetterParams<RowType extends GridBaseRow> extends ValueGetterParams {
|
|
23
|
+
data: RowType;
|
|
24
|
+
}
|
|
22
25
|
|
|
23
26
|
export interface RowValueGetterParams<RowType extends GridBaseRow> extends ValueGetterParams {
|
|
24
27
|
data: RowType;
|
|
@@ -29,6 +32,7 @@ export interface GenericCellColDef<RowType extends GridBaseRow> extends ColDefT<
|
|
|
29
32
|
cellRendererParams?: GenericCellRendererParams<RowType>;
|
|
30
33
|
valueGetter?: string | ((params: RowValueGetterParams<RowType>) => any);
|
|
31
34
|
valueFormatter?: string | ((params: RowValueFormatterParams<RowType>) => string);
|
|
35
|
+
filterValueGetter?: string | ((params: RowValueGetterParams<RowType>) => string);
|
|
32
36
|
editable?: boolean | ((params: RowEditableCallbackParams<RowType>) => boolean);
|
|
33
37
|
}
|
|
34
38
|
|
package/dist/src/setupTests.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@testing-library/jest-dom";
|
package/src/setupTests.ts
DELETED