@linzjs/step-ag-grid 14.3.1 → 14.3.3

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;
@@ -47,7 +49,6 @@ export interface GridContextType<RowType extends GridBaseRow> {
47
49
  removeExternalFilter: (filter: GridFilterExternal<RowType>) => void;
48
50
  isExternalFilterPresent: () => boolean;
49
51
  doesExternalFilterPass: (node: RowNode) => boolean;
50
- getColumns: () => ColDefT<RowType>[];
51
52
  invisibleColumnIds: string[];
52
53
  setInvisibleColumnIds: (colIds: string[]) => void;
53
54
  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 [];
@@ -265,9 +269,9 @@ var GridUpdatingContext = createContext({
265
269
  console.error("Missing GridUpdatingContext");
266
270
  return false;
267
271
  },
268
- isUpdating: function () {
272
+ updatingCols: function () {
269
273
  console.error("Missing GridUpdatingContext");
270
- return false;
274
+ return [];
271
275
  },
272
276
  modifyUpdating: function () { return __awaiter(void 0, void 0, void 0, function () {
273
277
  return __generator(this, function (_a) {
@@ -714,8 +718,8 @@ var GridHeaderSelect = function (_a) {
714
718
  var Grid = function (_a) {
715
719
  var _b, _c, _d;
716
720
  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;
721
+ 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, getColDef = _k.getColDef;
722
+ var _l = useContext(GridUpdatingContext), checkUpdating = _l.checkUpdating, updatedDep = _l.updatedDep, updatingCols = _l.updatingCols;
719
723
  var gridDivRef = useRef(null);
720
724
  var lastSelectedIds = useRef([]);
721
725
  var _m = useState(false), staleGrid = _m[0], setStaleGrid = _m[1];
@@ -944,12 +948,12 @@ var Grid = function (_a) {
944
948
  return;
945
949
  lastUpdatedDep.current = updatedDep;
946
950
  // Don't update while there are spinners
947
- if (isUpdating())
951
+ if (!isEmpty(updatingCols()))
948
952
  return;
949
953
  var skipHeader = sizeColumns === "auto-skip-headers";
950
954
  autoSizeColumns({ skipHeader: skipHeader, userSizedColIds: userSizedColIds.current, colIds: colIdsEdited.current });
951
955
  colIdsEdited.current.clear();
952
- }, [autoSizeColumns, isUpdating, (_c = params.rowData) === null || _c === void 0 ? void 0 : _c.length, setInitialContentSize, sizeColumns, updatedDep]);
956
+ }, [autoSizeColumns, (_c = params.rowData) === null || _c === void 0 ? void 0 : _c.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
953
957
  /**
954
958
  * Show/hide no rows overlay when model changes.
955
959
  */
@@ -1050,42 +1054,40 @@ var Grid = function (_a) {
1050
1054
  * Set of colIds that need auto-sizing.
1051
1055
  */
1052
1056
  var colIdsEdited = useRef(new Set());
1057
+ var lastUpdatedDep = useRef(updatedDep);
1053
1058
  /**
1054
- * When cell editing has completed tag the colId as needing auto-sizing
1059
+ * When cell editing has completed the colId as needing auto-sizing
1055
1060
  */
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() &&
1061
+ useEffect(function () {
1062
+ if (lastUpdatedDep.current === updatedDep)
1063
+ return;
1064
+ lastUpdatedDep.current = updatedDep;
1065
+ var colIds = updatingCols();
1066
+ // Updating possibly completed
1067
+ if (isEmpty(colIds)) {
1068
+ // Columns to resize?
1069
+ if (!isEmpty(colIdsEdited.current)) {
1070
+ var skipHeader = sizeColumns === "auto-skip-headers";
1071
+ if (sizeColumns === "auto" || skipHeader) {
1066
1072
  autoSizeColumns({
1067
1073
  skipHeader: skipHeader,
1068
1074
  userSizedColIds: userSizedColIds.current,
1069
- colIds: [colId]
1075
+ colIds: colIdsEdited.current
1070
1076
  });
1077
+ }
1078
+ colIdsEdited.current.clear();
1071
1079
  }
1072
1080
  }
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]);
1081
+ else {
1082
+ // Updates not complete, add them to a list of columns needing resize
1083
+ colIds.forEach(function (colId) {
1084
+ var _a;
1085
+ if (colId && !((_a = getColDef(colId)) === null || _a === void 0 ? void 0 : _a.flex)) {
1086
+ colIdsEdited.current.add(colId);
1087
+ }
1088
+ });
1089
+ }
1090
+ }, [autoSizeColumns, getColDef, sizeColumns, updatedDep, updatingCols]);
1089
1091
  /**
1090
1092
  * Resize columns to fit if required on window/container resize
1091
1093
  */
@@ -1118,7 +1120,7 @@ var Grid = function (_a) {
1118
1120
  setOnCellEditingComplete(params.onCellEditingComplete);
1119
1121
  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
1122
  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: {
1123
+ }, 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
1124
  rowData: params.rowData,
1123
1125
  noRowsOverlayText: params.noRowsOverlayText
1124
1126
  }, 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 }) })) })));
