Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09f9db9

Browse files
committed
fix: handle empty strings for Select component
1 parent 6ed2204 commit 09f9db9

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,17 @@ const ParameterField: FC<ParameterFieldProps> = ({
379379
id,
380380
}) => {
381381
switch (parameter.form_type) {
382-
case "dropdown":
382+
case "dropdown": {
383+
const EMPTY_VALUE_PLACEHOLDER = "__EMPTY_STRING__";
384+
const selectValue = value === "" ? EMPTY_VALUE_PLACEHOLDER : value;
385+
const handleSelectChange = (newValue: string) => {
386+
onChange(newValue === EMPTY_VALUE_PLACEHOLDER ? "" : newValue);
387+
};
388+
383389
return (
384390
<Select
385-
onValueChange={onChange}
386-
value={value}
391+
onValueChange={handleSelectChange}
392+
value={selectValue}
387393
disabled={disabled}
388394
required={parameter.required}
389395
>
@@ -393,14 +399,24 @@ const ParameterField: FC<ParameterFieldProps> = ({
393399
/>
394400
</SelectTrigger>
395401
<SelectContent>
396-
{parameter.options.map((option) => (
397-
<SelectItem key={option.value.value} value={option.value.value}>
398-
<OptionDisplay option={option} />
399-
</SelectItem>
400-
))}
402+
{parameter.options.map((option, index) => {
403+
const optionValue =
404+
option.value.value === ""
405+
? EMPTY_VALUE_PLACEHOLDER
406+
: option.value.value;
407+
return (
408+
<SelectItem
409+
key={option.value.value || `${EMPTY_VALUE_PLACEHOLDER}:${index}`}
410+
value={optionValue}
411+
>
412+
<OptionDisplay option={option} />
413+
</SelectItem>
414+
);
415+
})}
401416
</SelectContent>
402417
</Select>
403418
);
419+
}
404420

405421
case "multi-select": {
406422
const parsedValues = parseStringArrayValue(value ?? "");

0 commit comments

Comments
 (0)