Skip to content

Commit d109874

Browse files
committed
chore: update for types from typesGenerated
1 parent 0fc4289 commit d109874

File tree

2 files changed

+75
-92
lines changed

2 files changed

+75
-92
lines changed

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

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,35 @@ const ParameterField: FC<ParameterFieldProps> = ({
173173
<SelectValue placeholder="Select option" />
174174
</SelectTrigger>
175175
<SelectContent>
176-
{parameter.options.map((option) => (
177-
<SelectItem key={option.value.value} value={option.value.value}>
178-
<OptionDisplay option={option} />
179-
</SelectItem>
180-
))}
176+
{parameter.options
177+
.filter(
178+
(option): option is NonNullable<typeof option> =>
179+
option !== null,
180+
)
181+
.map((option) => (
182+
<SelectItem key={option.value.value} value={option.value.value}>
183+
<OptionDisplay option={option} />
184+
</SelectItem>
185+
))}
181186
</SelectContent>
182187
</Select>
183188
);
184189

185190
case "multi-select": {
186191
// Map parameter options to MultiSelectCombobox options format
187-
const comboboxOptions: Option[] = parameter.options.map((opt) => ({
188-
value: opt.value.value,
189-
label: opt.name,
190-
disable: false,
191-
}));
192+
const comboboxOptions: Option[] = parameter.options
193+
.filter((opt): opt is NonNullable<typeof opt> => opt !== null)
194+
.map((opt) => ({
195+
value: opt.value.value,
196+
label: opt.name,
197+
disable: false,
198+
}));
192199

193200
const defaultOptions: Option[] = JSON.parse(defaultValue).map(
194201
(val: string) => {
195-
const option = parameter.options.find((o) => o.value.value === val);
202+
const option = parameter.options
203+
.filter((o): o is NonNullable<typeof o> => o !== null)
204+
.find((o) => o.value.value === val);
196205
return {
197206
value: val,
198207
label: option?.name || val,
@@ -242,20 +251,24 @@ const ParameterField: FC<ParameterFieldProps> = ({
242251
disabled={disabled}
243252
defaultValue={defaultValue}
244253
>
245-
{parameter.options.map((option) => (
246-
<div
247-
key={option.value.value}
248-
className="flex items-center space-x-2"
249-
>
250-
<RadioGroupItem
251-
id={option.value.value}
252-
value={option.value.value}
253-
/>
254-
<Label htmlFor={option.value.value} className="cursor-pointer">
255-
<OptionDisplay option={option} />
256-
</Label>
257-
</div>
258-
))}
254+
{parameter.options
255+
.filter(
256+
(option): option is NonNullable<typeof option> => option !== null,
257+
)
258+
.map((option) => (
259+
<div
260+
key={option.value.value}
261+
className="flex items-center space-x-2"
262+
>
263+
<RadioGroupItem
264+
id={option.value.value}
265+
value={option.value.value}
266+
/>
267+
<Label htmlFor={option.value.value} className="cursor-pointer">
268+
<OptionDisplay option={option} />
269+
</Label>
270+
</div>
271+
))}
259272
</RadioGroup>
260273
);
261274

@@ -281,7 +294,10 @@ const ParameterField: FC<ParameterFieldProps> = ({
281294
const inputProps: Record<string, unknown> = {};
282295

283296
if (parameter.type === "number") {
284-
const validations = parameter.validations[0] || {};
297+
const validations =
298+
parameter.validations.filter(
299+
(v): v is NonNullable<typeof v> => v !== null,
300+
)[0] || {};
285301
const { validation_min, validation_max } = validations;
286302

287303
if (validation_min !== null) {
@@ -349,19 +365,24 @@ const ParameterDiagnostics: FC<ParameterDiagnosticsProps> = ({
349365
}) => {
350366
return (
351367
<div className="flex flex-col gap-2">
352-
{diagnostics.map((diagnostic, index) => (
353-
<div
354-
key={`diagnostic-${diagnostic.summary}-${index}`}
355-
className={`text-xs px-1 ${
356-
diagnostic.severity === "error"
357-
? "text-content-destructive"
358-
: "text-content-warning"
359-
}`}
360-
>
361-
<div className="font-medium">{diagnostic.summary}</div>
362-
{diagnostic.detail && <div>{diagnostic.detail}</div>}
363-
</div>
364-
))}
368+
{diagnostics
369+
.filter(
370+
(diagnostic): diagnostic is NonNullable<typeof diagnostic> =>
371+
diagnostic !== null,
372+
)
373+
.map((diagnostic, index) => (
374+
<div
375+
key={`diagnostic-${diagnostic.summary}-${index}`}
376+
className={`text-xs px-1 ${
377+
diagnostic.severity === "error"
378+
? "text-content-destructive"
379+
: "text-content-warning"
380+
}`}
381+
>
382+
<div className="font-medium">{diagnostic.summary}</div>
383+
{diagnostic.detail && <div>{diagnostic.detail}</div>}
384+
</div>
385+
))}
365386
</div>
366387
);
367388
};
@@ -433,12 +454,12 @@ export const useValidationSchemaForDynamicParameters = (
433454
if (parameter) {
434455
switch (parameter.type) {
435456
case "number": {
436-
const minValidation = parameter.validations.find(
437-
(v) => v.validation_min !== null,
438-
);
439-
const maxValidation = parameter.validations.find(
440-
(v) => v.validation_max !== null,
441-
);
457+
const minValidation = parameter.validations
458+
.filter((v): v is NonNullable<typeof v> => v !== null)
459+
.find((v) => v.validation_min !== null);
460+
const maxValidation = parameter.validations
461+
.filter((v): v is NonNullable<typeof v> => v !== null)
462+
.find((v) => v.validation_max !== null);
442463

443464
if (
444465
minValidation &&
@@ -547,15 +568,15 @@ const parameterError = (
547568
parameter: PreviewParameter,
548569
value?: string,
549570
): string | undefined => {
550-
const validation_error = parameter.validations.find(
551-
(v) => v.validation_error !== null,
552-
);
553-
const minValidation = parameter.validations.find(
554-
(v) => v.validation_min !== null,
555-
);
556-
const maxValidation = parameter.validations.find(
557-
(v) => v.validation_max !== null,
558-
);
571+
const validation_error = parameter.validations
572+
.filter((v): v is NonNullable<typeof v> => v !== null)
573+
.find((v) => v.validation_error !== null);
574+
const minValidation = parameter.validations
575+
.filter((v): v is NonNullable<typeof v> => v !== null)
576+
.find((v) => v.validation_min !== null);
577+
const maxValidation = parameter.validations
578+
.filter((v): v is NonNullable<typeof v> => v !== null)
579+
.find((v) => v.validation_max !== null);
559580

560581
if (!validation_error || !value) {
561582
return;

site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,44 +72,6 @@ export interface CreateWorkspacePageViewExperimentalProps {
7272
startPollingExternalAuth: () => void;
7373
}
7474

75-
// const getInitialParameterValues1 = (
76-
// params: Parameter[],
77-
// autofillParams?: AutofillBuildParameter[],
78-
// ): WorkspaceBuildParameter[] => {
79-
// return params.map((parameter) => {
80-
// // Short-circuit for ephemeral parameters, which are always reset to
81-
// // the template-defined default.
82-
// if (parameter.ephemeral) {
83-
// return {
84-
// name: parameter.name,
85-
// value: parameter.default_value,
86-
// };
87-
// }
88-
89-
// const autofillParam = autofillParams?.find(
90-
// ({ name }) => name === parameter.name,
91-
// );
92-
93-
// return {
94-
// name: parameter.name,
95-
// value:
96-
// autofillParam &&
97-
// isValidValue(parameter, autofillParam) &&
98-
// autofillParam.source !== "user_history"
99-
// ? autofillParam.value
100-
// : parameter.default_value,
101-
// };
102-
// });
103-
// };
104-
105-
const getInitialParameterValues = (parameters: Parameter[]) => {
106-
return parameters.map((parameter) => {
107-
return {
108-
name: parameter.name,
109-
value: parameter.default_value.valid ? parameter.default_value.value : "",
110-
};
111-
});
112-
};
11375
export const CreateWorkspacePageViewExperimental: FC<
11476
CreateWorkspacePageViewExperimentalProps
11577
> = ({

0 commit comments

Comments
 (0)