@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.
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { LuiMiniSpinner, LuiStatusSpinner, LuiIcon, LuiButtonGroup, LuiButton, LuiCheckboxInput } from '@linzjs/lui';
3
3
  import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community';
4
4
  import { AgGridReact } from 'ag-grid-react';
5
- import { negate, isEmpty, findIndex, defer, debounce as debounce$1, xorBy, last, difference, omit, sortBy, delay, partition, pick, groupBy, fromPairs, toPairs, isEqual, pull, compact, filter, sumBy, remove, flatten, castArray } from 'lodash-es';
5
+ import { negate, isEmpty, findIndex, defer, debounce as debounce$1, xorBy, last, difference, omit, sortBy, delay, partition, compact, pick, groupBy, fromPairs, toPairs, isEqual, pull, filter, sumBy, remove, flatten, castArray } from 'lodash-es';
6
6
  import React, { useRef, useLayoutEffect, useEffect, createContext, useContext, useState, useMemo, memo, forwardRef, useCallback, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1, useId } from 'react';
7
7
  import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
8
8
 
@@ -4008,7 +4008,6 @@ const useGridPopoverHook = ({ className, save, invalid, dontSaveOnExternalClick,
4008
4008
  return {
4009
4009
  popoverWrapper,
4010
4010
  triggerSave,
4011
- gridPopoverOpen: isOpen,
4012
4011
  };
4013
4012
  };
4014
4013
 
@@ -4033,7 +4032,7 @@ const GridFormDropDown = (props) => {
4033
4032
  // Save triggers during async action processing which triggers another selectItem(), this ref blocks that
4034
4033
  const [filter, setFilter] = useState(props.filterDefaultValue ?? '');
4035
4034
  const [filteredValues, setFilteredValues] = useState();
4036
- const [options, setOptions] = useState(null);
4035
+ const [options, setOptions] = useState(!!propOptions && typeof propOptions !== 'function' ? propOptions : null);
4037
4036
  const subComponentIsValid = useRef(false);
4038
4037
  const subComponentInitialValue = useRef(null);
4039
4038
  const [subSelectedValue, setSubSelectedValue] = useState(null);
@@ -4100,55 +4099,58 @@ const GridFormDropDown = (props) => {
4100
4099
  selectedRows,
4101
4100
  subSelectedValue,
4102
4101
  ]);
4103
- const { popoverWrapper, gridPopoverOpen } = useGridPopoverHook({
4102
+ const { popoverWrapper } = useGridPopoverHook({
4104
4103
  className: props.className,
4105
4104
  invalid: () => !options || !!(selectedItem && !subComponentIsValid.current),
4106
4105
  save,
4107
4106
  dontSaveOnExternalClick: true,
4108
4107
  });
4109
4108
  // Load up options list if it's async function
4110
- const prevIsOpen = usePrevious(gridPopoverOpen);
4111
- const prevFilter = usePrevious(filter);
4112
4109
  useEffect(() => {
4113
- if ((gridPopoverOpen !== prevIsOpen || filter !== prevFilter) && gridPopoverOpen) {
4114
- let optionsConf = propOptions;
4115
- void (async () => {
4116
- if (typeof optionsConf === 'function') {
4117
- optionsConf = await optionsConf(selectedRows, filter);
4118
- }
4119
- if (optionsConf !== undefined) {
4120
- setOptions(optionsConf);
4121
- }
4122
- })();
4110
+ // If options is null then we need to load/reload
4111
+ // Options will be set to null during a reload based filter, or on open popup
4112
+ if (options !== null) {
4113
+ return;
4123
4114
  }
4124
- }, [filter, gridPopoverOpen, options, prevFilter, prevIsOpen, propOptions, selectedRows]);
4115
+ // propOptions is a const list
4116
+ if (typeof propOptions !== 'function') {
4117
+ if (propOptions) {
4118
+ setOptions(propOptions);
4119
+ }
4120
+ return;
4121
+ }
4122
+ // propOptions is function, probably loading from web
4123
+ void (async () => {
4124
+ const r = await propOptions(selectedRows, filter);
4125
+ setOptions(r ?? []);
4126
+ })();
4127
+ }, [filter, options, propOptions, selectedRows]);
4125
4128
  // Local filtering.
4126
4129
  useEffect(() => {
4127
- if (props.filtered == 'local') {
4128
- if (options == null)
4129
- return;
4130
- setFilteredValues(options
4131
- .map((option) => {
4132
- if (option.label != null && typeof option.label !== 'string') {
4133
- console.error('Cannot filter non-string labels', option);
4134
- return undefined;
4135
- }
4136
- return textMatch(option.label || '', filter) ? option : undefined;
4137
- })
4138
- .filter((r) => r !== undefined));
4130
+ if (props.filtered !== 'local') {
4131
+ return;
4139
4132
  }
4133
+ if (options == null) {
4134
+ setFilteredValues([]);
4135
+ return;
4136
+ }
4137
+ setFilteredValues(compact(options.map((option) => {
4138
+ if (option.label != null && typeof option.label !== 'string') {
4139
+ console.warn('GridFormDropDown: Cannot filter non-string labels', option);
4140
+ return undefined;
4141
+ }
4142
+ return textMatch(option.label || '', filter) ? option : undefined;
4143
+ })));
4140
4144
  }, [props.filtered, filter, options]);
4141
4145
  const reSearchOnFilterChange = useMemo(() => debounce(() => {
4142
4146
  setOptions(null);
4143
4147
  }, 500), []);
4144
- const previousFilter = useRef(filter);
4145
- // Reload filtering.
4148
+ const previousFilter = usePrevious(filter);
4146
4149
  useEffect(() => {
4147
- if (previousFilter.current != filter && props.filtered == 'reload') {
4148
- previousFilter.current = filter;
4150
+ if (previousFilter != null && previousFilter != filter && props.filtered === 'reload') {
4149
4151
  void reSearchOnFilterChange();
4150
4152
  }
4151
- }, [filter, props, reSearchOnFilterChange]);
4153
+ }, [filter, previousFilter, props.filtered, reSearchOnFilterChange]);
4152
4154
  let lastHeader = null;
4153
4155
  let showHeader = null;
4154
4156
  return popoverWrapper(jsxs(Fragment, { children: [props.filtered && (jsxs("div", { className: 'GridFormDropDown-filter', children: [jsx(FocusableItem, { className: 'filter-item', onFocus: () => {