@linzjs/step-ag-grid 8.2.1 → 8.2.2

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "8.2.1",
5
+ "version": "8.2.2",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -46,6 +46,7 @@ export const Grid = (params: GridProps): JSX.Element => {
46
46
  const {
47
47
  gridReady,
48
48
  setGridApi,
49
+ prePopupOps,
49
50
  setQuickFilter,
50
51
  ensureRowVisible,
51
52
  selectRowsById,
@@ -241,6 +242,7 @@ export const Grid = (params: GridProps): JSX.Element => {
241
242
 
242
243
  const startCellEditing = useCallback(
243
244
  (event: CellEvent) => {
245
+ prePopupOps();
244
246
  if (!event.node.isSelected()) {
245
247
  event.node.setSelected(true, true);
246
248
  }
@@ -256,7 +258,7 @@ export const Grid = (params: GridProps): JSX.Element => {
256
258
  });
257
259
  }
258
260
  },
259
- [checkUpdating],
261
+ [checkUpdating, prePopupOps],
260
262
  );
261
263
 
262
264
  const onCellDoubleClick = useCallback(
@@ -5,6 +5,7 @@ import { GridBaseRow } from "../components/Grid";
5
5
  export interface GridContextType {
6
6
  gridReady: boolean;
7
7
  setGridApi: (gridApi: GridApi | undefined) => void;
8
+ prePopupOps: () => void;
8
9
  setQuickFilter: (quickFilter: string) => void;
9
10
  editingCells: () => boolean;
10
11
  getSelectedRows: <T extends GridBaseRow>() => T[];
@@ -34,6 +35,9 @@ export interface GridContextType {
34
35
 
35
36
  export const GridContext = createContext<GridContextType>({
36
37
  gridReady: false,
38
+ prePopupOps: () => {
39
+ console.error("no context provider for prePopupOps");
40
+ },
37
41
  externallySelectedItemsAreInSync: false,
38
42
  setGridApi: () => {
39
43
  console.error("no context provider for setGridApi");
@@ -5,6 +5,7 @@ import { defer, delay, difference, isEmpty, last, sortBy } from "lodash-es";
5
5
  import { isNotEmpty, wait } from "../utils/util";
6
6
  import { GridUpdatingContext } from "./GridUpdatingContext";
7
7
  import { GridBaseRow } from "../components/Grid";
8
+ import { CellPosition } from "ag-grid-community/dist/lib/entities/cellPosition";
8
9
 
9
10
  interface GridContextProps {
10
11
  children: ReactNode;
@@ -20,6 +21,7 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
20
21
  const [gridApi, _setGridApi] = useState<GridApi>();
21
22
  const [gridReady, setGridReady] = useState(false);
22
23
  const idsBeforeUpdate = useRef<number[]>([]);
24
+ const prePopupFocusedCell = useRef<CellPosition>();
23
25
  const [externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync] = useState(false);
24
26
 
25
27
  const setGridApi = useCallback((gridApi: GridApi | undefined) => {
@@ -43,6 +45,13 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
43
45
  [gridApi],
44
46
  );
45
47
 
48
+ /**
49
+ * Before a popup record the currently focused cell.
50
+ */
51
+ const prePopupOps = useCallback(() => {
52
+ prePopupFocusedCell.current = gridApi?.getFocusedCell() ?? undefined;
53
+ }, [gridApi]);
54
+
46
55
  /**
47
56
  * Set the quick filter value to grid.
48
57
  */
@@ -276,7 +285,12 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
276
285
  });
277
286
  }, [gridApiOp]);
278
287
 
279
- const stopEditing = useCallback((): void => gridApiOp((gridApi) => gridApi.stopEditing()), [gridApiOp]);
288
+ const stopEditing = useCallback((): void => {
289
+ if (prePopupFocusedCell.current) {
290
+ gridApi?.setFocusedCell(prePopupFocusedCell.current.rowIndex, prePopupFocusedCell.current.column);
291
+ }
292
+ gridApiOp((gridApi) => gridApi.stopEditing());
293
+ }, [gridApi, gridApiOp]);
280
294
 
281
295
  const selectNextCell = useCallback(
282
296
  (tabDirection: -1 | 0 | 1 = 0) => {
@@ -297,8 +311,6 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
297
311
  ): Promise<boolean> => {
298
312
  setSaving && setSaving(true);
299
313
  return await gridApiOp(async (gridApi) => {
300
- const preOpCell = gridApi.getFocusedCell();
301
-
302
314
  const selectedRows = props.selectedRows;
303
315
 
304
316
  let ok = false;
@@ -331,13 +343,13 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
331
343
  }
332
344
 
333
345
  // Only focus next cell if user hasn't already manually changed focus
334
- const postOpCell = gridApi.getFocusedCell();
346
+ const postPopupFocusedCell = gridApi.getFocusedCell();
335
347
  if (
336
348
  tabDirection &&
337
- preOpCell &&
338
- postOpCell &&
339
- preOpCell.rowIndex == postOpCell.rowIndex &&
340
- preOpCell.column.getColId() == postOpCell.column.getColId()
349
+ prePopupFocusedCell.current &&
350
+ postPopupFocusedCell &&
351
+ prePopupFocusedCell.current.rowIndex == postPopupFocusedCell.rowIndex &&
352
+ prePopupFocusedCell.current.column.getColId() == postPopupFocusedCell.column.getColId()
341
353
  ) {
342
354
  selectNextCell(tabDirection);
343
355
  }
@@ -368,6 +380,7 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
368
380
  <GridContext.Provider
369
381
  value={{
370
382
  gridReady,
383
+ prePopupOps,
371
384
  setGridApi,
372
385
  setQuickFilter,
373
386
  selectRowsById,