Skip to content

Commit

Permalink
Merge pull request #69 from yuvipanda/prefill-form
Browse files Browse the repository at this point in the history
Pre-select github repo and ref
  • Loading branch information
batpad authored Sep 17, 2024
2 parents 17acdd1 + 15c555b commit 6172e94
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 188 deletions.
22 changes: 19 additions & 3 deletions src/ImageBuilder.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState, useRef } from "react";
import { useEffect, useState, useRef, useContext } from "react";
import Select from "react-select";
import { SpawnerFormContext } from "./state";
import useRepositoryField from "./hooks/useRepositoryField";
import useRefField from "./hooks/useRefField";

Expand Down Expand Up @@ -91,9 +92,17 @@ function ImageLogs({ setTerm, setFitAddon }) {
}

export function ImageBuilder({ name }) {
const {
binderRepo,
ref: repoRef,
setCustomOption,
} = useContext(SpawnerFormContext);
const { repo, repoId, repoFieldProps, repoError, repoIsValidating } =
useRepositoryField();
const { ref, refError, refFieldProps, refIsLoading } = useRefField(repoId);
useRepositoryField(binderRepo);
const { ref, refError, refFieldProps, refIsLoading } = useRefField(
repoId,
repoRef,
);
const repoFieldRef = useRef();
const branchFieldRef = useRef();

Expand All @@ -102,6 +111,13 @@ export function ImageBuilder({ name }) {
const [term, setTerm] = useState(null);
const [fitAddon, setFitAddon] = useState(null);

useEffect(() => {
if (setCustomOption) {
repoFieldRef.current.setAttribute("value", binderRepo);
branchFieldRef.current.value = repoRef;
}
}, [binderRepo, repoRef, setCustomOption]);

const handleBuildStart = async () => {
if (!repo) {
repoFieldRef.current.focus();
Expand Down
2 changes: 2 additions & 0 deletions src/ProfileForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function Form() {
profile: selectedProfile,
setProfile,
profileList,
paramsError,
} = useContext(SpawnerFormContext);
const [formError, setFormError] = useState("");

Expand Down Expand Up @@ -46,6 +47,7 @@ function Form() {
aria-description="First, select the profile; second, configure the options for the selected profile."
>
{formError && <div className="profile-form-error">{formError}</div>}
{paramsError && <div className="profile-form-warning">{paramsError}</div>}
<input
type="radio"
className="hidden"
Expand Down
Loading

0 comments on commit 6172e94

Please sign in to comment.