@@ -4968,32 +4970,29 @@ var GridContextProvider = function (props) {
4968
4970
  !((_a = nextColDef.cellEditorParams) === null || _a === void 0 ? void 0 : _a.preventAutoEdit) &&
4969
4971
  !((_b = nextColDef.cellRendererParams) === null || _b === void 0 ? void 0 : _b.editAction));
4970
4972
  };
4971
- var foundEditableCell = false;
4972
4973
  // Just in case I've missed something, we don't want the loop to hang everything
4973
- var maxIterations = 50;
4974
- var preRow = null;
4975
- var postRow = null;
4976
- do {
4977
- preRow = gridApi.getFocusedCell();
4974
+ for (var maxIterations = 0; maxIterations < 50; maxIterations++) {
4975
+ var preRow = gridApi.getFocusedCell();
4978
4976
  tabDirection === 1 ? gridApi.tabToNextCell() : gridApi.tabToPreviousCell();
4979
- postRow = gridApi.getFocusedCell();
4980
- foundEditableCell = focusedCellIsEditable();
4981
- } while ((preRow === null || preRow === void 0 ? void 0 : preRow.rowIndex) === (postRow === null || postRow === void 0 ? void 0 : postRow.rowIndex) &&
4982
- (preRow === null || preRow === void 0 ? void 0 : preRow.column) !== (postRow === null || postRow === void 0 ? void 0 : postRow.column) &&
4983
- !foundEditableCell &&
4984
- maxIterations-- > 0);
4985
- if (foundEditableCell) {
4986
- prePopupOps();
4987
- var focusedCell = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getFocusedCell();
4988
- if (focusedCell) {
4989
- gridApi.startEditingCell({
4990
- rowIndex: focusedCell.rowIndex,
4991
- colKey: focusedCell.column.getColId()
4992
- });
4993
- return false;
4977
+ var postRow = gridApi.getFocusedCell();
4978
+ if ((preRow === null || preRow === void 0 ? void 0 : preRow.rowIndex) !== (postRow === null || postRow === void 0 ? void 0 : postRow.rowIndex) || (preRow === null || preRow === void 0 ? void 0 : preRow.column) === (postRow === null || postRow === void 0 ? void 0 : postRow.column)) {
4979
+ // We didn't find an editable cell in the same row, or the cell column didn't change
4980
+ // implying it was start/end of grid
4981
+ break;
4982
+ }
4983
+ if (focusedCellIsEditable()) {
4984
+ var focusedCell = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getFocusedCell();
4985
+ if (focusedCell) {
4986
+ prePopupOps();
4987
+ gridApi.startEditingCell({
4988
+ rowIndex: focusedCell.rowIndex,
4989
+ colKey: focusedCell.column.getColId()
4990
+ });
4991
+ return true;
4992
+ }
4994
4993
  }
4995
4994
  }
4996
- return true;
4995
+ return false;
4997
4996
  }, [gridApi, prePopupOps]);
