@linzjs/step-ag-grid 29.1.1 → 29.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": "29.1.1",
5
+ "version": "29.1.2",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -20,8 +20,13 @@ export interface GridPopoverHookProps<TData> {
20
20
  dontSaveOnExternalClick?: boolean;
21
21
  }
22
22
 
23
- export const useGridPopoverHook = <TData extends GridBaseRow>(props: GridPopoverHookProps<TData>) => {
24
- const { onBulkEditingComplete } = useGridContext<TData>();
23
+ export const useGridPopoverHook = <TData extends GridBaseRow>({
24
+ className,
25
+ save,
26
+ invalid,
27
+ dontSaveOnExternalClick,
28
+ }: GridPopoverHookProps<TData>) => {
29
+ const { onBulkEditingComplete, redrawRows } = useGridContext<TData>();
25
30
  const { anchorRef, saving, updateValue, stopEditing } = useGridPopoverContext<TData>();
26
31
  const saveButtonRef = useRef<HTMLButtonElement>(null);
27
32
  const [isOpen, setOpen] = useState(false);
@@ -35,30 +40,30 @@ export const useGridPopoverHook = <TData extends GridBaseRow>(props: GridPopover
35
40
  if (reason == CloseReason.CANCEL) {
36
41
  stopEditing();
37
42
  onBulkEditingComplete();
43
+ redrawRows();
38
44
  return;
39
45
  }
40
- if (props?.invalid?.()) {
46
+ if (invalid?.()) {
41
47
  // Don't close, don't do anything it's invalid
42
48
  return;
43
49
  }
44
50
 
45
- if (!props.save) {
51
+ if (!save) {
46
52
  // No save method so just close
47
53
  stopEditing();
48
54
  onBulkEditingComplete();
55
+ redrawRows();
49
56
  return;
50
57
  }
51
58
 
52
59
  if (
53
- await updateValue(
54
- props.save,
55
- reason === CloseReason.TAB_FORWARD ? 1 : reason === CloseReason.TAB_BACKWARD ? -1 : 0,
56
- )
60
+ await updateValue(save, reason === CloseReason.TAB_FORWARD ? 1 : reason === CloseReason.TAB_BACKWARD ? -1 : 0)
57
61
  ) {
58
62
  stopEditing();
63
+ redrawRows();
59
64
  }
60
65
  },
61
- [onBulkEditingComplete, props, stopEditing, updateValue],
66
+ [invalid, onBulkEditingComplete, redrawRows, save, stopEditing, updateValue],
62
67
  );
63
68
 
64
69
  const popoverWrapper = useCallback(
@@ -82,7 +87,7 @@ export const useGridPopoverHook = <TData extends GridBaseRow>(props: GridPopover
82
87
  }}
83
88
  viewScroll={'auto'}
84
89
  dontShrinkIfDirectionIsTop={true}
85
- className={props.className}
90
+ className={className}
86
91
  >
87
92
  {saving && ( // This is the overlay that prevents editing when the editor is saving
88
93
  <div className={'ComponentLoadingWrapper-saveOverlay'} />
@@ -93,7 +98,7 @@ export const useGridPopoverHook = <TData extends GridBaseRow>(props: GridPopover
93
98
  data-reason={''}
94
99
  onClick={(e) => {
95
100
  let reason = e.currentTarget.getAttribute('data-reason') ?? undefined;
96
- if (props.dontSaveOnExternalClick && reason === CloseReason.BLUR) {
101
+ if (dontSaveOnExternalClick && reason === CloseReason.BLUR) {
97
102
  reason = CloseReason.CANCEL;
98
103
  }
99
104
  void triggerSave(reason);
@@ -105,7 +110,7 @@ export const useGridPopoverHook = <TData extends GridBaseRow>(props: GridPopover
105
110
  </>
106
111
  );
107
112
  },
108
- [anchorRef, isOpen, props.className, props.dontSaveOnExternalClick, saving, triggerSave],
113
+ [anchorRef, isOpen, className, dontSaveOnExternalClick, saving, triggerSave],
109
114
  );
110
115
 
111
116
  return {
@@ -1,5 +1,12 @@
1
- import { CellPosition, ColDef, GridApi, IRowNode, RowNode } from 'ag-grid-community';
2
- import { CsvExportParams, ProcessCellForExportParams } from 'ag-grid-community';
1
+ import {
2
+ CellPosition,
3
+ ColDef,
4
+ CsvExportParams,
5
+ GridApi,
6
+ IRowNode,
7
+ ProcessCellForExportParams,
8
+ RowNode,
9
+ } from 'ag-grid-community';
3
10
  import debounce from 'debounce-promise';
4
11
  import { compact, defer, delay, difference, filter, isEmpty, last, pull, remove, sortBy, sumBy } from 'lodash-es';
5
12
  import { PropsWithChildren, ReactElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
@@ -8,6 +15,7 @@ import { ColDefT, GridBaseRow } from '../components';
8
15
  import { GridCellFillerColId, isGridCellFiller } from '../components/GridCellFiller';
9
16
  import { getColId, isFlexColumn } from '../components/gridUtil';
10
17
  import { fnOrVar, isNotEmpty, sanitiseFileName, wait } from '../utils/util';
18
+ import { waitForCondition } from '../utils/waitForCondition';
11
19
  import { AutoSizeColumnsProps, AutoSizeColumnsResult, GridContext, GridFilterExternal } from './GridContext';
12
20
  import { GridUpdatingContext } from './GridUpdatingContext';
13
21
 
@@ -909,15 +917,3 @@ export const downloadCsvUseValueFormattersProcessCellCallback = (params: Process
909
917
  // We add an extra encodeToString here just in case valueFormatter is returning non string values
910
918
  return encodeToString(result);
911
919
  };
912
-
913
- const waitForCondition = async (condition: () => boolean, timeoutMs: number): Promise<boolean> => {
914
- const endTime = Date.now() + timeoutMs;
915
- while (Date.now() < endTime) {
916
- if (condition()) {
917
- return true;
918
- }
919
- await wait(100);
920
- }
921
- console.warn('waitForCondition failed');
922
- return false;
923
- };
package/src/index.ts CHANGED
@@ -17,3 +17,4 @@ export * from './utils/deferredPromise';
17
17
  export * from './utils/textMatcher';
18
18
  export * from './utils/textValidator';
19
19
  export * from './utils/util';
20
+ export * from './utils/waitForCondition';
@@ -10,8 +10,7 @@ import { expect, fn, userEvent, within } from 'storybook/test';
10
10
 
11
11
  import {
12
12
  GridBaseRow,
13
- GridContext,
14
- GridContextType,
13
+ GridContextProvider,
15
14
  GridFormDropDown,
16
15
  GridFormDropDownProps,
17
16
  GridFormSubComponentTextInput,
@@ -51,14 +50,7 @@ const Template: StoryFn<typeof GridFormDropDown<GridBaseRow, number>> = (
51
50
 
52
51
  return (
53
52
  <div className={'react-menu-inline-test'}>
54
- <GridContext.Provider
55
- value={
56
- {
57
- onBulkEditingComplete: () => {},
58
- resetFocusedCellAfterCellEditing: () => {},
59
- } as unknown as GridContextType<GridBaseRow>
60
- }
61
- >
53
+ <GridContextProvider>
62
54
  <h6 ref={anchorRef}>Interaction test</h6>
63
55
  <GridPopoverContext.Provider
64
56
  value={{
@@ -77,7 +69,7 @@ const Template: StoryFn<typeof GridFormDropDown<GridBaseRow, number>> = (
77
69
  >
78
70
  <GridFormDropDown {...props} {...config} />
79
71
  </GridPopoverContext.Provider>
80
- </GridContext.Provider>
72
+ </GridContextProvider>
81
73
  </div>
82
74
  );
83
75
  };
@@ -9,7 +9,7 @@ import { useRef } from 'react';
9
9
  import { expect, fn, userEvent, within } from 'storybook/test';
10
10
 
11
11
  import {
12
- GridContext,
12
+ GridContextProvider,
13
13
  GridFormEditBearing,
14
14
  GridFormEditBearingProps,
15
15
  GridPopoverEditBearingCorrectionEditorParams,
@@ -28,14 +28,7 @@ const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearin
28
28
 
29
29
  return (
30
30
  <div className={'react-menu-inline-test'}>
31
- <GridContext.Provider
32
- value={
33
- {
34
- onBulkEditingComplete: () => {},
35
- resetFocusedCellAfterCellEditing: () => {},
36
- } as any
37
- }
38
- >
31
+ <GridContextProvider>
39
32
  <h6 ref={anchorRef}>Interaction Test</h6>
40
33
  <GridPopoverContext.Provider
41
34
  value={{
@@ -54,7 +47,7 @@ const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearin
54
47
  >
55
48
  <GridFormEditBearing {...props} {...GridPopoverEditBearingCorrectionEditorParams} />
56
49
  </GridPopoverContext.Provider>
57
- </GridContext.Provider>
50
+ </GridContextProvider>
58
51
  </div>
59
52
  );
60
53
  };
@@ -9,7 +9,7 @@ import { useRef } from 'react';
9
9
  import { expect, fn, userEvent, within } from 'storybook/test';
10
10
 
11
11
  import {
12
- GridContext,
12
+ GridContextProvider,
13
13
  GridFormEditBearing,
14
14
  GridFormEditBearingProps,
15
15
  GridPopoverEditBearingEditorParams,
@@ -28,14 +28,7 @@ const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearin
28
28
 
29
29
  return (
30
30
  <div className={'react-menu-inline-test'}>
31
- <GridContext.Provider
32
- value={
33
- {
34
- onBulkEditingComplete: () => {},
35
- resetFocusedCellAfterCellEditing: () => {},
36
- } as any
37
- }
38
- >
31
+ <GridContextProvider>
39
32
  <h6 ref={anchorRef}>Interaction Test</h6>
40
33
  <GridPopoverContext.Provider
41
34
  value={{
@@ -54,7 +47,7 @@ const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearin
54
47
  >
55
48
  <GridFormEditBearing {...props} {...GridPopoverEditBearingEditorParams} />
56
49
  </GridPopoverContext.Provider>
57
- </GridContext.Provider>
50
+ </GridContextProvider>
58
51
  </div>
59
52
  );
60
53
  };
@@ -8,7 +8,12 @@ import { GridPopoverContext } from 'contexts/GridPopoverContext';
8
8
  import { useRef } from 'react';
9
9
  import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
10
10
 
11
- import { GridContext, GridFormMultiSelectGrid, GridFormMultiSelectGridProps, MultiSelectGridOption } from '../../..';
11
+ import {
12
+ GridContextProvider,
13
+ GridFormMultiSelectGrid,
14
+ GridFormMultiSelectGridProps,
15
+ MultiSelectGridOption,
16
+ } from '../../..';
12
17
 
13
18
  export default {
14
19
  title: 'GridForm / Interactions',
@@ -42,14 +47,7 @@ const Template: StoryFn<typeof GridFormMultiSelectGrid> = (props: GridFormMultiS
42
47
 
43
48
  return (
44
49
  <div className={'react-menu-inline-test'}>
45
- <GridContext.Provider
46
- value={
47
- {
48
- onBulkEditingComplete: () => {},
49
- resetFocusedCellAfterCellEditing: () => {},
50
- } as any
51
- }
52
- >
50
+ <GridContextProvider>
53
51
  <h6 ref={anchorRef}>Interaction test</h6>
54
52
  <GridPopoverContext.Provider
55
53
  value={{
@@ -68,7 +66,7 @@ const Template: StoryFn<typeof GridFormMultiSelectGrid> = (props: GridFormMultiS
68
66
  >
69
67
  <GridFormMultiSelectGrid {...props} {...config} />
70
68
  </GridPopoverContext.Provider>
71
- </GridContext.Provider>
69
+ </GridContextProvider>
72
70
  </div>
73
71
  );
74
72
  };
@@ -9,7 +9,7 @@ import { useRef } from 'react';
9
9
  import { expect, fn, userEvent, within } from 'storybook/test';
10
10
 
11
11
  import {
12
- GridContext,
12
+ GridContextProvider,
13
13
  GridFormMultiSelect,
14
14
  GridFormMultiSelectProps,
15
15
  GridFormSubComponentTextInput,
@@ -53,14 +53,7 @@ const Template: StoryFn<typeof GridFormMultiSelect> = (props: GridFormMultiSelec
53
53
 
54
54
  return (
55
55
  <div className={'react-menu-inline-test'}>
56
- <GridContext.Provider
57
- value={
58
- {
59
- onBulkEditingComplete: () => {},
60
- resetFocusedCellAfterCellEditing: () => {},
61
- } as any
62
- }
63
- >
56
+ <GridContextProvider>
64
57
  <h6 ref={anchorRef}>Interaction test</h6>
65
58
  <GridPopoverContext.Provider
66
59
  value={{
@@ -79,7 +72,7 @@ const Template: StoryFn<typeof GridFormMultiSelect> = (props: GridFormMultiSelec
79
72
  >
80
73
  <GridFormMultiSelect {...props} {...config} />
81
74
  </GridPopoverContext.Provider>
82
- </GridContext.Provider>
75
+ </GridContextProvider>
83
76
  </div>
84
77
  );
85
78
  };
@@ -10,7 +10,7 @@ import * as test from 'storybook/test';
10
10
  import { expect, userEvent, within } from 'storybook/test';
11
11
 
12
12
  import {
13
- GridContext,
13
+ GridContextProvider,
14
14
  GridFormPopoverMenu,
15
15
  GridFormPopoverMenuProps,
16
16
  GridFormSubComponentTextArea,
@@ -37,14 +37,7 @@ const Template: StoryFn<typeof GridFormPopoverMenu> = (props: GridFormPopoverMen
37
37
 
38
38
  return (
39
39
  <div className={'react-menu-inline-test'}>
40
- <GridContext.Provider
41
- value={
42
- {
43
- onBulkEditingComplete: () => {},
44
- resetFocusedCellAfterCellEditing: () => {},
45
- } as any
46
- }
47
- >
40
+ <GridContextProvider>
48
41
  <h6 ref={anchorRef}>Interaction Test</h6>
49
42
  <GridPopoverContext.Provider
50
43
  value={{
@@ -85,7 +78,7 @@ const Template: StoryFn<typeof GridFormPopoverMenu> = (props: GridFormPopoverMen
85
78
  ]}
86
79
  />
87
80
  </GridPopoverContext.Provider>
88
- </GridContext.Provider>
81
+ </GridContextProvider>
89
82
  </div>
90
83
  );
91
84
  };
@@ -8,7 +8,7 @@ import { GridPopoverContext } from 'contexts/GridPopoverContext';
8
8
  import { useRef } from 'react';
9
9
  import { expect, fn, userEvent, within } from 'storybook/test';
10
10
 
11
- import { GridContext, GridFormTextArea, GridFormTextAreaProps } from '../../..';
11
+ import { GridContextProvider, GridFormTextArea, GridFormTextAreaProps } from '../../..';
12
12
 
13
13
  export default {
14
14
  title: 'GridForm / Interactions',
@@ -23,14 +23,7 @@ const Template: StoryFn<typeof GridFormTextArea> = (props: GridFormTextAreaProps
23
23
 
24
24
  return (
25
25
  <div className={'react-menu-inline-test'}>
26
- <GridContext.Provider
27
- value={
28
- {
29
- onBulkEditingComplete: () => {},
30
- resetFocusedCellAfterCellEditing: () => {},
31
- } as any
32
- }
33
- >
26
+ <GridContextProvider>
34
27
  <h6 ref={anchorRef}>Interaction Test</h6>
35
28
  <GridPopoverContext.Provider
36
29
  value={{
@@ -49,7 +42,7 @@ const Template: StoryFn<typeof GridFormTextArea> = (props: GridFormTextAreaProps
49
42
  >
50
43
  <GridFormTextArea {...props} required={true} />
51
44
  </GridPopoverContext.Provider>
52
- </GridContext.Provider>
45
+ </GridContextProvider>
53
46
  </div>
54
47
  );
55
48
  };
@@ -8,7 +8,7 @@ import { GridPopoverContext } from 'contexts/GridPopoverContext';
8
8
  import { useRef } from 'react';
9
9
  import { expect, fn, userEvent, within } from 'storybook/test';
10
10
 
11
- import { GridContext, GridFormTextInput, GridFormTextInputProps } from '../../..';
11
+ import { GridContextProvider, GridFormTextInput, GridFormTextInputProps } from '../../..';
12
12
 
13
13
  export default {
14
14
  title: 'GridForm / Interactions',
@@ -23,14 +23,7 @@ const Template: StoryFn<typeof GridFormTextInput> = (props: GridFormTextInputPro
23
23
 
24
24
  return (
25
25
  <div className={'react-menu-inline-test'}>
26
- <GridContext.Provider
27
- value={
28
- {
29
- onBulkEditingComplete: () => {},
30
- resetFocusedCellAfterCellEditing: () => {},
31
- } as any
32
- }
33
- >
26
+ <GridContextProvider>
34
27
  <h6 ref={anchorRef}>Interaction Test</h6>
35
28
  <GridPopoverContext.Provider
36
29
  value={{
@@ -49,7 +42,7 @@ const Template: StoryFn<typeof GridFormTextInput> = (props: GridFormTextInputPro
49
42
  >
50
43
  <GridFormTextInput {...props} required={true} />
51
44
  </GridPopoverContext.Provider>
52
- </GridContext.Provider>
45
+ </GridContextProvider>
53
46
  </div>
54
47
  );
55
48
  };
@@ -0,0 +1,13 @@
1
+ import { wait } from '../utils/util';
2
+
3
+ export const waitForCondition = async (condition: () => boolean, timeoutMs: number): Promise<boolean> => {
4
+ const endTime = Date.now() + timeoutMs;
5
+ while (Date.now() < endTime) {
6
+ if (condition()) {
7
+ return true;
8
+ }
9
+ await wait(100);
10
+ }
11
+ console.warn('waitForCondition failed');
12
+ return false;
13
+ };