@linzjs/step-ag-grid 8.2.2 → 8.3.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/step-ag-grid.esm.js +42 -26
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +18 -8
- package/src/components/GridCell.tsx +2 -1
- package/src/components/gridForm/GridFormDropDown.tsx +20 -11
- package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +2 -2
- package/src/stories/grid/GridNonEditableRow.stories.tsx +1 -3
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import { usePostSortRowsHook } from "./PostSortRowsHook";
|
|
|
10
10
|
import { fnOrVar, isNotEmpty } from "../utils/util";
|
|
11
11
|
import { GridHeaderSelect } from "./gridHeader/GridHeaderSelect";
|
|
12
12
|
import { GridUpdatingContext } from "../contexts/GridUpdatingContext";
|
|
13
|
-
import { CellClassParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
13
|
+
import { CellClassParams, EditableCallback, EditableCallbackParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
14
14
|
|
|
15
15
|
export interface GridBaseRow {
|
|
16
16
|
id: string | number;
|
|
@@ -162,6 +162,16 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
162
162
|
updateQuickFilter();
|
|
163
163
|
}, [updateQuickFilter]);
|
|
164
164
|
|
|
165
|
+
const combineEditables =
|
|
166
|
+
(...editables: (boolean | EditableCallback | undefined)[]) =>
|
|
167
|
+
(params: EditableCallbackParams): boolean => {
|
|
168
|
+
const results = editables.map((editable) => fnOrVar(editable, params));
|
|
169
|
+
// If editable is not set anywhere then it's non-editable
|
|
170
|
+
if (results.every((v) => v == null)) return false;
|
|
171
|
+
// If any editable value is or returns false then it's non-editable
|
|
172
|
+
return !results.some((v) => v == false);
|
|
173
|
+
};
|
|
174
|
+
|
|
165
175
|
/**
|
|
166
176
|
* Synchronise externally selected items to grid on externalSelectedItems change
|
|
167
177
|
*/
|
|
@@ -171,14 +181,14 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
171
181
|
|
|
172
182
|
const columnDefs = useMemo((): ColDef[] => {
|
|
173
183
|
const adjustColDefs = params.columnDefs.map((colDef) => {
|
|
184
|
+
const colDefEditable = colDef.editable;
|
|
185
|
+
const editable = combineEditables(params.readOnly !== false, params.defaultColDef?.editable, colDefEditable);
|
|
174
186
|
return {
|
|
175
187
|
...colDef,
|
|
176
|
-
editable
|
|
188
|
+
editable,
|
|
177
189
|
cellClassRules: {
|
|
178
190
|
...colDef.cellClassRules,
|
|
179
|
-
"GridCell-readonly": (ccp: CellClassParams) =>
|
|
180
|
-
(params.readOnly != null || !params.readOnly) &&
|
|
181
|
-
!fnOrVar(params.defaultColDef?.editable ?? colDef.editable, ccp),
|
|
191
|
+
"GridCell-readonly": (ccp: CellClassParams) => !editable(ccp as any as EditableCallbackParams),
|
|
182
192
|
},
|
|
183
193
|
};
|
|
184
194
|
});
|
|
@@ -187,9 +197,8 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
187
197
|
{
|
|
188
198
|
colId: "selection",
|
|
189
199
|
editable: false,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
maxWidth: 35,
|
|
200
|
+
minWidth: 42,
|
|
201
|
+
maxWidth: 42,
|
|
193
202
|
suppressSizeToFit: true,
|
|
194
203
|
checkboxSelection: true,
|
|
195
204
|
headerComponent: GridHeaderSelect,
|
|
@@ -280,6 +289,7 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
280
289
|
const invokeEditAction = (e: CellEvent): boolean => {
|
|
281
290
|
const editAction = e.colDef?.cellRendererParams?.editAction;
|
|
282
291
|
if (!editAction) return false;
|
|
292
|
+
|
|
283
293
|
const editable = fnOrVar(e.colDef?.editable, e);
|
|
284
294
|
if (editable) {
|
|
285
295
|
if (!e.node.isSelected()) {
|
|
@@ -67,7 +67,7 @@ export const suppressCellKeyboardEvents = (e: SuppressKeyboardEventParams) => {
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
/*
|
|
70
|
-
* All cells should use this
|
|
70
|
+
* All cells should use this.
|
|
71
71
|
*/
|
|
72
72
|
export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCommon>(
|
|
73
73
|
props: GenericCellColDef<RowType>,
|
|
@@ -81,6 +81,7 @@ export const GridCell = <RowType extends GridBaseRow, Props extends CellEditorCo
|
|
|
81
81
|
colId: props.field,
|
|
82
82
|
sortable: !!(props?.field || props?.valueGetter),
|
|
83
83
|
resizable: true,
|
|
84
|
+
editable: props.editable ?? false,
|
|
84
85
|
...(custom?.editor && {
|
|
85
86
|
cellClassRules: GridCellMultiSelectClassRules,
|
|
86
87
|
editable: props.editable ?? true,
|
|
@@ -188,6 +188,23 @@ 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
|
+
|
|
191
208
|
const { popoverWrapper } = useGridPopoverHook({
|
|
192
209
|
className: props.className,
|
|
193
210
|
invalid: () => !!(selectedItem && !subComponentIsValid.current),
|
|
@@ -268,17 +285,9 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
|
|
|
268
285
|
disabled={!!item.disabled}
|
|
269
286
|
title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""}
|
|
270
287
|
value={item.value}
|
|
271
|
-
onFocus={() =>
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
setSelectedItem(item);
|
|
275
|
-
subComponentIsValid.current = true;
|
|
276
|
-
subComponentInitialValue.current = null;
|
|
277
|
-
} else {
|
|
278
|
-
setSubSelectedValue(null);
|
|
279
|
-
subComponentIsValid.current = true;
|
|
280
|
-
}
|
|
281
|
-
}}
|
|
288
|
+
onFocus={() => onMouseEnterFocus(item)}
|
|
289
|
+
onMouseEnter={() => onMouseEnterFocus(item)}
|
|
290
|
+
onMouseLeave={onMouseLeaveFocus}
|
|
282
291
|
onClick={(e: ClickEvent) => {
|
|
283
292
|
if (item.subComponent) {
|
|
284
293
|
e.keepOpen = true;
|
|
@@ -13,8 +13,8 @@ export const GridPopoverMenu = <RowType extends GridBaseRow>(
|
|
|
13
13
|
): ColDefT<RowType> =>
|
|
14
14
|
GridCell<RowType, GridFormPopoverMenuProps<RowType>>(
|
|
15
15
|
{
|
|
16
|
-
minWidth:
|
|
17
|
-
maxWidth:
|
|
16
|
+
minWidth: 48,
|
|
17
|
+
maxWidth: 48,
|
|
18
18
|
width: 40,
|
|
19
19
|
editable: colDef.editable != null ? colDef.editable : true,
|
|
20
20
|
cellStyle: { justifyContent: "center" },
|
|
@@ -168,17 +168,15 @@ const GridNonEditableRowTemplate: ComponentStory<typeof Grid> = (props: GridProp
|
|
|
168
168
|
return (
|
|
169
169
|
<Grid
|
|
170
170
|
{...props}
|
|
171
|
-
selectable={true}
|
|
172
171
|
externalSelectedItems={externalSelectedItems}
|
|
173
172
|
setExternalSelectedItems={setExternalSelectedItems}
|
|
174
173
|
defaultColDef={defaultColDef}
|
|
175
174
|
columnDefs={columnDefs}
|
|
176
175
|
rowData={rowData}
|
|
177
176
|
domLayout={"autoHeight"}
|
|
178
|
-
autoSelectFirstRow={true}
|
|
179
|
-
readOnly={false}
|
|
180
177
|
/>
|
|
181
178
|
);
|
|
182
179
|
};
|
|
183
180
|
|
|
184
181
|
export const NonEditableRow = GridNonEditableRowTemplate.bind({});
|
|
182
|
+
NonEditableRow.args = { autoSelectFirstRow: true, selectable: true };
|