Skip to content

feat: setup url autofill for dynamic parameters #17739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 16, 2025
Prev Previous commit
Next Next commit
fix: setup ParameterLabel to use htmlfor
  • Loading branch information
jaaydenh committed May 15, 2025
commit ec35a7f4bd47383b88cea03000c90c7ec1c62d4f
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export const MultiSelectCombobox = forwardRef<
})}
{/* Avoid having the "Search" Icon */}
<CommandPrimitive.Input
id={inputProps?.id}
{...inputProps}
ref={inputRef}
value={inputValue}
Expand Down
5 changes: 3 additions & 2 deletions site/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ export const SelectValue = SelectPrimitive.Value;

export const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & { id?: string }
>(({ className, children, id, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
id={id}
className={cn(
`flex h-10 w-full font-medium items-center justify-between whitespace-nowrap rounded-md
border border-border border-solid bg-transparent px-3 py-2 text-sm shadow-sm
Expand Down
39 changes: 23 additions & 16 deletions site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const DynamicParameter: FC<DynamicParameterProps> = ({
data-testid={`parameter-field-${parameter.name}`}
>
<ParameterLabel
id={id}
parameter={parameter}
isPreset={isPreset}
autofill={autofill}
Expand All @@ -86,12 +87,14 @@ interface ParameterLabelProps {
parameter: PreviewParameter;
isPreset?: boolean;
autofill?: AutofillBuildParameter;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is only being used for a truthy check to influence the conditional rendering, can we replace this with an autofill boolean?

id: string;
}

const ParameterLabel: FC<ParameterLabelProps> = ({
parameter,
isPreset,
autofill,
id,
}) => {
const hasDescription = parameter.description && parameter.description !== "";
const displayName = parameter.display_name
Expand All @@ -109,7 +112,10 @@ const ParameterLabel: FC<ParameterLabelProps> = ({
)}

<div className="flex flex-col w-full gap-1">
<Label className="flex gap-2 flex-wrap text-sm font-medium">
<Label
htmlFor={id}
className="flex gap-2 flex-wrap text-sm font-medium"
>
<span className="flex">
{displayName}
{parameter.required && (
Expand Down Expand Up @@ -197,15 +203,12 @@ const ParameterField: FC<ParameterFieldProps> = ({
disabled,
id,
}) => {
const initialValue =
value !== undefined ? value : validValue(parameter.value);
const [localValue, setLocalValue] = useState(initialValue);

useEffect(() => {
if (value !== undefined) {
setLocalValue(value);
}
}, [value]);
const [localValue, setLocalValue] = useState(
value !== undefined ? value : validValue(parameter.value)
);
if (value !== undefined && value !== localValue) {
setLocalValue(value);
}

switch (parameter.form_type) {
case "dropdown":
Expand All @@ -216,7 +219,7 @@ const ParameterField: FC<ParameterFieldProps> = ({
disabled={disabled}
required={parameter.required}
>
<SelectTrigger>
<SelectTrigger id={id}>
<SelectValue
placeholder={parameter.styling?.placeholder || "Select option"}
/>
Expand Down Expand Up @@ -256,7 +259,7 @@ const ParameterField: FC<ParameterFieldProps> = ({
return (
<MultiSelectCombobox
inputProps={{
id: `${id}-${parameter.name}`,
id: id,
}}
options={options}
defaultOptions={selectedOptions}
Expand All @@ -281,7 +284,7 @@ const ParameterField: FC<ParameterFieldProps> = ({

return (
<TagInput
id={parameter.name}
id={id}
label={parameter.display_name || parameter.name}
values={values}
onChange={(values) => {
Expand All @@ -294,6 +297,7 @@ const ParameterField: FC<ParameterFieldProps> = ({
case "switch":
return (
<Switch
id={id}
checked={value === "true"}
onCheckedChange={(checked) => {
onChange(checked ? "true" : "false");
Expand Down Expand Up @@ -329,23 +333,24 @@ const ParameterField: FC<ParameterFieldProps> = ({
return (
<div className="flex items-center space-x-2">
<Checkbox
id={parameter.name}
id={id}
checked={value === "true"}
onCheckedChange={(checked) => {
onChange(checked ? "true" : "false");
}}
disabled={disabled}
/>
<Label htmlFor={parameter.name}>{parameter.styling?.label}</Label>
<Label htmlFor={id}>{parameter.styling?.label}</Label>
</div>
);

case "slider":
return (
<div className="flex flex-row items-baseline gap-3">
<Slider
id={id}
className="mt-2"
value={[Number(localValue ?? 0)]}
value={[Number(localValue)]}
onValueChange={([value]) => {
setLocalValue(value.toString());
onChange(value.toString());
Expand All @@ -361,6 +366,7 @@ const ParameterField: FC<ParameterFieldProps> = ({
case "textarea":
return (
<Textarea
id={id}
className="max-w-2xl"
value={localValue}
onChange={(e) => {
Expand Down Expand Up @@ -397,6 +403,7 @@ const ParameterField: FC<ParameterFieldProps> = ({

return (
<Input
id={id}
type={inputType}
value={localValue}
onChange={(e) => {
Expand Down