@linzjs/step-ag-grid 6.1.0 → 6.1.1
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/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/dist/step-ag-grid.esm.js +12 -11
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/gridForm/GridFormDropDown.tsx +14 -10
package/package.json
CHANGED
|
@@ -68,12 +68,15 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
68
68
|
const optionsInitialising = useRef(false);
|
|
69
69
|
const [options, setOptions] = useState<FinalSelectOption[] | null>(null);
|
|
70
70
|
const subComponentIsValid = useRef(false);
|
|
71
|
-
const
|
|
71
|
+
const subComponentInitialValue = useRef<string | null>(null);
|
|
72
|
+
const [subSelectedValue, setSubSelectedValue] = useState<any>(null);
|
|
72
73
|
const [selectedSubComponent, setSelectedSubComponent] = useState<FinalSelectOption | null>(null);
|
|
73
74
|
|
|
74
75
|
const selectItemHandler = useCallback(
|
|
75
76
|
async (value: any, subComponentValue?: any): Promise<boolean> => {
|
|
76
|
-
const hasChanged =
|
|
77
|
+
const hasChanged =
|
|
78
|
+
selectedRows.some((row) => row[field as keyof RowType] !== value) ||
|
|
79
|
+
(subComponentValue !== undefined && subComponentInitialValue.current !== JSON.stringify(subComponentValue));
|
|
77
80
|
if (hasChanged) {
|
|
78
81
|
if (props.onSelectedItem) {
|
|
79
82
|
await props.onSelectedItem({ selectedRows, value, subComponentValue });
|
|
@@ -182,6 +185,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
182
185
|
*/
|
|
183
186
|
const save = useCallback(async () => {
|
|
184
187
|
if (!options) return true;
|
|
188
|
+
|
|
185
189
|
const activeOptions = options.filter((option) => !filteredValues.includes(option.value));
|
|
186
190
|
if (activeOptions.length === 1) {
|
|
187
191
|
await selectItemHandler(activeOptions[0].value);
|
|
@@ -254,14 +258,10 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
254
258
|
value={item.value}
|
|
255
259
|
onClick={(e: ClickEvent) => {
|
|
256
260
|
if (item.subComponent) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
} else {
|
|
262
|
-
// toggle selection on
|
|
263
|
-
setSelectedSubComponent(item);
|
|
264
|
-
}
|
|
261
|
+
// toggle selection
|
|
262
|
+
setSelectedSubComponent(selectedSubComponent === item ? null : item);
|
|
263
|
+
subComponentIsValid.current = true;
|
|
264
|
+
subComponentInitialValue.current = null;
|
|
265
265
|
e.keepOpen = true;
|
|
266
266
|
} else {
|
|
267
267
|
clickItemHandler(
|
|
@@ -289,6 +289,10 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
|
|
|
289
289
|
value: subSelectedValue,
|
|
290
290
|
setValue: (value: any) => {
|
|
291
291
|
setSubSelectedValue(value);
|
|
292
|
+
if (subComponentInitialValue.current === null) {
|
|
293
|
+
// copy the default value of the sub-component so we can change detect on save
|
|
294
|
+
subComponentInitialValue.current = JSON.stringify(value);
|
|
295
|
+
}
|
|
292
296
|
},
|
|
293
297
|
setValid: (valid: boolean) => {
|
|
294
298
|
subComponentIsValid.current = valid;
|