Skip to content

Commit

Permalink
wip: add option
Browse files Browse the repository at this point in the history
  • Loading branch information
leafty committed Jan 17, 2025
1 parent f3c1390 commit 278fdec
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
Controller,
FieldErrors,
FieldNamesMarkedBoolean,
UseFormSetValue,
UseFormWatch,
} from "react-hook-form";
import { Collapse, Input, Label, ListGroup } from "reactstrap";
Expand All @@ -50,15 +49,13 @@ interface SessionLauncherFormContentProps {

interface EditLauncherFormContentProps extends SessionLauncherFormContentProps {
environmentId?: string;
setValue: UseFormSetValue<SessionLauncherForm>;
}
export default function EditLauncherFormContent({
control,
errors,
watch,
touchedFields,
environmentId,
setValue,
}: EditLauncherFormContentProps) {
const {
data: environments,
Expand Down Expand Up @@ -221,7 +218,7 @@ export default function EditLauncherFormContent({
)}
/>
</div>
<EnvironmentKindField control={control} setValue={setValue} />
<EnvironmentKindField control={control} />

{environmentKind === "GLOBAL" && renderEnvironmentList()}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function EnvironmentFields({
<span className="fw-bold">1 of 2. Define environment</span>
</div>
<div>
<EnvironmentKindField control={control} setValue={setValue} />
<EnvironmentKindField control={control} />
</div>
<div className={cx(watchEnvironmentKind !== "GLOBAL" && "d-none")}>
<GlobalEnvironmentFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
* limitations under the License.
*/
import cx from "classnames";
import { Control, Controller, UseFormSetValue } from "react-hook-form";
import { Button, ButtonGroup } from "reactstrap";
import { Control, Controller } from "react-hook-form";
import { ButtonGroup } from "reactstrap";
import { SessionLauncherForm } from "../../sessionsV2.types";

interface EnvironmentKindField {
control: Control<SessionLauncherForm, unknown>;
setValue: UseFormSetValue<SessionLauncherForm>;
control: Control<SessionLauncherForm>;
}
export default function EnvironmentKindField({
control,
setValue,
}: EnvironmentKindField) {
return (
<Controller
Expand All @@ -35,30 +33,56 @@ export default function EnvironmentKindField({
render={({ field }) => (
<div className={cx("d-flex", "gap-4")}>
<ButtonGroup size="sm">
<Button
active={field.value === "GLOBAL"}
data-cy="existing-global-button"
onClick={() => setValue("environment_kind", "GLOBAL")}
className={cx(
field.value === "GLOBAL"
? ["text-white", "bg-primary"]
: ["text-primary", "bg-white"]
)}
<input
type="radio"
className="btn-check"
name={field.name}
autoComplete="off"
checked={field.value === "GLOBAL"}
id="environment-kind-global-radio"
onChange={() => field.onChange("GLOBAL")}
onBlur={field.onBlur}
/>
<label
className={cx("btn", "btn-outline-primary")}
htmlFor="environment-kind-global-radio"
>
Global environment
</Button>
<Button
active={field.value === "CUSTOM"}
data-cy="existing-custom-button"
onClick={() => setValue("environment_kind", "CUSTOM")}
className={cx(
field.value === "CUSTOM"
? ["text-white", "bg-primary"]
: ["text-primary", "bg-white"]
)}
</label>

<input
type="radio"
className="btn-check"
name={field.name}
autoComplete="off"
checked={field.value === "CUSTOM"}
id="environment-kind-custom-radio"
onChange={() => field.onChange("CUSTOM")}
onBlur={field.onBlur}
/>
<label
className={cx("btn", "btn-outline-primary")}
htmlFor="environment-kind-custom-radio"
>
Custom Environment
</Button>
</label>

<input
type="radio"
className="btn-check"
name={field.name}
autoComplete="off"
checked={field.value === "BUILDER"}
id="environment-kind-builder-radio"
onChange={() => field.onChange("BUILDER")}
onBlur={field.onBlur}
/>
<label
className={cx("btn", "btn-outline-primary")}
htmlFor="environment-kind-builder-radio"
>
Create from a repository
</label>
</ButtonGroup>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export default function UpdateSessionLauncherModal({
watch={watch}
touchedFields={touchedFields}
environmentId={launcher.environment?.id}
setValue={setValue}
/>
</Form>
)}
Expand Down

0 comments on commit 278fdec

Please sign in to comment.