@linzjs/step-ag-grid 14.3.2 → 14.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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { ColumnApi, GridApi, RowNode } from "ag-grid-community";
2
+ import { ColDef, ColumnApi, GridApi, RowNode } from "ag-grid-community";
3
3
  import { CsvExportParams } from "ag-grid-community/dist/lib/interfaces/exportParams";
4
4
  import { ColDefT, GridBaseRow } from "../components";
5
5
  export type GridFilterExternal<RowType extends GridBaseRow> = (data: RowType, rowNode: RowNode) => boolean;
@@ -13,6 +13,8 @@ export type AutoSizeColumnsResult = {
13
13
  } | null;
14
14
  export interface GridContextType<RowType extends GridBaseRow> {
15
15
  gridReady: boolean;
16
+ getColDef: (colId?: string) => ColDef | undefined;
17
+ getColumns: () => ColDefT<RowType>[];
16
18
  setApis: (gridApi: GridApi | undefined, columnApi: ColumnApi | undefined, dataTestId?: string) => void;
17
19
  prePopupOps: () => void;
18
20
  setQuickFilter: (quickFilter: string) => void;
@@ -34,6 +36,10 @@ export interface GridContextType<RowType extends GridBaseRow> {
34
36
  autoSizeColumns: (props?: AutoSizeColumnsProps) => AutoSizeColumnsResult;
35
37
  sizeColumnsToFit: () => void;
36
38
  cancelEdit: () => void;
39
+ startCellEditing: ({ rowId, colId }: {
40
+ rowId: number;
41
+ colId: string;
42
+ }) => void;
37
43
  stopEditing: () => void;
38
44
  updatingCells: (props: {
39
45
  selectedRows: GridBaseRow[];
@@ -47,7 +53,6 @@ export interface GridContextType<RowType extends GridBaseRow> {
47
53
  removeExternalFilter: (filter: GridFilterExternal<RowType>) => void;
48
54
  isExternalFilterPresent: () => boolean;
49
55
  doesExternalFilterPass: (node: RowNode) => boolean;
50
- getColumns: () => ColDefT<RowType>[];
51
56
  invisibleColumnIds: string[];
52
57
  setInvisibleColumnIds: (colIds: string[]) => void;
53
58
  downloadCsv: (csvExportParams?: CsvExportParams) => void;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  export type GridUpdatingContextType = {
3
3
  checkUpdating: (fields: string | string[], id: number | string) => boolean;
4
- isUpdating: () => boolean;
5
4
  modifyUpdating: (fields: string | string[], ids: (number | string)[], fn: () => void | Promise<void>) => Promise<void>;
6
5
  updatedDep: number;
6
+ updatingCols: () => string[];
7
7
  };
8
8
  export declare const GridUpdatingContext: import("react").Context<GridUpdatingContextType>;
@@ -123,6 +123,10 @@ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else i
123
123
 
124
124
  var GridContext = createContext({
125
125
  gridReady: false,
126
+ getColDef: function () {
127
+ console.error("no context provider for getColDef");
128
+ return undefined;
129
+ },
126
130
  getColumns: function () {
127
131
  console.error("no context provider for getColumns");
128
132
  return [];
@@ -216,6 +220,9 @@ var GridContext = createContext({
216
220
  cancelEdit: function () {
217
221
  console.error("no context provider for cancelEdit");
218
222
  },
223
+ startCellEditing: function () {
224
+ console.error("no context provider for startCellEditing");
225
+ },
219
226
  stopEditing: function () {
220
227
  console.error("no context provider for stopEditing");
221
228
  },
@@ -265,9 +272,9 @@ var GridUpdatingContext = createContext({
265
272
  console.error("Missing GridUpdatingContext");
266
273
  return false;
267
274
  },
268
- isUpdating: function () {
275
+ updatingCols: function () {
269
276
  console.error("Missing GridUpdatingContext");
270
- return false;
277
+ return [];
271
278
  },
272
279
  modifyUpdating: function () { return __awaiter(void 0, void 0, void 0, function () {
273
280
  return __generator(this, function (_a) {
@@ -714,8 +721,9 @@ var GridHeaderSelect = function (_a) {
714
721
  var Grid = function (_a) {
715
722
  var _b, _c, _d;
716
723
  var dataTestId = _a["data-testid"], _e = _a.rowSelection, rowSelection = _e === void 0 ? "multiple" : _e, _f = _a.suppressColumnVirtualization, suppressColumnVirtualization = _f === void 0 ? true : _f, _g = _a.theme, theme = _g === void 0 ? "ag-theme-alpine" : _g, _h = _a.sizeColumns, sizeColumns = _h === void 0 ? "auto" : _h, _j = _a.selectColumnPinned, selectColumnPinned = _j === void 0 ? null : _j, params = __rest(_a, ["data-testid", "rowSelection", "suppressColumnVirtualization", "theme", "sizeColumns", "selectColumnPinned"]);
717
- var _k = useContext(GridContext), gridReady = _k.gridReady, setApis = _k.setApis, prePopupOps = _k.prePopupOps, ensureRowVisible = _k.ensureRowVisible, getFirstRowId = _k.getFirstRowId, selectRowsById = _k.selectRowsById, focusByRowById = _k.focusByRowById, ensureSelectedRowIsVisible = _k.ensureSelectedRowIsVisible, autoSizeColumns = _k.autoSizeColumns, sizeColumnsToFit = _k.sizeColumnsToFit, externallySelectedItemsAreInSync = _k.externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync = _k.setExternallySelectedItemsAreInSync, isExternalFilterPresent = _k.isExternalFilterPresent, doesExternalFilterPass = _k.doesExternalFilterPass, setOnCellEditingComplete = _k.setOnCellEditingComplete;
718
- var _l = useContext(GridUpdatingContext), checkUpdating = _l.checkUpdating, updatedDep = _l.updatedDep, isUpdating = _l.isUpdating;
724
+ var _k = useContext(GridContext), gridReady = _k.gridReady, setApis = _k.setApis, ensureRowVisible = _k.ensureRowVisible, getFirstRowId = _k.getFirstRowId, selectRowsById = _k.selectRowsById, focusByRowById = _k.focusByRowById, ensureSelectedRowIsVisible = _k.ensureSelectedRowIsVisible, autoSizeColumns = _k.autoSizeColumns, sizeColumnsToFit = _k.sizeColumnsToFit, externallySelectedItemsAreInSync = _k.externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync = _k.setExternallySelectedItemsAreInSync, isExternalFilterPresent = _k.isExternalFilterPresent, doesExternalFilterPass = _k.doesExternalFilterPass, setOnCellEditingComplete = _k.setOnCellEditingComplete, getColDef = _k.getColDef;
725
+ var _l = useContext(GridUpdatingContext), updatedDep = _l.updatedDep, updatingCols = _l.updatingCols;
726
+ var gridContext = useContext(GridContext);
719
727
  var gridDivRef = useRef(null);
720
728
  var lastSelectedIds = useRef([]);
721
729
  var _m = useState(false), staleGrid = _m[0], setStaleGrid = _m[1];
@@ -944,12 +952,12 @@ var Grid = function (_a) {
944
952
  return;
945
953
  lastUpdatedDep.current = updatedDep;
946
954
  // Don't update while there are spinners
947
- if (isUpdating())
955
+ if (!isEmpty(updatingCols()))
948
956
  return;
949
957
  var skipHeader = sizeColumns === "auto-skip-headers";
950
958
  autoSizeColumns({ skipHeader: skipHeader, userSizedColIds: userSizedColIds.current, colIds: colIdsEdited.current });
951
959
  colIdsEdited.current.clear();
952
- }, [autoSizeColumns, isUpdating, (_c = params.rowData) === null || _c === void 0 ? void 0 : _c.length, setInitialContentSize, sizeColumns, updatedDep]);
960
+ }, [autoSizeColumns, (_c = params.rowData) === null || _c === void 0 ? void 0 : _c.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
953
961
  /**
954
962
  * Show/hide no rows overlay when model changes.
955
963
  */
@@ -981,22 +989,12 @@ var Grid = function (_a) {
981
989
  * Make sure node is selected for editing and start edit
982
990
  */
983
991
  var startCellEditing = useCallback(function (event) {
984
- var _a;
985
- prePopupOps();
986
- if (!event.node.isSelected()) {
987
- event.node.setSelected(true, true);
988
- }
989
- // Cell already being edited, so don't re-edit until finished
990
- if (checkUpdating([(_a = event.colDef.field) !== null && _a !== void 0 ? _a : ""], event.data.id)) {
991
- return;
992
- }
993
- if (event.rowIndex !== null) {
994
- event.api.startEditingCell({
995
- rowIndex: event.rowIndex,
996
- colKey: event.column.getColId()
992
+ event.data.id &&
993
+ gridContext.startCellEditing({
994
+ rowId: event.data.id,
995
+ colId: event.column.getColId()
997
996
  });
998
- }
999
- }, [checkUpdating, prePopupOps]);
997
+ }, [gridContext]);
1000
998
  /**
1001
999
  * Handle double click edit
1002
1000
  */
@@ -1050,42 +1048,40 @@ var Grid = function (_a) {
1050
1048
  * Set of colIds that need auto-sizing.
1051
1049
  */
1052
1050
  var colIdsEdited = useRef(new Set());
1051
+ var lastUpdatedDep = useRef(updatedDep);
1053
1052
  /**
1054
- * When cell editing has completed tag the colId as needing auto-sizing
1053
+ * When cell editing has completed the colId as needing auto-sizing
1055
1054
  */
1056
- var onCellEditingStopped = useCallback(function (e) {
1057
- var skipHeader = sizeColumns === "auto-skip-headers";
1058
- if (sizeColumns === "auto" || skipHeader) {
1059
- // This may be wrong as the cell update hasn't completed?
1060
- var colId = e.colDef.colId;
1061
- if (colId && !e.colDef.flex) {
1062
- // This auto-sizes based on updatingContext completing
1063
- colIdsEdited.current.add(colId);
1064
- // This auto-sizes immediately in case it was an in place update
1065
- !isUpdating() &&
1055
+ useEffect(function () {
1056
+ if (lastUpdatedDep.current === updatedDep)
1057
+ return;
1058
+ lastUpdatedDep.current = updatedDep;
1059
+ var colIds = updatingCols();
1060
+ // Updating possibly completed
1061
+ if (isEmpty(colIds)) {
1062
+ // Columns to resize?
1063
+ if (!isEmpty(colIdsEdited.current)) {
1064
+ var skipHeader = sizeColumns === "auto-skip-headers";
1065
+ if (sizeColumns === "auto" || skipHeader) {
1066
1066
  autoSizeColumns({
1067
1067
  skipHeader: skipHeader,
1068
1068
  userSizedColIds: userSizedColIds.current,
1069
- colIds: [colId]
1069
+ colIds: colIdsEdited.current
1070
1070
  });
1071
+ }
1072
+ colIdsEdited.current.clear();
1071
1073
  }
1072
1074
  }
1073
- }, [autoSizeColumns, isUpdating, sizeColumns]);
1074
- var lastUpdatedDep = useRef(updatedDep);
1075
- /**
1076
- * If columns are edited, wait for the updating context to complete then auto-size them.
1077
- */
1078
- useEffect(function () {
1079
- if (lastUpdatedDep.current === updatedDep || isEmpty(colIdsEdited.current))
1080
- return;
1081
- lastUpdatedDep.current = updatedDep;
1082
- // Don't update while there are spinners
1083
- if (isUpdating())
1084
- return;
1085
- var skipHeader = sizeColumns === "auto-skip-headers";
1086
- autoSizeColumns({ skipHeader: skipHeader, userSizedColIds: userSizedColIds.current, colIds: colIdsEdited.current });
1087
- colIdsEdited.current.clear();
1088
- }, [autoSizeColumns, updatedDep, sizeColumns, isUpdating]);
1075
+ else {
1076
+ // Updates not complete, add them to a list of columns needing resize
1077
+ colIds.forEach(function (colId) {
1078
+ var _a;
1079
+ if (colId && !((_a = getColDef(colId)) === null || _a === void 0 ? void 0 : _a.flex)) {
1080
+ colIdsEdited.current.add(colId);
1081
+ }
1082
+ });
1083
+ }
1084
+ }, [autoSizeColumns, getColDef, sizeColumns, updatedDep, updatingCols]);
1089
1085
  /**
1090
1086
  * Resize columns to fit if required on window/container resize
1091
1087
  */
@@ -1118,7 +1114,7 @@ var Grid = function (_a) {
1118
1114
  setOnCellEditingComplete(params.onCellEditingComplete);
1119
1115
  return (jsx("div", __assign({ "data-testid": dataTestId, className: clsx("Grid-container", theme, staleGrid && "Grid-sortIsStale", gridReady && params.rowData && "Grid-ready") }, { children: jsx("div", __assign({ style: { flex: 1 }, ref: gridDivRef }, { children: jsx(AgGridReact, { animateRows: params.animateRows, rowClassRules: params.rowClassRules, getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: rowSelection, suppressBrowserResizeObserver: true, onGridSizeChanged: onGridSizeChanged, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: function () {
1120
1116
  setInitialContentSize();
1121
- }, onRowDataChanged: onRowDataChanged, onCellKeyPress: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, domLayout: params.domLayout, onCellEditingStopped: onCellEditingStopped, onColumnResized: onColumnResized, defaultColDef: __assign({ minWidth: 48 }, omit(params.defaultColDef, ["editable"])), columnDefs: columnDefsAdjusted, rowData: params.rowData, noRowsOverlayComponent: GridNoRowsOverlay, noRowsOverlayComponentParams: {
1117
+ }, onRowDataChanged: onRowDataChanged, onCellKeyPress: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: __assign({ minWidth: 48 }, omit(params.defaultColDef, ["editable"])), columnDefs: columnDefsAdjusted, rowData: params.rowData, noRowsOverlayComponent: GridNoRowsOverlay, noRowsOverlayComponentParams: {
1122
1118
  rowData: params.rowData,
1123
1119
  noRowsOverlayText: params.noRowsOverlayText
1124
1120
  }, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: (_d = params.postSortRows) !== null && _d !== void 0 ? _d : postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true }) })) })));
@@ -4645,16 +4641,16 @@ var GridWrapper = function (_a) {
4645
4641
  * Also, make sure the provider is created in a separate component, otherwise it won't be found.
4646
4642
  */
4647
4643
  var GridContextProvider = function (props) {
4648
- var modifyUpdating = useContext(GridUpdatingContext).modifyUpdating;
4649
- var _a = useState(), gridApi = _a[0], setGridApi = _a[1];
4650
- var _b = useState(), columnApi = _b[0], setColumnApi = _b[1];
4651
- var _c = useState(false), gridReady = _c[0], setGridReady = _c[1];
4652
- var _d = useState(""), quickFilter = _d[0], setQuickFilter = _d[1];
4653
- var _e = useState([]), invisibleColumnIds = _e[0], setInvisibleColumnIds = _e[1];
4644
+ var _a = useContext(GridUpdatingContext), modifyUpdating = _a.modifyUpdating, checkUpdating = _a.checkUpdating;
4645
+ var _b = useState(), gridApi = _b[0], setGridApi = _b[1];
4646
+ var _c = useState(), columnApi = _c[0], setColumnApi = _c[1];
4647
+ var _d = useState(false), gridReady = _d[0], setGridReady = _d[1];
4648
+ var _e = useState(""), quickFilter = _e[0], setQuickFilter = _e[1];
4649
+ var _f = useState([]), invisibleColumnIds = _f[0], setInvisibleColumnIds = _f[1];
4654
4650
  var testId = useRef();
4655
4651
  var idsBeforeUpdate = useRef([]);
4656
4652
  var prePopupFocusedCell = useRef();
4657
- var _f = useState(false), externallySelectedItemsAreInSync = _f[0], setExternallySelectedItemsAreInSync = _f[1];
4653
+ var _g = useState(false), externallySelectedItemsAreInSync = _g[0], setExternallySelectedItemsAreInSync = _g[1];
4658
4654
  var externalFilters = useRef([]);
4659
4655
  /**
4660
4656
  * Set quick filter directly on grid, based on previously save quickFilter state.
@@ -4939,6 +4935,43 @@ var GridContextProvider = function (props) {
4939
4935
  }
4940
4936
  gridApi.stopEditing();
4941
4937
  }, [gridApi]);
4938
+ var startCellEditing = useCallback(function (_a) {
4939
+ var rowId = _a.rowId, colId = _a.colId;
4940
+ return __awaiter(void 0, void 0, void 0, function () {
4941
+ var colDef, rowNode, rowIndex, focusAndEdit;
4942
+ var _b;
4943
+ return __generator(this, function (_c) {
4944
+ if (!gridApi)
4945
+ return [2 /*return*/];
4946
+ colDef = gridApi.getColumnDef(colId);
4947
+ if (!colDef)
4948
+ return [2 /*return*/];
4949
+ // Cell already being edited, so don't re-edit until finished
4950
+ if (checkUpdating([(_b = colDef.field) !== null && _b !== void 0 ? _b : ""], rowId)) {
4951
+ return [2 /*return*/];
4952
+ }
4953
+ rowNode = gridApi.getRowNode("".concat(rowId));
4954
+ if (!rowNode) {
4955
+ return [2 /*return*/];
4956
+ }
4957
+ if (!rowNode.isSelected()) {
4958
+ rowNode.setSelected(true, true);
4959
+ }
4960
+ prePopupOps();
4961
+ rowIndex = rowNode.rowIndex;
4962
+ if (rowIndex != null) {
4963
+ focusAndEdit = function () {
4964
+ gridApi.startEditingCell({
4965
+ rowIndex: rowIndex,
4966
+ colKey: colId
4967
+ });
4968
+ };
4969
+ defer$1(focusAndEdit);
4970
+ }
4971
+ return [2 /*return*/];
4972
+ });
4973
+ });
4974
+ }, [checkUpdating, gridApi, prePopupOps]);
4942
4975
  /**
4943
4976
  * This differs from stopEdit in that it will also invoke cellEditingCompleteCallback
4944
4977
  */
@@ -5101,6 +5134,7 @@ var GridContextProvider = function (props) {
5101
5134
  var doesExternalFilterPass = function (node) {
5102
5135
  return externalFilters.current.every(function (filter) { return filter(node.data, node); });
5103
5136
  };
5137
+ var getColDef = useCallback(function (colId) { return (!!colId && (gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(colId))) || undefined; }, [gridApi]);
5104
5138
  var getColumns = useCallback(function () { var _a; return (_a = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDefs()) !== null && _a !== void 0 ? _a : []; }, [gridApi]);
5105
5139
  useEffect(function () {
5106
5140
  if (columnApi) {
@@ -5123,6 +5157,7 @@ var GridContextProvider = function (props) {
5123
5157
  gridApi.exportDataAsCsv(__assign(__assign({ columnKeys: columnKeys, processCellCallback: downloadCsvUseValueFormattersProcessCellCallback }, csvExportParams), { fileName: fileName }));
5124
5158
  }, [columnApi, gridApi]);
5125
5159
  return (jsx(GridContext.Provider, __assign({ value: {
5160
+ getColDef: getColDef,
5126
5161
  getColumns: getColumns,
5127
5162
  invisibleColumnIds: invisibleColumnIds,
5128
5163
  setInvisibleColumnIds: setInvisibleColumnIds,
@@ -5147,6 +5182,7 @@ var GridContextProvider = function (props) {
5147
5182
  ensureSelectedRowIsVisible: ensureSelectedRowIsVisible,
5148
5183
  sizeColumnsToFit: sizeColumnsToFit,
5149
5184
  autoSizeColumns: autoSizeColumns,
5185
+ startCellEditing: startCellEditing,
5150
5186
  stopEditing: stopEditing,
5151
5187
  cancelEdit: cancelEdit,
5152
5188
  updatingCells: updatingCells,
@@ -5222,7 +5258,7 @@ var GridUpdatingContextProvider = function (props) {
5222
5258
  updating.current = mergedUpdatingBlocks;
5223
5259
  setUpdatedDep(function (updatedDep) { return updatedDep + 1; });
5224
5260
  };
5225
- var isUpdating = function () { return !isEmpty(updating.current); };
5261
+ var updatingCols = function () { return Object.keys(updating.current); };
5226
5262
  var modifyUpdating = function (fields, ids, fn) { return __awaiter(void 0, void 0, void 0, function () {
5227
5263
  var idRef;
5228
5264
  return __generator(this, function (_a) {
@@ -5250,7 +5286,7 @@ var GridUpdatingContextProvider = function (props) {
5250
5286
  var checkUpdating = function (fields, id) {
5251
5287
  return castArray(fields).some(function (f) { var _a; return (_a = updating.current[f]) === null || _a === void 0 ? void 0 : _a.includes(id); });
5252
5288
  };
5253
- return (jsx(GridUpdatingContext.Provider, __assign({ value: { modifyUpdating: modifyUpdating, checkUpdating: checkUpdating, isUpdating: isUpdating, updatedDep: updatedDep } }, { children: props.children })));
5289
+ return (jsx(GridUpdatingContext.Provider, __assign({ value: { modifyUpdating: modifyUpdating, checkUpdating: checkUpdating, updatingCols: updatingCols, updatedDep: updatedDep } }, { children: props.children })));
5254
5290
  };
5255
5291
 
5256
5292
  var css_248z = ".ActionButton{align-items:center;display:flex}.ActionButton-minimal.lui-button-lg.lui-button-icon-right{padding-right:38px}.ActionButton.lui-button-lg.lui-button-icon-right:not(.ActionButton-tight) .LuiIcon{margin:0 4px}.ActionButton.ActionButton-tight.lui-button-lg.lui-button-icon-right .LuiIcon{margin:0}.ActionButton-iconOnly.lui-button-lg.lui-button-icon-right:not(.ActionButton-tight){padding:8px 5px}.ActionButton-iconOnly.lui-button-lg.lui-button-icon-right.ActionButton-tight{padding:0}.ActionButton-minimalArea{position:relative}.ActionButton-minimalAreaDisplay{position:absolute}.ActionButton-minimalAreaExpand{visibility:hidden}.ActionButton-inProgress.lui-button-lg.lui-button-icon-right{background-color:#e2f3f7;color:#007198;cursor:progress}.ActionButton-inProgress.lui-button-lg.lui-button-icon-right svg *{fill:#0000}.ActionButton-fill{justify-content:center;width:100%}";