Skip to content

Commit 5ffdb55

Browse files
stirbyClaude
and
Claude
committed
feat: add searchable dropdown for parameter options
Add typeahead search functionality for parameter options with more than 5 entries. This provides a better user experience for templates with many VM image names or other options that benefit from filtering by substring. Fixes #15038 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0b141c4 commit 5ffdb55

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

site/src/components/RichParameterInput/RichParameterInput.tsx

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Interpolation, Theme } from "@emotion/react";
22
import ErrorOutline from "@mui/icons-material/ErrorOutline";
33
import SettingsIcon from "@mui/icons-material/Settings";
4+
import Autocomplete from "@mui/material/Autocomplete";
45
import Button from "@mui/material/Button";
56
import FormControlLabel from "@mui/material/FormControlLabel";
67
import FormHelperText from "@mui/material/FormHelperText";
@@ -9,7 +10,7 @@ import Radio from "@mui/material/Radio";
910
import RadioGroup from "@mui/material/RadioGroup";
1011
import TextField, { type TextFieldProps } from "@mui/material/TextField";
1112
import Tooltip from "@mui/material/Tooltip";
12-
import type { TemplateVersionParameter } from "api/typesGenerated";
13+
import type { TemplateVersionParameter, TemplateVersionParameterOption } from "api/typesGenerated";
1314
import { ExternalImage } from "components/ExternalImage/ExternalImage";
1415
import { MemoizedMarkdown } from "components/Markdown/Markdown";
1516
import { Pill } from "components/Pill/Pill";
@@ -110,6 +111,11 @@ const styles = {
110111
width: 16,
111112
},
112113
},
114+
autocompleteOption: {
115+
display: "flex",
116+
alignItems: "center",
117+
gap: 8,
118+
},
113119
suggestion: (theme) => ({
114120
color: theme.roles.notice.fill.solid,
115121
marginLeft: "-4px",
@@ -296,6 +302,64 @@ const RichParameterField: FC<RichParameterInputProps> = ({
296302
}
297303

298304
if (parameter.options.length > 0) {
305+
// If we have more than 5 options, use a searchable dropdown instead of radio buttons
306+
if (parameter.options.length > 5) {
307+
// Find the selected option
308+
const selectedOption = parameter.options.find((option) => option.value === value) || null;
309+
310+
return (
311+
<Autocomplete
312+
id={parameter.name}
313+
data-testid="parameter-field-options-autocomplete"
314+
options={parameter.options}
315+
value={selectedOption}
316+
onChange={(_, selectedOption) => {
317+
if (selectedOption) {
318+
onChange(selectedOption.value);
319+
}
320+
}}
321+
getOptionLabel={(option) => option.name}
322+
isOptionEqualToValue={(option, value) => option.value === value.value}
323+
disabled={disabled}
324+
renderInput={(params) => (
325+
<TextField
326+
{...params}
327+
placeholder="Search options..."
328+
size={small ? "small" : "medium"}
329+
fullWidth
330+
/>
331+
)}
332+
renderOption={(props, option) => (
333+
<li {...props} key={option.value}>
334+
<div css={styles.autocompleteOption}>
335+
{option.icon && (
336+
<ExternalImage
337+
css={styles.optionIcon}
338+
src={option.icon}
339+
alt="Parameter icon"
340+
/>
341+
)}
342+
{option.description ? (
343+
<Tooltip
344+
title={
345+
<MemoizedMarkdown>
346+
{option.description}
347+
</MemoizedMarkdown>
348+
}
349+
>
350+
<div>{option.name}</div>
351+
</Tooltip>
352+
) : (
353+
option.name
354+
)}
355+
</div>
356+
</li>
357+
)}
358+
/>
359+
);
360+
}
361+
362+
// Use radio buttons for 5 or fewer options
299363
return (
300364
<RadioGroup
301365
id={parameter.name}
@@ -433,4 +497,4 @@ const RichParameterField: FC<RichParameterInputProps> = ({
433497
}}
434498
/>
435499
);
436-
};
500+
};

0 commit comments

Comments
 (0)