From d6cb9b49b71db3bb93dc730f6316c8ed17529e5a Mon Sep 17 00:00:00 2001 From: Jaayden Halko Date: Fri, 16 May 2025 23:05:33 +0100 Subject: [PATCH] feat: setup url autofill for dynamic parameters (#17739) resolves coder/preview#80 Parameter autofill allows setting parameters from the url using the format param.[param name]=["purple","green"] Example: http://localhost:8080/templates/coder/scratch/workspace?param.list=%5b%22purple%22%2c%22green%22%5d%0a The goal is to maintain feature parity of for autofill with dynamic parameters. Note: user history autofill is no longer being used and is being removed. --- site/src/components/Select/Select.tsx | 7 +- .../DynamicParameter/DynamicParameter.tsx | 316 ++++++++++++------ .../CreateWorkspacePageExperimental.tsx | 101 ++++-- .../CreateWorkspacePageViewExperimental.tsx | 44 +-- 4 files changed, 308 insertions(+), 160 deletions(-) diff --git a/site/src/components/Select/Select.tsx b/site/src/components/Select/Select.tsx index 43839d9a00..3d2f8ffc3b 100644 --- a/site/src/components/Select/Select.tsx +++ b/site/src/components/Select/Select.tsx @@ -15,10 +15,13 @@ export const SelectValue = SelectPrimitive.Value; export const SelectTrigger = React.forwardRef< React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, children, ...props }, ref) => ( + React.ComponentPropsWithoutRef & { + id?: string; + } +>(({ className, children, id, ...props }, ref) => ( void; disabled?: boolean; isPreset?: boolean; + autofill: boolean; } export const DynamicParameter: FC = ({ parameter, + value, onChange, disabled, isPreset, + autofill = false, }) => { const id = useId(); @@ -57,14 +63,31 @@ export const DynamicParameter: FC = ({ className="flex flex-col gap-2" data-testid={`parameter-field-${parameter.name}`} > - +
- + {parameter.form_type === "input" || + parameter.form_type === "textarea" ? ( + + ) : ( + + )}
{parameter.diagnostics.length > 0 && ( @@ -76,10 +99,16 @@ export const DynamicParameter: FC = ({ interface ParameterLabelProps { parameter: PreviewParameter; isPreset?: boolean; + autofill: boolean; + id: string; } -const ParameterLabel: FC = ({ parameter, isPreset }) => { - const hasDescription = parameter.description && parameter.description !== ""; +const ParameterLabel: FC = ({ + parameter, + isPreset, + autofill, + id, +}) => { const displayName = parameter.display_name ? parameter.display_name : parameter.name; @@ -95,7 +124,10 @@ const ParameterLabel: FC = ({ parameter, isPreset }) => { )}
-