@linzjs/step-ag-grid 29.1.3 → 29.1.4

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.
@@ -3799,6 +3799,19 @@ const FormError = (props) => {
3799
3799
  return (jsxs(Fragment, { children: [props.error && (jsxs("div", { className: "FormError", children: [jsx(LuiIcon, { alt: "error", name: "ic_error", className: "FormError-text-icon", size: "sm", status: "error" }), jsx("span", { className: "FormError-error", children: props.error })] })), props.helpText && !props.error && jsx("span", { className: 'FormError-helpText', children: props.helpText })] }));
3800
3800
  };
3801
3801
 
3802
+ /**
3803
+ * Track previous values of states.
3804
+ *
3805
+ * @param value Value to track.
3806
+ */
3807
+ const usePrevious = (value) => {
3808
+ const ref = useRef();
3809
+ useEffect(() => {
3810
+ ref.current = value;
3811
+ }, [value]);
3812
+ return ref.current;
3813
+ };
3814
+
3802
3815
  function escapeStringRegexp(string) {
3803
3816
  if (typeof string !== 'string') {
3804
3817
  throw new TypeError('Expected a string');
@@ -3995,6 +4008,7 @@ const useGridPopoverHook = ({ className, save, invalid, dontSaveOnExternalClick,
3995
4008
  return {
3996
4009
  popoverWrapper,
3997
4010
  triggerSave,
4011
+ gridPopoverOpen: isOpen,
3998
4012
  };
3999
4013
  };
4000
4014
 
@@ -4015,6 +4029,7 @@ const fieldToString = (field) => {
4015
4029
  };
4016
4030
  const GridFormDropDown = (props) => {
4017
4031
  const { selectedRows, field, data } = useGridPopoverContext();
4032
+ const { onSelectFilter, options: propOptions, onSelectedItem } = props;
4018
4033
  // Save triggers during async action processing which triggers another selectItem(), this ref blocks that
4019
4034
  const [filter, setFilter] = useState(props.filterDefaultValue ?? '');
4020
4035
  const [filteredValues, setFilteredValues] = useState();
@@ -4028,8 +4043,8 @@ const GridFormDropDown = (props) => {
4028
4043
  const hasChanged = selectedRows.some((row) => row[field] !== value) ||
4029
4044
  (subComponentValue !== undefined && subComponentInitialValue.current !== JSON.stringify(subComponentValue));
4030
4045
  if (hasChanged) {
4031
- if (props.onSelectedItem) {
4032
- await props.onSelectedItem({
4046
+ if (onSelectedItem) {
4047
+ await onSelectedItem({
4033
4048
  selectedRows,
4034
4049
  selectedRowIds: selectedRows.map((row) => row.id),
4035
4050
  value,
@@ -4041,58 +4056,17 @@ const GridFormDropDown = (props) => {
4041
4056
  }
4042
4057
  }
4043
4058
  return true;
4044
- }, [field, props, selectedRows]);
4045
- // Load up options list if it's async function
4046
- useEffect(() => {
4047
- if (options)
4048
- return;
4049
- let optionsConf = props.options;
4050
- void (async () => {
4051
- if (typeof optionsConf === 'function') {
4052
- optionsConf = await optionsConf(selectedRows, filter);
4053
- }
4054
- if (optionsConf !== undefined) {
4055
- setOptions(optionsConf);
4056
- }
4057
- })();
4058
- }, [filter, options, props, selectedRows]);
4059
- // Local filtering.
4060
- useEffect(() => {
4061
- if (props.filtered == 'local') {
4062
- if (options == null)
4063
- return;
4064
- setFilteredValues(options
4065
- .map((option) => {
4066
- if (option.label != null && typeof option.label !== 'string') {
4067
- console.error('Cannot filter non-string labels', option);
4068
- return undefined;
4069
- }
4070
- return textMatch(option.label || '', filter) ? option : undefined;
4071
- })
4072
- .filter((r) => r !== undefined));
4073
- }
4074
- }, [props.filtered, filter, options]);
4075
- const reSearchOnFilterChange = useMemo(() => debounce(() => {
4076
- setOptions(null);
4077
- }, 500), []);
4078
- const previousFilter = useRef(filter);
4079
- // Reload filtering.
4080
- useEffect(() => {
4081
- if (previousFilter.current != filter && props.filtered == 'reload') {
4082
- previousFilter.current = filter;
4083
- void reSearchOnFilterChange();
4084
- }
4085
- }, [filter, props, reSearchOnFilterChange]);
4059
+ }, [field, onSelectedItem, selectedRows]);
4086
4060
  /**
4087
4061
  * Saves are wrapped in updateValue and triggered by blur events
4088
4062
  */
4089
4063
  const save = useCallback(async () => {
4090
- if (!options)
4064
+ if (!options) {
4091
4065
  return true;
4066
+ }
4092
4067
  // Filter saved
4093
4068
  if (selectedItem === null) {
4094
- if (props.onSelectFilter) {
4095
- const { onSelectFilter } = props;
4069
+ if (onSelectFilter) {
4096
4070
  if (!isEmpty(filter)) {
4097
4071
  await onSelectFilter({
4098
4072
  selectedRows,
@@ -4111,17 +4085,70 @@ const GridFormDropDown = (props) => {
4111
4085
  }
4112
4086
  return false;
4113
4087
  }
4114
- if (selectedItem.subComponent && !subComponentIsValid.current)
4088
+ if (selectedItem.subComponent && !subComponentIsValid.current) {
4115
4089
  return false;
4090
+ }
4116
4091
  await selectItemHandler(selectedItem.value, subSelectedValue);
4117
4092
  return true;
4118
- }, [filter, filteredValues, options, props, selectItemHandler, selectedItem, selectedRows, subSelectedValue]);
4119
- const { popoverWrapper } = useGridPopoverHook({
4093
+ }, [
4094
+ filter,
4095
+ filteredValues,
4096
+ onSelectFilter,
4097
+ options,
4098
+ selectItemHandler,
4099
+ selectedItem,
4100
+ selectedRows,
4101
+ subSelectedValue,
4102
+ ]);
4103
+ const { popoverWrapper, gridPopoverOpen } = useGridPopoverHook({
4120
4104
  className: props.className,
4121
4105
  invalid: () => !options || !!(selectedItem && !subComponentIsValid.current),
4122
4106
  save,
4123
4107
  dontSaveOnExternalClick: true,
4124
4108
  });
4109
+ // Load up options list if it's async function
4110
+ const prevIsOpen = usePrevious(gridPopoverOpen);
4111
+ const prevFilter = usePrevious(filter);
4112
+ 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
+ })();
4123
+ }
4124
+ }, [filter, gridPopoverOpen, options, prevFilter, prevIsOpen, propOptions, selectedRows]);
4125
+ // Local filtering.
4126
+ 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));
4139
+ }
4140
+ }, [props.filtered, filter, options]);
4141
+ const reSearchOnFilterChange = useMemo(() => debounce(() => {
4142
+ setOptions(null);
4143
+ }, 500), []);
4144
+ const previousFilter = useRef(filter);
4145
+ // Reload filtering.
4146
+ useEffect(() => {
4147
+ if (previousFilter.current != filter && props.filtered == 'reload') {
4148
+ previousFilter.current = filter;
4149
+ void reSearchOnFilterChange();
4150
+ }
4151
+ }, [filter, props, reSearchOnFilterChange]);
4125
4152
  let lastHeader = null;
4126
4153
  let showHeader = null;
4127
4154
  return popoverWrapper(jsxs(Fragment, { children: [props.filtered && (jsxs("div", { className: 'GridFormDropDown-filter', children: [jsx(FocusableItem, { className: 'filter-item', onFocus: () => {
@@ -5805,19 +5832,6 @@ const GridUpdatingContextProvider = (props) => {
5805
5832
  var css_248z = ".ActionButton{align-items:center;display:flex}.ActionButton-inProgress .LuiIcon{visibility:hidden}.ActionButton-minimal.lui-button-lg.lui-button-icon-right{padding-right:38px}.ActionButton.lui-button-lg.lui-button-icon-right:not(.ActionButton-tight) .LuiIcon{margin:0 4px}.ActionButton.ActionButton-tight.lui-button-lg.lui-button-icon-right .LuiIcon{margin:0}.ActionButton-iconOnly.lui-button-lg.lui-button-icon-right:not(.ActionButton-tight){padding:8px 5px}.ActionButton-iconOnly.lui-button-lg.lui-button-icon-right.ActionButton-tight{padding:0}.ActionButton-minimalArea{position:relative}.ActionButton-minimalAreaDisplay{position:absolute}.ActionButton-minimalAreaExpand{visibility:hidden}.ActionButton-inProgress.lui-button-lg.lui-button-icon-right{background-color:#e2f3f7;color:#007198;cursor:progress}.ActionButton-fill{justify-content:center;width:100%}";
5806
5833
  styleInject(css_248z);
5807
5834
 
5808
- /**
5809
- * Track previous values of states.
5810
- *
5811
- * @param value Value to track.
5812
- */
5813
- const usePrevious = (value) => {
5814
- const ref = useRef();
5815
- useEffect(() => {
5816
- ref.current = value;
5817
- }, [value]);
5818
- return ref.current;
5819
- };
5820
-
5821
5835
  // Kept this less than one second, so I don't have issues with waitFor as it defaults to 1s
5822
5836
  const minimumInProgressTimeMs = 950;
5823
5837
  const ActionButton = ({ icon, name, inProgressName, disabled, dataTestId, style, className, title, onClick, size = 'sm', iconPosition = 'left', level = 'tertiary', 'aria-label': ariaLabel, }) => {