@linzjs/step-ag-grid 8.3.2 → 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 +6 -2
- package/dist/step-ag-grid.esm.js +34 -4
- 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 +46 -7
- package/src/components/gridForm/GridFormDropDown.tsx +1 -1
- package/src/components/gridRender/GridRenderGenericCell.tsx +6 -2
- 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.
|
|
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,7 +2,12 @@ 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 {
|
|
5
|
+
import {
|
|
6
|
+
GenericCellColDef,
|
|
7
|
+
GenericCellRendererParams,
|
|
8
|
+
RowValueFormatterParams,
|
|
9
|
+
RowValueGetterParams,
|
|
10
|
+
} from "./gridRender/GridRenderGenericCell";
|
|
6
11
|
import { ColDef, ICellEditorParams, ICellRendererParams } from "ag-grid-community";
|
|
7
12
|
import { GridLoadableCell } from "./GridLoadableCell";
|
|
8
13
|
import { GridIcon } from "./GridIcon";
|
|
@@ -22,23 +27,27 @@ export const GridCellRenderer = (props: ICellRendererParams) => {
|
|
|
22
27
|
|
|
23
28
|
const rendererParams = colDef.cellRendererParams as GenericCellRendererParams<any> | undefined;
|
|
24
29
|
const warningFn = rendererParams?.warning;
|
|
25
|
-
|
|
30
|
+
let warningText = warningFn ? warningFn(props) : undefined;
|
|
26
31
|
const infoFn = rendererParams?.info;
|
|
27
|
-
|
|
32
|
+
let infoText = infoFn ? infoFn(props) : undefined;
|
|
33
|
+
if (Array.isArray(warningText)) warningText = warningText.join("\n");
|
|
34
|
+
if (Array.isArray(infoText)) infoText = infoText.join("\n");
|
|
28
35
|
|
|
29
36
|
return (
|
|
30
37
|
<GridLoadableCell isLoading={checkUpdating(colDef.field ?? colDef.colId ?? "", props.data.id)}>
|
|
31
38
|
<>
|
|
32
|
-
{
|
|
33
|
-
|
|
39
|
+
{!!warningText && (
|
|
40
|
+
<GridIcon icon={"ic_warning_outline"} title={typeof warningText === "string" ? warningText : "Warning"} />
|
|
41
|
+
)}
|
|
42
|
+
{!!infoText && <GridIcon icon={"ic_info_outline"} title={typeof infoText === "string" ? infoText : "Info"} />}
|
|
34
43
|
<div style={{ display: "flex", flex: 1, overflow: "hidden" }}>
|
|
35
|
-
{colDef
|
|
44
|
+
{colDef.cellRendererParams?.originalCellRenderer ? (
|
|
36
45
|
<colDef.cellRendererParams.originalCellRenderer {...props} />
|
|
37
46
|
) : (
|
|
38
47
|
<span title={props.valueFormatted}>{props.valueFormatted}</span>
|
|
39
48
|
)}
|
|
40
49
|
</div>
|
|
41
|
-
{fnOrVar(
|
|
50
|
+
{fnOrVar(colDef.editable, props) && rendererParams?.rightHoverElement && (
|
|
42
51
|
<div style={{ display: "flex", alignItems: "center" }}>{rendererParams?.rightHoverElement}</div>
|
|
43
52
|
)}
|
|
44
53
|
</>
|
|
@@ -66,6 +75,28 @@ export const suppressCellKeyboardEvents = (e: SuppressKeyboardEventParams) => {
|
|
|
66
75
|
);
|
|
67
76
|
};
|
|
68
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
|
+
|
|
69
100
|
/*
|
|
70
101
|
* All cells should use this.
|
|
71
102
|
*/
|
|
@@ -77,6 +108,12 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
77
108
|
editorParams?: Props;
|
|
78
109
|
},
|
|
79
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
|
+
|
|
80
117
|
return {
|
|
81
118
|
colId: props.field,
|
|
82
119
|
sortable: !!(props?.field || props?.valueGetter),
|
|
@@ -91,6 +128,8 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
91
128
|
...(custom?.editorParams && {
|
|
92
129
|
cellEditorParams: { ...custom.editorParams, multiEdit: custom.multiEdit },
|
|
93
130
|
}),
|
|
131
|
+
// If there's a valueFormatter and no filterValueGetter then create a filterValueGetter
|
|
132
|
+
filterValueGetter,
|
|
94
133
|
// Default value formatter, otherwise react freaks out on objects
|
|
95
134
|
valueFormatter: (params: ValueFormatterParams) => {
|
|
96
135
|
if (params.value == null) return "–";
|
|
@@ -300,7 +300,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
|
|
|
300
300
|
setValue: (value: any) => {
|
|
301
301
|
setSubSelectedValue(value);
|
|
302
302
|
if (subComponentInitialValue.current === null) {
|
|
303
|
-
// copy the default value of the subcomponent so we can change detect on save
|
|
303
|
+
// copy the default value of the subcomponent, so we can change detect on save
|
|
304
304
|
subComponentInitialValue.current = JSON.stringify(value);
|
|
305
305
|
}
|
|
306
306
|
},
|
|
@@ -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
|
|
|
@@ -37,6 +41,6 @@ export interface GenericCellRendererParams<RowType extends GridBaseRow> {
|
|
|
37
41
|
rightHoverElement?: JSX.Element | undefined;
|
|
38
42
|
editAction?: (selectedRows: RowType[]) => void;
|
|
39
43
|
shortcutKeys?: Record<string, ((params: SuppressKeyboardEventParams) => boolean | void) | undefined>;
|
|
40
|
-
warning?: (props: RowICellRendererParams<RowType>) => string | boolean | null | undefined;
|
|
41
|
-
info?: (props: RowICellRendererParams<RowType>) => string | boolean | null | undefined;
|
|
44
|
+
warning?: (props: RowICellRendererParams<RowType>) => string | string[] | boolean | null | undefined;
|
|
45
|
+
info?: (props: RowICellRendererParams<RowType>) => string | string[] | boolean | null | undefined;
|
|
42
46
|
}
|
package/dist/src/setupTests.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@testing-library/jest-dom";
|
package/src/setupTests.ts
DELETED