@linzjs/step-ag-grid 28.1.0 → 28.1.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": "28.1.0",
5
+ "version": "28.1.2",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -36,6 +36,36 @@ import { usePostSortRowsHook } from './PostSortRowsHook';
36
36
 
37
37
  ModuleRegistry.registerModules([AllCommunityModule]);
38
38
 
39
+ let timeOfLastSingleClick = 0;
40
+ let lastClickColId: unknown;
41
+ let lastClickRowIndex: unknown;
42
+
43
+ const resetClickDebounce = () => {
44
+ timeOfLastSingleClick = 0;
45
+ lastClickColId = '';
46
+ lastClickRowIndex = -1;
47
+ };
48
+
49
+ /**
50
+ * If click is more than 200ms since last click return true.
51
+ */
52
+ const clickDebounceSkipClick = (colId: unknown, rowIndex: unknown): boolean => {
53
+ const doubleClickMs = 200;
54
+
55
+ if (
56
+ Date.now() - timeOfLastSingleClick < doubleClickMs &&
57
+ lastClickColId === colId &&
58
+ lastClickRowIndex === rowIndex
59
+ ) {
60
+ // Skipping double click due to single click edit
61
+ return true;
62
+ }
63
+ timeOfLastSingleClick = Date.now();
64
+ lastClickColId = colId;
65
+ lastClickRowIndex = rowIndex;
66
+ return false;
67
+ };
68
+
39
69
  export interface GridBaseRow {
40
70
  id: string | number;
41
71
  }
@@ -425,6 +455,11 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
425
455
  */
426
456
  const onCellDoubleClick = useCallback(
427
457
  (event: CellDoubleClickedEvent) => {
458
+ if (clickDebounceSkipClick(event.colDef.colId, event.rowIndex)) {
459
+ // the next click will be a single click, we want it to pass
460
+ resetClickDebounce();
461
+ return;
462
+ }
428
463
  const editable = fnOrVar(event.colDef?.editable, event);
429
464
  if (editable && !invokeEditAction(event)) {
430
465
  void startCellEditing({ rowId: event.data.id, colId: event.column.getColId() });
@@ -440,6 +475,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
440
475
  (event: CellClickedEvent) => {
441
476
  const editable = fnOrVar(event.colDef?.editable, event);
442
477
  if ((editable && event.colDef.singleClickEdit) ?? singleClickEdit) {
478
+ if (clickDebounceSkipClick(event.colDef.colId, event.rowIndex)) {
479
+ return;
480
+ }
443
481
  void startCellEditing({ rowId: event.data.id, colId: event.column.getColId() });
444
482
  }
445
483
  },
@@ -135,8 +135,13 @@ export const findCellContains = async (
135
135
  };
136
136
 
137
137
  export const selectCell = async (rowId: string | number, colId: string, within?: HTMLElement): Promise<void> => {
138
- const cell = await findCell(rowId, colId, within);
139
- await user.click(cell);
138
+ await waitFor(
139
+ async () => {
140
+ const cell = await findCell(rowId, colId, within);
141
+ await user.click(cell);
142
+ },
143
+ { timeout: 10000 },
144
+ );
140
145
  };
141
146
 
142
147
  export const editCell = async (rowId: number | string, colId: string, within?: HTMLElement): Promise<void> => {
@@ -200,7 +205,7 @@ export const openAndClickMenuOption = async (
200
205
  menuOptionText: string | RegExp,
201
206
  within?: HTMLElement,
202
207
  ): Promise<void> => {
203
- await editCell(rowId, colId, within);
208
+ await selectCell(rowId, colId, within);
204
209
  await clickMenuOption(menuOptionText);
205
210
  };
206
211