Skip to content

Commit 614a7ec

Browse files
authored
Biz/dj 2837 show label and keep selected remote option dropdown enabled (#15438)
* Always show labels on dynamic props * Update version to 1.0.0-preview.25 * Add comment to useEffect * Handle propsNeedConfiguring on field registration * Cleanup
1 parent 505f170 commit 614a7ec

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

packages/connect-react/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<!-- markdownlint-disable MD024 -->
22
# Changelog
33

4+
# [1.0.0-preview.25] - 2025-01-28
5+
6+
- Show prop labels instead of values after selecting dynamic props
7+
- Fix the bug where a remote option would not be reloaded when the form component is re-rendered
8+
49
# [1.0.0-preview.24] - 2025-01-24
510

611
- Fix the bug where inputting multiple strings into an array prop would merge the strings into one

packages/connect-react/examples/nextjs/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/connect-react/src/components/ControlSelect.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,16 @@ export function ControlSelect<T>({
171171
if (o) {
172172
if (Array.isArray(o)) {
173173
if (typeof o[0] === "object" && "value" in o[0]) {
174-
const vs = [];
175-
for (const _o of o) {
176-
if (prop.withLabel) {
177-
vs.push(_o);
178-
} else {
179-
vs.push(_o.value);
180-
}
181-
}
182-
onChange(vs);
183-
} else {
184-
onChange(o);
185-
}
186-
} else if (typeof o === "object" && "value" in o) {
187-
if (prop.withLabel) {
188174
onChange({
189175
__lv: o,
190176
});
191177
} else {
192-
onChange(o.value);
178+
onChange(o);
193179
}
180+
} else if (typeof o === "object" && "value" in o) {
181+
onChange({
182+
__lv: o,
183+
});
194184
} else {
195185
throw new Error("unhandled option type"); // TODO
196186
}

packages/connect-react/src/hooks/form-context.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
appPropErrors, arrayPropErrors, booleanPropErrors, integerPropErrors,
1414
stringPropErrors,
1515
} from "../utils/component";
16+
import _ from "lodash";
1617

1718
export type DynamicProps<T extends ConfigurableProps> = { id: string; configurableProps: T; }; // TODO
1819

@@ -254,6 +255,15 @@ export const FormContextProvider = <T extends ConfigurableProps>({
254255
setErrors(_errors);
255256
};
256257

258+
useEffect(() => {
259+
// Initialize queryDisabledIdx on load so that we don't force users
260+
// to reconfigure a prop they've already configured whenever the page
261+
// or component is reloaded
262+
updateConfiguredPropsQueryDisabledIdx(_configuredProps)
263+
}, [
264+
_configuredProps,
265+
]);
266+
257267
useEffect(() => {
258268
const newConfiguredProps: ConfiguredProps<T> = {};
259269
for (const prop of configurableProps) {
@@ -365,6 +375,15 @@ export const FormContextProvider = <T extends ConfigurableProps>({
365375
}
366376
}
367377
// propsNeedConfiguring.splice(0, propsNeedConfiguring.length, ..._propsNeedConfiguring)
378+
379+
// Prevent useEffect/useState infinite loop by updating
380+
// propsNeedConfiguring only if there is an actual change to the list of
381+
// props that need to be configured.
382+
// NB: The infinite loop is triggered because of calling
383+
// checkPropsNeedConfiguring() from registerField, which is called
384+
// from inside useEffect.
385+
if (_propsNeedConfiguring && propsNeedConfiguring && _.isEqual(_propsNeedConfiguring, propsNeedConfiguring)) return;
386+
368387
setPropsNeedConfiguring(_propsNeedConfiguring)
369388
}
370389

@@ -373,6 +392,7 @@ export const FormContextProvider = <T extends ConfigurableProps>({
373392
fields[field.prop.name] = field
374393
return fields
375394
});
395+
checkPropsNeedConfiguring()
376396
};
377397

378398
// console.log("***", configurableProps, configuredProps)

packages/connect-react/src/utils/component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export function valuesFromOptions<T>(value: unknown | T[] | PropOptions<T>): T[]
4040
}
4141
return results
4242
}
43+
if (value && typeof value === "object" && Array.isArray(value.__lv)) {
44+
return value.__lv as T[]
45+
}
4346
if (!Array.isArray(value))
4447
return []
4548
return value as T[]

0 commit comments

Comments
 (0)