@linzjs/step-ag-grid 29.1.4 → 29.1.5

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.4",
5
+ "version": "29.1.5",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -110,6 +110,5 @@ export const useGridPopoverHook = <TData extends GridBaseRow>({
110
110
  return {
111
111
  popoverWrapper,
112
112
  triggerSave,
113
- gridPopoverOpen: isOpen,
114
113
  };
115
114
  };
@@ -1,5 +1,5 @@
1
1
  import debounce from 'debounce-promise';
2
- import { isEmpty } from 'lodash-es';
2
+ import { compact, isEmpty } from 'lodash-es';
3
3
  import { Fragment, ReactElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
 
5
5
  import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
@@ -90,7 +90,9 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
90
90
  // Save triggers during async action processing which triggers another selectItem(), this ref blocks that
91
91
  const [filter, setFilter] = useState(props.filterDefaultValue ?? '');
92
92
  const [filteredValues, setFilteredValues] = useState<any[]>();
93
- const [options, setOptions] = useState<FinalSelectOption<TOptionValue>[] | null>(null);
93
+ const [options, setOptions] = useState<FinalSelectOption<TOptionValue>[] | null>(
94
+ !!propOptions && typeof propOptions !== 'function' ? propOptions : null,
95
+ );
94
96
  const subComponentIsValid = useRef(false);
95
97
  const subComponentInitialValue = useRef<string | null>(null);
96
98
  const [subSelectedValue, setSubSelectedValue] = useState<any>(null);
@@ -164,7 +166,7 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
164
166
  subSelectedValue,
165
167
  ]);
166
168
 
167
- const { popoverWrapper, gridPopoverOpen } = useGridPopoverHook({
169
+ const { popoverWrapper } = useGridPopoverHook({
168
170
  className: props.className,
169
171
  invalid: () => !options || !!(selectedItem && !subComponentIsValid.current),
170
172
  save,
@@ -172,39 +174,49 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
172
174
  });
173
175
 
174
176
  // Load up options list if it's async function
175
- const prevIsOpen = usePrevious(gridPopoverOpen);
176
- const prevFilter = usePrevious(filter);
177
177
  useEffect(() => {
178
- if ((gridPopoverOpen !== prevIsOpen || filter !== prevFilter) && gridPopoverOpen) {
179
- let optionsConf = propOptions;
178
+ // If options is null then we need to load/reload
179
+ // Options will be set to null during a reload based filter, or on open popup
180
+ if (options !== null) {
181
+ return;
182
+ }
180
183
 
181
- void (async () => {
182
- if (typeof optionsConf === 'function') {
183
- optionsConf = await optionsConf(selectedRows, filter);
184
- }
185
- if (optionsConf !== undefined) {
186
- setOptions(optionsConf);
187
- }
188
- })();
184
+ // propOptions is a const list
185
+ if (typeof propOptions !== 'function') {
186
+ if (propOptions) {
187
+ setOptions(propOptions);
188
+ }
189
+ return;
189
190
  }
190
- }, [filter, gridPopoverOpen, options, prevFilter, prevIsOpen, propOptions, selectedRows]);
191
+
192
+ // propOptions is function, probably loading from web
193
+ void (async () => {
194
+ const r = await propOptions(selectedRows, filter);
195
+ setOptions(r ?? []);
196
+ })();
197
+ }, [filter, options, propOptions, selectedRows]);
191
198
 
192
199
  // Local filtering.
193
200
  useEffect(() => {
194
- if (props.filtered == 'local') {
195
- if (options == null) return;
196
- setFilteredValues(
197
- options
198
- .map((option) => {
199
- if (option.label != null && typeof option.label !== 'string') {
200
- console.error('Cannot filter non-string labels', option);
201
- return undefined;
202
- }
203
- return textMatch((option.label as string) || '', filter) ? option : undefined;
204
- })
205
- .filter((r) => r !== undefined),
206
- );
201
+ if (props.filtered !== 'local') {
202
+ return;
203
+ }
204
+ if (options == null) {
205
+ setFilteredValues([]);
206
+ return;
207
207
  }
208
+
209
+ setFilteredValues(
210
+ compact(
211
+ options.map((option) => {
212
+ if (option.label != null && typeof option.label !== 'string') {
213
+ console.warn('GridFormDropDown: Cannot filter non-string labels', option);
214
+ return undefined;
215
+ }
216
+ return textMatch((option.label as string) || '', filter) ? option : undefined;
217
+ }),
218
+ ),
219
+ );
208
220
  }, [props.filtered, filter, options]);
209
221
 
210
222
  const reSearchOnFilterChange = useMemo(
@@ -215,15 +227,12 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
215
227
  [],
216
228
  );
217
229
 
218
- const previousFilter = useRef<string>(filter);
219
-
220
- // Reload filtering.
230
+ const previousFilter = usePrevious(filter);
221
231
  useEffect(() => {
222
- if (previousFilter.current != filter && props.filtered == 'reload') {
223
- previousFilter.current = filter;
232
+ if (previousFilter != null && previousFilter != filter && props.filtered === 'reload') {
224
233
  void reSearchOnFilterChange();
225
234
  }
226
- }, [filter, props, reSearchOnFilterChange]);
235
+ }, [filter, previousFilter, props.filtered, reSearchOnFilterChange]);
227
236
 
228
237
  let lastHeader: ReactElement | null = null;
229
238
  let showHeader: ReactElement | null = null;
@@ -9,7 +9,6 @@ import { useRef } from 'react';
9
9
  import { expect, fn, userEvent, within } from 'storybook/test';
10
10
 
11
11
  import {
12
- CancelPromise,
13
12
  GridContextProvider,
14
13
  GridFormEditBearing,
15
14
  GridFormEditBearingProps,