Skip to content

Commit 96a9096

Browse files
committed
minor: clean up session launcher form
1 parent 8be2af4 commit 96a9096

File tree

2 files changed

+48
-35
lines changed

2 files changed

+48
-35
lines changed

client/src/features/sessionsV2/components/SessionForm/AdvancedSettingsFields.tsx

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@ function OptionalLabel() {
4343
return <span className={cx("small", "text-muted")}>(Optional)</span>;
4444
}
4545

46+
interface FormFieldLabelProps<T extends FieldValues> {
47+
info: string;
48+
isOptional?: boolean;
49+
label: ReactNode;
50+
name: Path<T>;
51+
}
52+
53+
function FormFieldLabel<T extends FieldValues>({
54+
info,
55+
isOptional,
56+
label,
57+
name,
58+
}: FormFieldLabelProps<T>) {
59+
return (
60+
<div className={cx("d-flex", "align-items-center", "gap-2", "mb-1")}>
61+
<Label
62+
for={`addSessionLauncher${name}`}
63+
className="mb-0"
64+
aria-required={isOptional ? "false" : "true"}
65+
>
66+
{label}
67+
</Label>
68+
{info && (
69+
<MoreInfo>
70+
<LazyRenkuMarkdown markdownText={info} />
71+
</MoreInfo>
72+
)}
73+
{isOptional && <OptionalLabel />}
74+
</div>
75+
);
76+
}
77+
4678
function FormField<T extends FieldValues>({
4779
control,
4880
errors,
@@ -53,16 +85,12 @@ function FormField<T extends FieldValues>({
5385
rules,
5486
type = "text",
5587
isOptional,
56-
}: {
88+
}: FormFieldLabelProps<T> & {
5789
control: Control<T>;
5890
errors?: FieldErrors<T>;
59-
info: string;
60-
label: ReactNode;
61-
name: Path<T>;
6291
placeholder?: string;
6392
rules?: ControllerProps<T>["rules"];
6493
type: InputType;
65-
isOptional?: boolean;
6694
}) {
6795
if (type === "checkbox" || type === "radio") {
6896
return (
@@ -82,20 +110,12 @@ function FormField<T extends FieldValues>({
82110

83111
return (
84112
<>
85-
<Label
86-
for={`addSessionLauncher${name}`}
87-
className={cx("align-items-center", "d-flex", "gap-2")}
88-
aria-required={isOptional ? "false" : "true"}
89-
>
90-
{label}
91-
{info && (
92-
<MoreInfo>
93-
<LazyRenkuMarkdown markdownText={info} />
94-
</MoreInfo>
95-
)}
96-
97-
{isOptional && <OptionalLabel />}
98-
</Label>
113+
<FormFieldLabel
114+
info={info}
115+
isOptional={isOptional}
116+
label={label}
117+
name={name}
118+
/>
99119
<Controller
100120
control={control}
101121
name={name}
@@ -207,20 +227,12 @@ function JsonField<T extends FieldValues>({
207227
}: JsonFieldProps<T>) {
208228
return (
209229
<>
210-
<Label
211-
for={`addSessionLauncher${name}`}
212-
className={cx("align-items-center", "d-flex", "gap-2")}
213-
>
214-
{label}
215-
{info && (
216-
<MoreInfo>
217-
<LazyRenkuMarkdown markdownText={info} />
218-
</MoreInfo>
219-
)}
220-
{isOptional && <OptionalLabel />}
221-
</Label>
222-
223-
<FormText tag="div">{helpText}</FormText>
230+
<FormFieldLabel
231+
info={info}
232+
isOptional={isOptional}
233+
label={label}
234+
name={name}
235+
/>
224236
<Controller
225237
control={control}
226238
name={name}
@@ -237,6 +249,7 @@ function JsonField<T extends FieldValues>({
237249
/>
238250
)}
239251
/>
252+
<FormText tag="div">{helpText}</FormText>
240253
{errors?.[name] && (
241254
<div className="invalid-feedback mt-0 d-block">
242255
{errors[name]?.message?.toString()}
@@ -295,7 +308,7 @@ export function AdvancedSettingsFields<
295308

296309
<div className="row">
297310
<div className={cx("col-12")}>
298-
<h4 className="fw-bold">Docker settings</h4>
311+
<h3 className={cx("fw-bold", "mt-3")}>Docker settings</h3>
299312
</div>
300313
</div>
301314

client/src/features/sessionsV2/components/SessionForm/CustomEnvironmentFields.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export function CustomEnvironmentFields({
130130
</div>
131131

132132
<div>
133-
<h4 className="fw-bold">Advanced settings</h4>
133+
<h3 className={cx("fw-bold", "mt-3")}>Advanced settings</h3>
134134

135135
<InfoAlert dismissible={false} timeout={0}>
136136
<p className="mb-0">

0 commit comments

Comments
 (0)