@linzjs/step-ag-grid 8.2.0 → 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.0",
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(
@@ -297,16 +299,6 @@ export const Grid = (params: GridProps): JSX.Element => {
297
299
  [startCellEditing],
298
300
  );
299
301
 
300
- const onCellEditingStopped = useCallback(
301
- (event: CellEvent) => {
302
- refreshSelectedRows(event);
303
- // The grid loses cell focus after editing
304
- const cell = event.api.getFocusedCell();
305
- cell && event.api.setFocusedCell(cell.rowIndex, cell.column);
306
- },
307
- [refreshSelectedRows],
308
- );
309
-
310
302
  // When rows added or removed then resize columns
311
303
  useEffect(() => {
312
304
  if (columnDefs?.length) {
@@ -354,7 +346,6 @@ export const Grid = (params: GridProps): JSX.Element => {
354
346
  onCellClicked={onCellClicked}
355
347
  onCellDoubleClicked={onCellDoubleClick}
356
348
  onCellEditingStarted={refreshSelectedRows}
357
- onCellEditingStopped={onCellEditingStopped}
358
349
  domLayout={params.domLayout}
359
350
  columnDefs={columnDefs}
360
351
  rowData={params.rowData}
@@ -95,6 +95,8 @@ export const GridFormPopoverMenu = <RowType extends GridBaseRow>(props: GridForm
95
95
  setSubComponentSelected(subComponentSelected === item ? null : item);
96
96
  e.keepOpen = true;
97
97
  } else {
98
+ subComponentIsValid.current = true;
99
+ setSubSelectedValue(null);
98
100
  await updateValue(async () => actionClick(item), e.key === "Tab" ? (e.shiftKey ? -1 : 1) : 0);
99
101
  }
100
102
  },
@@ -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,
@@ -120,6 +120,10 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
120
120
  {
121
121
  multiEdit: true,
122
122
  editorParams: {
123
+ defaultAction: async ({ menuOption }) => {
124
+ // eslint-disable-next-line no-console
125
+ console.log("clicked", { menuOption });
126
+ },
123
127
  options: async (selectedItems) => {
124
128
  // Just doing a timeout here to demonstrate deferred loading
125
129
  await wait(500);
@@ -22,7 +22,7 @@ const Template: ComponentStory<typeof GridFormMultiSelect> = (props) => {
22
22
  "With options",
23
23
  {
24
24
  options: [
25
- { label: "One", value: 0 },
25
+ { label: "One", value: 0, checked: true },
26
26
  { label: "Two", value: 1 },
27
27
  ],
28
28
  },
@@ -34,7 +34,7 @@ const Template: ComponentStory<typeof GridFormMultiSelect> = (props) => {
34
34
  options: [
35
35
  { label: "One", value: 0 },
36
36
  { label: "With warning", value: 1, warning: "Test warning" },
37
- { label: "Three", value: 2 },
37
+ { label: "Three", value: 2, checked: true },
38
38
  ],
39
39
  },
40
40
  ],