@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.
- package/dist/src/components/GridPopoverHook.d.ts +1 -0
- package/dist/step-ag-grid.cjs +77 -63
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +77 -63
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridPopoverHook.tsx +1 -0
- package/src/components/gridForm/GridFormDropDown.tsx +71 -54
|
@@ -10,4 +10,5 @@ export declare const CancelPromise: () => Promise<boolean>;
|
|
|
10
10
|
export declare const useGridPopoverHook: <TData extends GridBaseRow>({ className, save, invalid, dontSaveOnExternalClick, }: GridPopoverHookProps<TData>) => {
|
|
11
11
|
popoverWrapper: (children: ReactElement) => import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
triggerSave: (reason?: string) => Promise<void>;
|
|
13
|
+
gridPopoverOpen: boolean;
|
|
13
14
|
};
|
package/dist/step-ag-grid.cjs
CHANGED
|
@@ -3801,6 +3801,19 @@ const FormError = (props) => {
|
|
|
3801
3801
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [props.error && (jsxRuntime.jsxs("div", { className: "FormError", children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "FormError-text-icon", size: "sm", status: "error" }), jsxRuntime.jsx("span", { className: "FormError-error", children: props.error })] })), props.helpText && !props.error && jsxRuntime.jsx("span", { className: 'FormError-helpText', children: props.helpText })] }));
|
|
3802
3802
|
};
|
|
3803
3803
|
|
|
3804
|
+
/**
|
|
3805
|
+
* Track previous values of states.
|
|
3806
|
+
*
|
|
3807
|
+
* @param value Value to track.
|
|
3808
|
+
*/
|
|
3809
|
+
const usePrevious = (value) => {
|
|
3810
|
+
const ref = React.useRef();
|
|
3811
|
+
React.useEffect(() => {
|
|
3812
|
+
ref.current = value;
|
|
3813
|
+
}, [value]);
|
|
3814
|
+
return ref.current;
|
|
3815
|
+
};
|
|
3816
|
+
|
|
3804
3817
|
function escapeStringRegexp(string) {
|
|
3805
3818
|
if (typeof string !== 'string') {
|
|
3806
3819
|
throw new TypeError('Expected a string');
|
|
@@ -3997,6 +4010,7 @@ const useGridPopoverHook = ({ className, save, invalid, dontSaveOnExternalClick,
|
|
|
3997
4010
|
return {
|
|
3998
4011
|
popoverWrapper,
|
|
3999
4012
|
triggerSave,
|
|
4013
|
+
gridPopoverOpen: isOpen,
|
|
4000
4014
|
};
|
|
4001
4015
|
};
|
|
4002
4016
|
|
|
@@ -4017,6 +4031,7 @@ const fieldToString = (field) => {
|
|
|
4017
4031
|
};
|
|
4018
4032
|
const GridFormDropDown = (props) => {
|
|
4019
4033
|
const { selectedRows, field, data } = useGridPopoverContext();
|
|
4034
|
+
const { onSelectFilter, options: propOptions, onSelectedItem } = props;
|
|
4020
4035
|
// Save triggers during async action processing which triggers another selectItem(), this ref blocks that
|
|
4021
4036
|
const [filter, setFilter] = React.useState(props.filterDefaultValue ?? '');
|
|
4022
4037
|
const [filteredValues, setFilteredValues] = React.useState();
|
|
@@ -4030,8 +4045,8 @@ const GridFormDropDown = (props) => {
|
|
|
4030
4045
|
const hasChanged = selectedRows.some((row) => row[field] !== value) ||
|
|
4031
4046
|
(subComponentValue !== undefined && subComponentInitialValue.current !== JSON.stringify(subComponentValue));
|
|
4032
4047
|
if (hasChanged) {
|
|
4033
|
-
if (
|
|
4034
|
-
await
|
|
4048
|
+
if (onSelectedItem) {
|
|
4049
|
+
await onSelectedItem({
|
|
4035
4050
|
selectedRows,
|
|
4036
4051
|
selectedRowIds: selectedRows.map((row) => row.id),
|
|
4037
4052
|
value,
|
|
@@ -4043,58 +4058,17 @@ const GridFormDropDown = (props) => {
|
|
|
4043
4058
|
}
|
|
4044
4059
|
}
|
|
4045
4060
|
return true;
|
|
4046
|
-
}, [field,
|
|
4047
|
-
// Load up options list if it's async function
|
|
4048
|
-
React.useEffect(() => {
|
|
4049
|
-
if (options)
|
|
4050
|
-
return;
|
|
4051
|
-
let optionsConf = props.options;
|
|
4052
|
-
void (async () => {
|
|
4053
|
-
if (typeof optionsConf === 'function') {
|
|
4054
|
-
optionsConf = await optionsConf(selectedRows, filter);
|
|
4055
|
-
}
|
|
4056
|
-
if (optionsConf !== undefined) {
|
|
4057
|
-
setOptions(optionsConf);
|
|
4058
|
-
}
|
|
4059
|
-
})();
|
|
4060
|
-
}, [filter, options, props, selectedRows]);
|
|
4061
|
-
// Local filtering.
|
|
4062
|
-
React.useEffect(() => {
|
|
4063
|
-
if (props.filtered == 'local') {
|
|
4064
|
-
if (options == null)
|
|
4065
|
-
return;
|
|
4066
|
-
setFilteredValues(options
|
|
4067
|
-
.map((option) => {
|
|
4068
|
-
if (option.label != null && typeof option.label !== 'string') {
|
|
4069
|
-
console.error('Cannot filter non-string labels', option);
|
|
4070
|
-
return undefined;
|
|
4071
|
-
}
|
|
4072
|
-
return textMatch(option.label || '', filter) ? option : undefined;
|
|
4073
|
-
})
|
|
4074
|
-
.filter((r) => r !== undefined));
|
|
4075
|
-
}
|
|
4076
|
-
}, [props.filtered, filter, options]);
|
|
4077
|
-
const reSearchOnFilterChange = React.useMemo(() => debounce(() => {
|
|
4078
|
-
setOptions(null);
|
|
4079
|
-
}, 500), []);
|
|
4080
|
-
const previousFilter = React.useRef(filter);
|
|
4081
|
-
// Reload filtering.
|
|
4082
|
-
React.useEffect(() => {
|
|
4083
|
-
if (previousFilter.current != filter && props.filtered == 'reload') {
|
|
4084
|
-
previousFilter.current = filter;
|
|
4085
|
-
void reSearchOnFilterChange();
|
|
4086
|
-
}
|
|
4087
|
-
}, [filter, props, reSearchOnFilterChange]);
|
|
4061
|
+
}, [field, onSelectedItem, selectedRows]);
|
|
4088
4062
|
/**
|
|
4089
4063
|
* Saves are wrapped in updateValue and triggered by blur events
|
|
4090
4064
|
*/
|
|
4091
4065
|
const save = React.useCallback(async () => {
|
|
4092
|
-
if (!options)
|
|
4066
|
+
if (!options) {
|
|
4093
4067
|
return true;
|
|
4068
|
+
}
|
|
4094
4069
|
// Filter saved
|
|
4095
4070
|
if (selectedItem === null) {
|
|
4096
|
-
if (
|
|
4097
|
-
const { onSelectFilter } = props;
|
|
4071
|
+
if (onSelectFilter) {
|
|
4098
4072
|
if (!lodashEs.isEmpty(filter)) {
|
|
4099
4073
|
await onSelectFilter({
|
|
4100
4074
|
selectedRows,
|
|
@@ -4113,17 +4087,70 @@ const GridFormDropDown = (props) => {
|
|
|
4113
4087
|
}
|
|
4114
4088
|
return false;
|
|
4115
4089
|
}
|
|
4116
|
-
if (selectedItem.subComponent && !subComponentIsValid.current)
|
|
4090
|
+
if (selectedItem.subComponent && !subComponentIsValid.current) {
|
|
4117
4091
|
return false;
|
|
4092
|
+
}
|
|
4118
4093
|
await selectItemHandler(selectedItem.value, subSelectedValue);
|
|
4119
4094
|
return true;
|
|
4120
|
-
}, [
|
|
4121
|
-
|
|
4095
|
+
}, [
|
|
4096
|
+
filter,
|
|
4097
|
+
filteredValues,
|
|
4098
|
+
onSelectFilter,
|
|
4099
|
+
options,
|
|
4100
|
+
selectItemHandler,
|
|
4101
|
+
selectedItem,
|
|
4102
|
+
selectedRows,
|
|
4103
|
+
subSelectedValue,
|
|
4104
|
+
]);
|
|
4105
|
+
const { popoverWrapper, gridPopoverOpen } = useGridPopoverHook({
|
|
4122
4106
|
className: props.className,
|
|
4123
4107
|
invalid: () => !options || !!(selectedItem && !subComponentIsValid.current),
|
|
4124
4108
|
save,
|
|
4125
4109
|
dontSaveOnExternalClick: true,
|
|
4126
4110
|
});
|
|
4111
|
+
// Load up options list if it's async function
|
|
4112
|
+
const prevIsOpen = usePrevious(gridPopoverOpen);
|
|
4113
|
+
const prevFilter = usePrevious(filter);
|
|
4114
|
+
React.useEffect(() => {
|
|
4115
|
+
if ((gridPopoverOpen !== prevIsOpen || filter !== prevFilter) && gridPopoverOpen) {
|
|
4116
|
+
let optionsConf = propOptions;
|
|
4117
|
+
void (async () => {
|
|
4118
|
+
if (typeof optionsConf === 'function') {
|
|
4119
|
+
optionsConf = await optionsConf(selectedRows, filter);
|
|
4120
|
+
}
|
|
4121
|
+
if (optionsConf !== undefined) {
|
|
4122
|
+
setOptions(optionsConf);
|
|
4123
|
+
}
|
|
4124
|
+
})();
|
|
4125
|
+
}
|
|
4126
|
+
}, [filter, gridPopoverOpen, options, prevFilter, prevIsOpen, propOptions, selectedRows]);
|
|
4127
|
+
// Local filtering.
|
|
4128
|
+
React.useEffect(() => {
|
|
4129
|
+
if (props.filtered == 'local') {
|
|
4130
|
+
if (options == null)
|
|
4131
|
+
return;
|
|
4132
|
+
setFilteredValues(options
|
|
4133
|
+
.map((option) => {
|
|
4134
|
+
if (option.label != null && typeof option.label !== 'string') {
|
|
4135
|
+
console.error('Cannot filter non-string labels', option);
|
|
4136
|
+
return undefined;
|
|
4137
|
+
}
|
|
4138
|
+
return textMatch(option.label || '', filter) ? option : undefined;
|
|
4139
|
+
})
|
|
4140
|
+
.filter((r) => r !== undefined));
|
|
4141
|
+
}
|
|
4142
|
+
}, [props.filtered, filter, options]);
|
|
4143
|
+
const reSearchOnFilterChange = React.useMemo(() => debounce(() => {
|
|
4144
|
+
setOptions(null);
|
|
4145
|
+
}, 500), []);
|
|
4146
|
+
const previousFilter = React.useRef(filter);
|
|
4147
|
+
// Reload filtering.
|
|
4148
|
+
React.useEffect(() => {
|
|
4149
|
+
if (previousFilter.current != filter && props.filtered == 'reload') {
|
|
4150
|
+
previousFilter.current = filter;
|
|
4151
|
+
void reSearchOnFilterChange();
|
|
4152
|
+
}
|
|
4153
|
+
}, [filter, props, reSearchOnFilterChange]);
|
|
4127
4154
|
let lastHeader = null;
|
|
4128
4155
|
let showHeader = null;
|
|
4129
4156
|
return popoverWrapper(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [props.filtered && (jsxRuntime.jsxs("div", { className: 'GridFormDropDown-filter', children: [jsxRuntime.jsx(FocusableItem, { className: 'filter-item', onFocus: () => {
|
|
@@ -5807,19 +5834,6 @@ const GridUpdatingContextProvider = (props) => {
|
|
|
5807
5834
|
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%}";
|
|
5808
5835
|
styleInject(css_248z);
|
|
5809
5836
|
|
|
5810
|
-
/**
|
|
5811
|
-
* Track previous values of states.
|
|
5812
|
-
*
|
|
5813
|
-
* @param value Value to track.
|
|
5814
|
-
*/
|
|
5815
|
-
const usePrevious = (value) => {
|
|
5816
|
-
const ref = React.useRef();
|
|
5817
|
-
React.useEffect(() => {
|
|
5818
|
-
ref.current = value;
|
|
5819
|
-
}, [value]);
|
|
5820
|
-
return ref.current;
|
|
5821
|
-
};
|
|
5822
|
-
|
|
5823
5837
|
// Kept this less than one second, so I don't have issues with waitFor as it defaults to 1s
|
|
5824
5838
|
const minimumInProgressTimeMs = 950;
|
|
5825
5839
|
const ActionButton = ({ icon, name, inProgressName, disabled, dataTestId, style, className, title, onClick, size = 'sm', iconPosition = 'left', level = 'tertiary', 'aria-label': ariaLabel, }) => {
|