4998
4997
  var updatingCells = useCallback(function (props, fnUpdate, setSaving, tabDirection) { return __awaiter(void 0, void 0, void 0, function () {
4999
4998
  return __generator(this, function (_a) {
@@ -5045,7 +5044,7 @@ var GridContextProvider = function (props) {
5045
5044
  postPopupFocusedCell &&
5046
5045
  prePopupFocusedCell.current.rowIndex == postPopupFocusedCell.rowIndex &&
5047
5046
  prePopupFocusedCell.current.column.getColId() == postPopupFocusedCell.column.getColId()) {
5048
- if (!tabDirection || selectNextEditableCell(tabDirection)) {
5047
+ if (!tabDirection || !selectNextEditableCell(tabDirection)) {
5049
5048
  cellEditingCompleteCallbackRef.current && cellEditingCompleteCallbackRef.current();
5050
5049
  }
5051
5050
  }
@@ -5104,6 +5103,7 @@ var GridContextProvider = function (props) {
5104
5103
  var doesExternalFilterPass = function (node) {
5105
5104
  return externalFilters.current.every(function (filter) { return filter(node.data, node); });
5106
5105
  };
5106
+ var getColDef = useCallback(function (colId) { return (!!colId && (gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(colId))) || undefined; }, [gridApi]);
5107
5107
  var getColumns = useCallback(function () { var _a; return (_a = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDefs()) !== null && _a !== void 0 ? _a : []; }, [gridApi]);
5108
5108
  useEffect(function () {
5109
5109
  if (columnApi) {
@@ -5126,6 +5126,7 @@ var GridContextProvider = function (props) {
5126
5126
  gridApi.exportDataAsCsv(__assign(__assign({ columnKeys: columnKeys, processCellCallback: downloadCsvUseValueFormattersProcessCellCallback }, csvExportParams), { fileName: fileName }));
5127
5127
  }, [columnApi, gridApi]);
5128
5128
  return (jsx(GridContext.Provider, __assign({ value: {
5129
+ getColDef: getColDef,
5129
5130
  getColumns: getColumns,
5130
5131
  invisibleColumnIds: invisibleColumnIds,
5131
5132
  setInvisibleColumnIds: setInvisibleColumnIds,
@@ -5225,7 +5226,7 @@ var GridUpdatingContextProvider = function (props) {
5225
5226
  updating.current = mergedUpdatingBlocks;
5226
5227
  setUpdatedDep(function (updatedDep) { return updatedDep + 1; });
5227
5228
  };
5228
- var isUpdating = function () { return !isEmpty(updating.current); };
5229
+ var updatingCols = function () { return Object.keys(updating.current); };
5229
5230
  var modifyUpdating = function (fields, ids, fn) { return __awaiter(void 0, void 0, void 0, function () {
5230
5231
  var idRef;
5231
5232
  return __generator(this, function (_a) {
@@ -5253,7 +5254,7 @@ var GridUpdatingContextProvider = function (props) {
5253
5254
  var checkUpdating = function (fields, id) {
5254
5255
  return castArray(fields).some(function (f) { var _a; return (_a = updating.current[f]) === null || _a === void 0 ? void 0 : _a.includes(id); });
5255
5256
  };
5256
- return (jsx(GridUpdatingContext.Provider, __assign({ value: { modifyUpdating: modifyUpdating, checkUpdating: checkUpdating, isUpdating: isUpdating, updatedDep: updatedDep } }, { children: props.children })));
5257
+ return (jsx(GridUpdatingContext.Provider, __assign({ value: { modifyUpdating: modifyUpdating, checkUpdating: checkUpdating, updatingCols: updatingCols, updatedDep: updatedDep } }, { children: props.children })));
5257
5258
  };
5258
5259
 
5259
5260
  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%}";