Skip to content

Commit 112e81a

Browse files
PRTTMPRPHTpascalbreuninger
authored andcommitted
feat: Add selection of runner to DevPod Pro workspace creation flow
1 parent 919e30a commit 112e81a

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

desktop/src/views/Pro/CreateWorkspace/CreateWorkspace.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ async function buildWorkspaceInstance(
146146
name: template,
147147
version: templateVersion,
148148
}
149+
150+
instance.spec.runnerRef = {
151+
runner: values.runner,
152+
}
153+
149154
try {
150155
instance.spec.parameters = jsyaml.dump(parameters)
151156
} catch (err) {

desktop/src/views/Pro/CreateWorkspace/CreateWorkspaceForm.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BottomActionBar, BottomActionBarError, Form } from "@/components"
2-
import { ProWorkspaceInstance } from "@/contexts"
2+
import { ProWorkspaceInstance, useProjectClusters } from "@/contexts"
33
import { Code, Laptop, Parameters } from "@/icons"
44
import {
55
Annotations,
@@ -33,6 +33,7 @@ import { OptionsInput } from "./OptionsInput"
3333
import { SourceInput } from "./SourceInput"
3434
import { FieldName, TFormValues } from "./types"
3535
import { useTemplates } from "@/contexts"
36+
import { RunnerInput } from "@/views/Pro/CreateWorkspace/RunnerInput"
3637

3738
type TCreateWorkspaceFormProps = Readonly<{
3839
instance?: ProWorkspaceInstance
@@ -52,9 +53,18 @@ export function CreateWorkspaceForm({
5253
const containerRef = useRef<HTMLDivElement>(null)
5354
const { ides, defaultIDE } = useIDEs()
5455
const { data: templates, isLoading: isTemplatesLoading } = useTemplates()
56+
57+
const { data: projectClusterData, isLoading: projectClusterDataLoading } = useProjectClusters()
58+
5559
const form = useForm<TFormValues>({ mode: "onChange", defaultValues })
56-
const { sourceError, defaultIDEError, nameError, devcontainerJSONError, optionsError } =
57-
useFormErrors(Object.values(FieldName), form.formState)
60+
const {
61+
sourceError,
62+
defaultIDEError,
63+
nameError,
64+
devcontainerJSONError,
65+
optionsError,
66+
runnerError,
67+
} = useFormErrors(Object.values(FieldName), form.formState)
5868

5969
useEffect(() => {
6070
if (!form.getFieldState(FieldName.DEFAULT_IDE).isDirty && defaultIDE && defaultIDE.name) {
@@ -108,6 +118,26 @@ export function CreateWorkspaceForm({
108118
</CreateWorkspaceRow>
109119
</FormControl>
110120

121+
<FormControl isDisabled={!!instance} isRequired isInvalid={exists(runnerError)}>
122+
<CreateWorkspaceRow
123+
label={
124+
<FormLabel>
125+
<Code boxSize={5} mr="1" />
126+
Runner
127+
</FormLabel>
128+
}>
129+
{projectClusterDataLoading ? (
130+
<Spinner />
131+
) : (
132+
<RunnerInput runners={projectClusterData?.runners} />
133+
)}
134+
135+
{exists(runnerError) && (
136+
<FormErrorMessage>{runnerError.message ?? "Error"}</FormErrorMessage>
137+
)}
138+
</CreateWorkspaceRow>
139+
</FormControl>
140+
111141
<FormControl isInvalid={exists(defaultIDEError)}>
112142
<CreateWorkspaceRow
113143
label={
@@ -226,6 +256,7 @@ function getDefaultValues(
226256
}
227257
const defaultValues: DefaultValues<TFormValues> = {
228258
defaultIDE: instance.status?.ide?.name ?? "none",
259+
runner: instance.spec?.runnerRef?.runner,
229260
}
230261

231262
// source
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useFormContext } from "react-hook-form"
2+
import { FieldName, TFormValues } from "@/views/Pro/CreateWorkspace/types"
3+
import { Select } from "@chakra-ui/react"
4+
import { ManagementV1Runner } from "@loft-enterprise/client/gen/models/managementV1Runner"
5+
6+
export function RunnerInput({ runners }: { runners: readonly ManagementV1Runner[] | undefined }) {
7+
const { register } = useFormContext<TFormValues>()
8+
9+
return (
10+
<Select {...register(FieldName.RUNNER)}>
11+
{runners?.map((r, index) => (
12+
<option key={index} value={r.metadata?.name}>
13+
{r.spec?.displayName ?? r.metadata?.name}
14+
</option>
15+
))}
16+
</Select>
17+
)
18+
}

desktop/src/views/Pro/CreateWorkspace/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const FieldName = {
55
SOURCE_TYPE: "sourceType",
66
NAME: "name",
77
DEFAULT_IDE: "defaultIDE",
8+
RUNNER: "runner",
89
DEVCONTAINER_JSON: "devcontainerJSON",
910
DEVCONTAINER_TYPE: "devcontainerType",
1011
OPTIONS: "options",
@@ -16,6 +17,7 @@ export type TFormValues = {
1617
[FieldName.DEFAULT_IDE]: string
1718
[FieldName.NAME]: string
1819
[FieldName.DEVCONTAINER_JSON]: string
20+
[FieldName.RUNNER]: string
1921
[FieldName.DEVCONTAINER_TYPE]: TDevContainerType
2022
[FieldName.OPTIONS]: TOptions
2123
}

0 commit comments

Comments
 (0)