@linzjs/step-ag-grid 7.8.1 → 7.10.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/index.css +6 -1
- package/dist/index.js +28 -20
- package/dist/index.js.map +1 -1
- package/dist/src/components/Grid.d.ts +1 -0
- package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +3 -1
- package/dist/step-ag-grid.esm.js +28 -20
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +14 -11
- package/src/components/GridCell.tsx +8 -2
- package/src/components/gridRender/GridRenderGenericCell.tsx +3 -1
- package/src/stories/grid/GridPopoutBearing.stories.tsx +1 -1
- package/src/stories/grid/GridReadOnly.stories.tsx +10 -2
- package/src/styles/Grid.scss +6 -1
- package/src/utils/bearing.ts +1 -1
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -33,6 +33,7 @@ export interface GridProps {
|
|
|
33
33
|
postSortRows?: GridOptions["postSortRows"];
|
|
34
34
|
animateRows?: boolean;
|
|
35
35
|
rowClassRules?: GridOptions["rowClassRules"];
|
|
36
|
+
rowSelection?: "single" | "multiple";
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -200,15 +201,7 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
200
201
|
|
|
201
202
|
const onCellDoubleClick = useCallback(
|
|
202
203
|
(event: CellEvent) => {
|
|
203
|
-
|
|
204
|
-
if (!editable) return;
|
|
205
|
-
const editAction = event.colDef?.cellRendererParams?.editAction;
|
|
206
|
-
if (editAction) {
|
|
207
|
-
// Clicked row comes first in selected rows
|
|
208
|
-
editAction([event.data, ...event.api.getSelectedRows().filter((row) => row.id !== event.data.id)]);
|
|
209
|
-
} else if (!event.colDef?.cellRendererParams?.singleClickEdit) {
|
|
210
|
-
startCellEditing(event);
|
|
211
|
-
}
|
|
204
|
+
if (!invokeEditAction(event)) startCellEditing(event);
|
|
212
205
|
},
|
|
213
206
|
[startCellEditing],
|
|
214
207
|
);
|
|
@@ -222,9 +215,19 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
222
215
|
[startCellEditing],
|
|
223
216
|
);
|
|
224
217
|
|
|
218
|
+
const invokeEditAction = (e: CellEvent): boolean => {
|
|
219
|
+
const editAction = e.colDef?.cellRendererParams?.editAction;
|
|
220
|
+
if (!editAction) return false;
|
|
221
|
+
const editable = fnOrVar(e.colDef?.editable, e);
|
|
222
|
+
editable && editAction([e.data, ...e.api.getSelectedRows().filter((row) => row.id !== e.data.id)]);
|
|
223
|
+
return true;
|
|
224
|
+
};
|
|
225
|
+
|
|
225
226
|
const onCellKeyPress = useCallback(
|
|
226
227
|
(e: CellEvent) => {
|
|
227
|
-
if ((e.event as KeyboardEvent).key === "Enter")
|
|
228
|
+
if ((e.event as KeyboardEvent).key === "Enter") {
|
|
229
|
+
if (!invokeEditAction(e)) startCellEditing(e);
|
|
230
|
+
}
|
|
228
231
|
},
|
|
229
232
|
[startCellEditing],
|
|
230
233
|
);
|
|
@@ -271,7 +274,7 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
271
274
|
defaultColDef={params.defaultColDef}
|
|
272
275
|
getRowId={(params) => `${params.data.id}`}
|
|
273
276
|
suppressRowClickSelection={true}
|
|
274
|
-
rowSelection={"multiple"}
|
|
277
|
+
rowSelection={params.rowSelection ?? "multiple"}
|
|
275
278
|
suppressBrowserResizeObserver={true}
|
|
276
279
|
colResizeDefault={"shift"}
|
|
277
280
|
onFirstDataRendered={sizeColumnsToFit}
|
|
@@ -38,8 +38,8 @@ export const GridCellRenderer = (props: ICellRendererParams) => {
|
|
|
38
38
|
<span title={props.valueFormatted}>{props.valueFormatted}</span>
|
|
39
39
|
)}
|
|
40
40
|
</div>
|
|
41
|
-
{fnOrVar(props.colDef?.editable, props) && rendererParams?.
|
|
42
|
-
<div style={{ display: "flex", alignItems: "center" }}>{rendererParams?.
|
|
41
|
+
{fnOrVar(props.colDef?.editable, props) && rendererParams?.rightHoverElement && (
|
|
42
|
+
<div style={{ display: "flex", alignItems: "center" }}>{rendererParams?.rightHoverElement}</div>
|
|
43
43
|
)}
|
|
44
44
|
</>
|
|
45
45
|
</GridLoadableCell>
|
|
@@ -73,6 +73,12 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
73
73
|
cellEditor: GenericCellEditorComponentWrapper(custom),
|
|
74
74
|
}),
|
|
75
75
|
suppressKeyboardEvent: (e) => {
|
|
76
|
+
const shortcutKeys = e.colDef.cellRendererParams?.shortcutKeys ?? {};
|
|
77
|
+
const exec = shortcutKeys[e.event.key];
|
|
78
|
+
if (!e.editing && !e.event.repeat && e.event.type === "keypress" && exec) {
|
|
79
|
+
const editable = fnOrVar(e.colDef?.editable, e);
|
|
80
|
+
return editable ? exec(e) ?? true : true;
|
|
81
|
+
}
|
|
76
82
|
// It's important that aggrid doesn't trigger edit on enter
|
|
77
83
|
// as the incorrect selected rows will be returned
|
|
78
84
|
return !["ArrowLeft", "ArrowRight", "ArrowDown", "ArrowUp", "Tab", " "].includes(e.event.key);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ICellRendererParams } from "ag-grid-community";
|
|
2
2
|
import { GridBaseRow } from "../Grid";
|
|
3
3
|
import { ColDefT } from "../GridCell";
|
|
4
|
+
import { SuppressKeyboardEventParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
4
5
|
|
|
5
6
|
export interface RowICellRendererParams<RowType extends GridBaseRow> extends ICellRendererParams {
|
|
6
7
|
data: RowType;
|
|
@@ -12,8 +13,9 @@ export interface GenericCellColDef<RowType extends GridBaseRow> extends ColDefT<
|
|
|
12
13
|
|
|
13
14
|
export interface GenericCellRendererParams<RowType extends GridBaseRow> {
|
|
14
15
|
singleClickEdit?: boolean;
|
|
15
|
-
|
|
16
|
+
rightHoverElement?: JSX.Element | undefined;
|
|
16
17
|
editAction?: (selectedRows: RowType[]) => void;
|
|
18
|
+
shortcutKeys?: Record<string, ((params: SuppressKeyboardEventParams) => boolean | void) | undefined>;
|
|
17
19
|
warning?: (props: RowICellRendererParams<RowType>) => string | boolean | null | undefined;
|
|
18
20
|
info?: (props: RowICellRendererParams<RowType>) => string | boolean | null | undefined;
|
|
19
21
|
}
|
|
@@ -88,7 +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:
|
|
91
|
+
{ id: 1004, bearing: 5.0, bearingCorrection: "1.00500" },
|
|
92
92
|
] as ITestRow[]);
|
|
93
93
|
|
|
94
94
|
return (
|
|
@@ -101,10 +101,17 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
101
101
|
editable: true,
|
|
102
102
|
valueFormatter: () => "Double click me!",
|
|
103
103
|
cellRendererParams: {
|
|
104
|
-
|
|
104
|
+
rightHoverElement: (
|
|
105
|
+
<GridIcon icon={"ic_launch_modal"} title={"Title text"} className={"GridCell-editableIcon"} />
|
|
106
|
+
),
|
|
105
107
|
editAction: (selectedRows) => {
|
|
106
108
|
alert(`Custom edit ${selectedRows.length} row(s) selected`);
|
|
107
109
|
},
|
|
110
|
+
shortcutKeys: {
|
|
111
|
+
e: () => {
|
|
112
|
+
alert("Hi");
|
|
113
|
+
},
|
|
114
|
+
},
|
|
108
115
|
},
|
|
109
116
|
}),
|
|
110
117
|
GridPopoverMenu(
|
|
@@ -197,8 +204,9 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
197
204
|
columnDefs={columnDefs}
|
|
198
205
|
rowData={rowData}
|
|
199
206
|
domLayout={"autoHeight"}
|
|
207
|
+
rowSelection={"single"}
|
|
200
208
|
/>
|
|
201
209
|
);
|
|
202
210
|
};
|
|
203
211
|
|
|
204
|
-
export const
|
|
212
|
+
export const ReadOnlySingleSelection = GridReadOnlyTemplate.bind({});
|
package/src/styles/Grid.scss
CHANGED
|
@@ -35,8 +35,13 @@
|
|
|
35
35
|
padding: 4px 8px;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
.GridCell-editableIcon {
|
|
38
|
+
.ag-cell .GridCell-editableIcon {
|
|
39
39
|
fill: colors.$silver;
|
|
40
|
+
visibility: hidden;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.ag-cell:hover .GridCell-editableIcon, .ag-cell.ag-cell-focus .GridCell-editableIcon {
|
|
44
|
+
visibility: visible;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
.GridFormMessage-container {
|
package/src/utils/bearing.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const bearingCorrectionValueFormatter = (params: ValueFormatterParams): s
|
|
|
14
14
|
return "–";
|
|
15
15
|
}
|
|
16
16
|
if (typeof value === "string") {
|
|
17
|
-
return convertDDToDMS(bearingNumberParser(value), true,
|
|
17
|
+
return convertDDToDMS(bearingNumberParser(value), true, false);
|
|
18
18
|
}
|
|
19
19
|
return convertDDToDMS(value, true, false);
|
|
20
20
|
};
|