@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
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { Fragment, ReactElement, useCallback, useEffect, useMemo, useRef, useSta
|
|
|
5
5
|
import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
|
|
6
6
|
import { GridSubComponentContext } from '../../contexts/GridSubComponentContext';
|
|
7
7
|
import { FormError } from '../../lui/FormError';
|
|
8
|
+
import { usePrevious } from '../../lui/reactUtils';
|
|
8
9
|
import { FocusableItem, MenuDivider, MenuHeader, MenuItem } from '../../react-menu3';
|
|
9
10
|
import { ClickEvent } from '../../react-menu3/types';
|
|
10
11
|
import { textMatch } from '../../utils/textMatcher';
|
|
@@ -84,6 +85,7 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
|
|
|
84
85
|
props: GridFormDropDownProps<TData, TOptionValue>,
|
|
85
86
|
) => {
|
|
86
87
|
const { selectedRows, field, data } = useGridPopoverContext<TData>();
|
|
88
|
+
const { onSelectFilter, options: propOptions, onSelectedItem } = props;
|
|
87
89
|
|
|
88
90
|
// Save triggers during async action processing which triggers another selectItem(), this ref blocks that
|
|
89
91
|
const [filter, setFilter] = useState(props.filterDefaultValue ?? '');
|
|
@@ -101,8 +103,8 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
|
|
|
101
103
|
selectedRows.some((row) => row[field] !== value) ||
|
|
102
104
|
(subComponentValue !== undefined && subComponentInitialValue.current !== JSON.stringify(subComponentValue));
|
|
103
105
|
if (hasChanged) {
|
|
104
|
-
if (
|
|
105
|
-
await
|
|
106
|
+
if (onSelectedItem) {
|
|
107
|
+
await onSelectedItem({
|
|
106
108
|
selectedRows,
|
|
107
109
|
selectedRowIds: selectedRows.map((row) => row.id),
|
|
108
110
|
value,
|
|
@@ -114,23 +116,78 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
|
|
|
114
116
|
}
|
|
115
117
|
return true;
|
|
116
118
|
},
|
|
117
|
-
[field,
|
|
119
|
+
[field, onSelectedItem, selectedRows],
|
|
118
120
|
);
|
|
119
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Saves are wrapped in updateValue and triggered by blur events
|
|
124
|
+
*/
|
|
125
|
+
const save = useCallback(async () => {
|
|
126
|
+
if (!options) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Filter saved
|
|
131
|
+
if (selectedItem === null) {
|
|
132
|
+
if (onSelectFilter) {
|
|
133
|
+
if (!isEmpty(filter)) {
|
|
134
|
+
await onSelectFilter({
|
|
135
|
+
selectedRows,
|
|
136
|
+
selectedRowIds: selectedRows.map((row) => row.id),
|
|
137
|
+
value: filter as any,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return true;
|
|
142
|
+
} else {
|
|
143
|
+
if (filteredValues && filteredValues.length === 1) {
|
|
144
|
+
if (filteredValues[0].subComponent) return false;
|
|
145
|
+
return await selectItemHandler(filteredValues[0].value, null);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (selectedItem.subComponent && !subComponentIsValid.current) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
await selectItemHandler(selectedItem.value, subSelectedValue);
|
|
154
|
+
|
|
155
|
+
return true;
|
|
156
|
+
}, [
|
|
157
|
+
filter,
|
|
158
|
+
filteredValues,
|
|
159
|
+
onSelectFilter,
|
|
160
|
+
options,
|
|
161
|
+
selectItemHandler,
|
|
162
|
+
selectedItem,
|
|
163
|
+
selectedRows,
|
|
164
|
+
subSelectedValue,
|
|
165
|
+
]);
|
|
166
|
+
|
|
167
|
+
const { popoverWrapper, gridPopoverOpen } = useGridPopoverHook({
|
|
168
|
+
className: props.className,
|
|
169
|
+
invalid: () => !options || !!(selectedItem && !subComponentIsValid.current),
|
|
170
|
+
save,
|
|
171
|
+
dontSaveOnExternalClick: true,
|
|
172
|
+
});
|
|
173
|
+
|
|
120
174
|
// Load up options list if it's async function
|
|
175
|
+
const prevIsOpen = usePrevious(gridPopoverOpen);
|
|
176
|
+
const prevFilter = usePrevious(filter);
|
|
121
177
|
useEffect(() => {
|
|
122
|
-
if (
|
|
123
|
-
|
|
178
|
+
if ((gridPopoverOpen !== prevIsOpen || filter !== prevFilter) && gridPopoverOpen) {
|
|
179
|
+
let optionsConf = propOptions;
|
|
124
180
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
181
|
+
void (async () => {
|
|
182
|
+
if (typeof optionsConf === 'function') {
|
|
183
|
+
optionsConf = await optionsConf(selectedRows, filter);
|
|
184
|
+
}
|
|
185
|
+
if (optionsConf !== undefined) {
|
|
186
|
+
setOptions(optionsConf);
|
|
187
|
+
}
|
|
188
|
+
})();
|
|
189
|
+
}
|
|
190
|
+
}, [filter, gridPopoverOpen, options, prevFilter, prevIsOpen, propOptions, selectedRows]);
|
|
134
191
|
|
|
135
192
|
// Local filtering.
|
|
136
193
|
useEffect(() => {
|
|
@@ -168,46 +225,6 @@ export const GridFormDropDown = <TData extends GridBaseRow, TOptionValue>(
|
|
|
168
225
|
}
|
|
169
226
|
}, [filter, props, reSearchOnFilterChange]);
|
|
170
227
|
|
|
171
|
-
/**
|
|
172
|
-
* Saves are wrapped in updateValue and triggered by blur events
|
|
173
|
-
*/
|
|
174
|
-
const save = useCallback(async () => {
|
|
175
|
-
if (!options) return true;
|
|
176
|
-
|
|
177
|
-
// Filter saved
|
|
178
|
-
if (selectedItem === null) {
|
|
179
|
-
if (props.onSelectFilter) {
|
|
180
|
-
const { onSelectFilter } = props;
|
|
181
|
-
if (!isEmpty(filter)) {
|
|
182
|
-
await onSelectFilter({
|
|
183
|
-
selectedRows,
|
|
184
|
-
selectedRowIds: selectedRows.map((row) => row.id),
|
|
185
|
-
value: filter as any,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return true;
|
|
190
|
-
} else {
|
|
191
|
-
if (filteredValues && filteredValues.length === 1) {
|
|
192
|
-
if (filteredValues[0].subComponent) return false;
|
|
193
|
-
return await selectItemHandler(filteredValues[0].value, null);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
if (selectedItem.subComponent && !subComponentIsValid.current) return false;
|
|
199
|
-
await selectItemHandler(selectedItem.value, subSelectedValue);
|
|
200
|
-
|
|
201
|
-
return true;
|
|
202
|
-
}, [filter, filteredValues, options, props, selectItemHandler, selectedItem, selectedRows, subSelectedValue]);
|
|
203
|
-
|
|
204
|
-
const { popoverWrapper } = useGridPopoverHook({
|
|
205
|
-
className: props.className,
|
|
206
|
-
invalid: () => !options || !!(selectedItem && !subComponentIsValid.current),
|
|
207
|
-
save,
|
|
208
|
-
dontSaveOnExternalClick: true,
|
|
209
|
-
});
|
|
210
|
-
|
|
211
228
|
let lastHeader: ReactElement | null = null;
|
|
212
229
|
let showHeader: ReactElement | null = null;
|
|
213
230
|
|