@linzjs/step-ag-grid 8.3.1 → 8.4.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/components/GridPopoverHook.d.ts +1 -0
- package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +2 -2
- package/dist/step-ag-grid.esm.js +30 -24
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridCell.tsx +14 -5
- package/src/components/GridPopoverHook.tsx +7 -2
- package/src/components/gridForm/GridFormDropDown.tsx +15 -24
- package/src/components/gridRender/GridRenderGenericCell.tsx +2 -2
- package/src/stories/grid/GridReadOnly.stories.tsx +1 -1
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import { GridBaseRow } from "./Grid";
|
|
|
3
3
|
import { GridUpdatingContext } from "../contexts/GridUpdatingContext";
|
|
4
4
|
import { GridCellMultiSelectClassRules } from "./GridCellMultiSelectClassRules";
|
|
5
5
|
import { GenericCellColDef, GenericCellRendererParams } from "./gridRender/GridRenderGenericCell";
|
|
6
|
-
import { ColDef, ICellEditorParams, ICellRendererParams } from "ag-grid-community";
|
|
6
|
+
import { ColDef, ICellEditorParams, ICellRendererParams, ValueGetterFunc } from "ag-grid-community";
|
|
7
7
|
import { GridLoadableCell } from "./GridLoadableCell";
|
|
8
8
|
import { GridIcon } from "./GridIcon";
|
|
9
9
|
import { SuppressKeyboardEventParams, ValueFormatterParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
@@ -22,15 +22,19 @@ export const GridCellRenderer = (props: ICellRendererParams) => {
|
|
|
22
22
|
|
|
23
23
|
const rendererParams = colDef.cellRendererParams as GenericCellRendererParams<any> | undefined;
|
|
24
24
|
const warningFn = rendererParams?.warning;
|
|
25
|
-
|
|
25
|
+
let warningText = warningFn ? warningFn(props) : undefined;
|
|
26
26
|
const infoFn = rendererParams?.info;
|
|
27
|
-
|
|
27
|
+
let infoText = infoFn ? infoFn(props) : undefined;
|
|
28
|
+
if (Array.isArray(warningText)) warningText = warningText.join("\n");
|
|
29
|
+
if (Array.isArray(infoText)) infoText = infoText.join("\n");
|
|
28
30
|
|
|
29
31
|
return (
|
|
30
32
|
<GridLoadableCell isLoading={checkUpdating(colDef.field ?? colDef.colId ?? "", props.data.id)}>
|
|
31
33
|
<>
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
+
{!!warningText && (
|
|
35
|
+
<GridIcon icon={"ic_warning_outline"} title={typeof warningText === "string" ? warningText : "Warning"} />
|
|
36
|
+
)}
|
|
37
|
+
{!!infoText && <GridIcon icon={"ic_info_outline"} title={typeof infoText === "string" ? infoText : "Info"} />}
|
|
34
38
|
<div style={{ display: "flex", flex: 1, overflow: "hidden" }}>
|
|
35
39
|
{colDef?.cellRendererParams?.originalCellRenderer ? (
|
|
36
40
|
<colDef.cellRendererParams.originalCellRenderer {...props} />
|
|
@@ -91,6 +95,11 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
91
95
|
...(custom?.editorParams && {
|
|
92
96
|
cellEditorParams: { ...custom.editorParams, multiEdit: custom.multiEdit },
|
|
93
97
|
}),
|
|
98
|
+
// If there's a valueFormatter and no filterValueGetter then create a filterValueGetter
|
|
99
|
+
...(props.valueFormatter &&
|
|
100
|
+
!props.filterValueGetter && {
|
|
101
|
+
filterValueGetter: props.valueFormatter as string | ValueGetterFunc,
|
|
102
|
+
}),
|
|
94
103
|
// Default value formatter, otherwise react freaks out on objects
|
|
95
104
|
valueFormatter: (params: ValueFormatterParams) => {
|
|
96
105
|
if (params.value == null) return "–";
|
|
@@ -16,6 +16,7 @@ export interface GridPopoverHookProps<RowType> {
|
|
|
16
16
|
| null
|
|
17
17
|
| undefined;
|
|
18
18
|
save?: (selectedRows: RowType[]) => Promise<boolean>;
|
|
19
|
+
dontSaveOnExternalClick?: boolean;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopoverHookProps<RowType>) => {
|
|
@@ -96,7 +97,11 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopov
|
|
|
96
97
|
ref={saveButtonRef}
|
|
97
98
|
data-reason={""}
|
|
98
99
|
onClick={(e) => {
|
|
99
|
-
|
|
100
|
+
let reason = e.currentTarget.getAttribute("data-reason") ?? undefined;
|
|
101
|
+
if (props.dontSaveOnExternalClick && reason === CloseReason.BLUR) {
|
|
102
|
+
reason = CloseReason.CANCEL;
|
|
103
|
+
}
|
|
104
|
+
triggerSave(reason).then();
|
|
100
105
|
}}
|
|
101
106
|
style={{ display: "none" }}
|
|
102
107
|
/>
|
|
@@ -105,7 +110,7 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopov
|
|
|
105
110
|
</>
|
|
106
111
|
);
|
|
107
112
|
},
|
|
108
|
-
[anchorRef, isOpen, props.className, saving, triggerSave],
|
|
113
|
+
[anchorRef, isOpen, props.className, props.dontSaveOnExternalClick, saving, triggerSave],
|
|
109
114
|
);
|
|
110
115
|
|
|
111
116
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FocusableItem, MenuDivider, MenuHeader, MenuItem } from "../../react-menu3";
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { GridBaseRow } from "../Grid";
|
|
4
4
|
import { ComponentLoadingWrapper } from "../ComponentLoadingWrapper";
|
|
5
5
|
import { isEmpty } from "lodash-es";
|
|
@@ -188,27 +188,11 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
|
|
|
188
188
|
return true;
|
|
189
189
|
}, [filter, filteredValues, options, props, selectItemHandler, selectedItem, selectedRows, subSelectedValue]);
|
|
190
190
|
|
|
191
|
-
const onMouseEnterFocus = useCallback((item: FinalSelectOption) => {
|
|
192
|
-
setSelectedItem(item);
|
|
193
|
-
if (item.subComponent) {
|
|
194
|
-
subComponentIsValid.current = true;
|
|
195
|
-
subComponentInitialValue.current = null;
|
|
196
|
-
} else {
|
|
197
|
-
setSubSelectedValue(null);
|
|
198
|
-
subComponentIsValid.current = true;
|
|
199
|
-
}
|
|
200
|
-
}, []);
|
|
201
|
-
|
|
202
|
-
const onMouseLeaveFocus = useCallback(() => {
|
|
203
|
-
setSelectedItem(null);
|
|
204
|
-
setSubSelectedValue(null);
|
|
205
|
-
subComponentIsValid.current = true;
|
|
206
|
-
}, []);
|
|
207
|
-
|
|
208
191
|
const { popoverWrapper } = useGridPopoverHook({
|
|
209
192
|
className: props.className,
|
|
210
193
|
invalid: () => !!(selectedItem && !subComponentIsValid.current),
|
|
211
194
|
save,
|
|
195
|
+
dontSaveOnExternalClick: true,
|
|
212
196
|
});
|
|
213
197
|
|
|
214
198
|
let lastHeader: JSX.Element | null = null;
|
|
@@ -277,7 +261,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
|
|
|
277
261
|
}
|
|
278
262
|
return (
|
|
279
263
|
(!filteredValues || filteredValues.includes(item)) && (
|
|
280
|
-
|
|
264
|
+
<Fragment key={`${index}`}>
|
|
281
265
|
{showHeader}
|
|
282
266
|
<div key={`menu-wrapper-${index}`}>
|
|
283
267
|
<MenuItem
|
|
@@ -285,9 +269,16 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
|
|
|
285
269
|
disabled={!!item.disabled}
|
|
286
270
|
title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""}
|
|
287
271
|
value={item.value}
|
|
288
|
-
onFocus={() =>
|
|
289
|
-
|
|
290
|
-
|
|
272
|
+
onFocus={() => {
|
|
273
|
+
setSelectedItem(item);
|
|
274
|
+
if (item.subComponent) {
|
|
275
|
+
subComponentIsValid.current = true;
|
|
276
|
+
subComponentInitialValue.current = null;
|
|
277
|
+
} else {
|
|
278
|
+
setSubSelectedValue(null);
|
|
279
|
+
subComponentIsValid.current = true;
|
|
280
|
+
}
|
|
281
|
+
}}
|
|
291
282
|
onClick={(e: ClickEvent) => {
|
|
292
283
|
if (item.subComponent) {
|
|
293
284
|
e.keepOpen = true;
|
|
@@ -309,7 +300,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
|
|
|
309
300
|
setValue: (value: any) => {
|
|
310
301
|
setSubSelectedValue(value);
|
|
311
302
|
if (subComponentInitialValue.current === null) {
|
|
312
|
-
// 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
|
|
313
304
|
subComponentInitialValue.current = JSON.stringify(value);
|
|
314
305
|
}
|
|
315
306
|
},
|
|
@@ -331,7 +322,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
|
|
|
331
322
|
</FocusableItem>
|
|
332
323
|
)}
|
|
333
324
|
</div>
|
|
334
|
-
|
|
325
|
+
</Fragment>
|
|
335
326
|
)
|
|
336
327
|
);
|
|
337
328
|
})}
|
|
@@ -37,6 +37,6 @@ export interface GenericCellRendererParams<RowType extends GridBaseRow> {
|
|
|
37
37
|
rightHoverElement?: JSX.Element | undefined;
|
|
38
38
|
editAction?: (selectedRows: RowType[]) => void;
|
|
39
39
|
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;
|
|
40
|
+
warning?: (props: RowICellRendererParams<RowType>) => string | string[] | boolean | null | undefined;
|
|
41
|
+
info?: (props: RowICellRendererParams<RowType>) => string | string[] | boolean | null | undefined;
|
|
42
42
|
}
|
|
@@ -100,7 +100,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
100
100
|
headerName: "Custom edit",
|
|
101
101
|
maxWidth: 100,
|
|
102
102
|
editable: true,
|
|
103
|
-
valueFormatter: () => "
|
|
103
|
+
valueFormatter: () => "Press E",
|
|
104
104
|
cellRendererParams: {
|
|
105
105
|
rightHoverElement: (
|
|
106
106
|
<GridIcon icon={"ic_launch_modal"} title={"Title text"} className={"GridCell-editableIcon"} />
|