Skip to content

Commit

Permalink
fix(desktop): explicitly set source type now that we have tabs for it
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbreuninger committed May 8, 2024
1 parent e619fec commit 98ebad2
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions desktop/src/client/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const DEVPOD_FLAG_PROVIDER = "--provider"
export const DEVPOD_FLAG_ACCESS_KEY = "--access-key"
export const DEVPOD_FLAG_PREBUILD_REPOSITORY = "--prebuild-repository"
export const DEVPOD_FLAG_ID = "--id"
export const DEVPOD_FLAG_SOURCE = "--source"
export const DEVPOD_FLAG_DEBUG = "--debug"
export const DEVPOD_FLAG_USE = "--use"
export const DEVPOD_FLAG_NAME = "--name"
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/client/workspaces/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export class WorkspacesClient implements TDebuggable {
}

public setDotfilesFlag(dotfilesURL: string): void {
WorkspaceCommands.ADDITIONAL_FLAGS = WorkspaceCommands.ADDITIONAL_FLAGS + " --dotfiles=" + dotfilesURL
WorkspaceCommands.ADDITIONAL_FLAGS =
WorkspaceCommands.ADDITIONAL_FLAGS + " --dotfiles=" + dotfilesURL
}

public setAdditionalFlags(additionalFlags: string): void {
Expand Down
11 changes: 9 additions & 2 deletions desktop/src/client/workspaces/workspaceCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DEVPOD_FLAG_PROVIDER,
DEVPOD_FLAG_RECREATE,
DEVPOD_FLAG_RESET,
DEVPOD_FLAG_SOURCE,
DEVPOD_FLAG_TIMEOUT,
} from "../constants"

Expand Down Expand Up @@ -100,6 +101,13 @@ export class WorkspaceCommands {
const maybeSource = config.sourceConfig?.source
const maybeIDFlag = exists(maybeSource) ? [toFlagArg(DEVPOD_FLAG_ID, id)] : []

const maybeSourceType = config.sourceConfig?.type
const maybeSourceFlag =
exists(maybeSourceType) && exists(maybeSource)
? [toFlagArg(DEVPOD_FLAG_SOURCE, `${maybeSourceType}:${maybeSource}`)]
: []
const identifier = exists(maybeSource) && exists(maybeIDFlag) ? maybeSource : id

const maybeIdeName = config.ideConfig?.name
const maybeIDEFlag = exists(maybeIdeName) ? [toFlagArg(DEVPOD_FLAG_IDE, maybeIdeName)] : []

Expand All @@ -116,8 +124,6 @@ export class WorkspaceCommands {
? [toFlagArg(DEVPOD_FLAG_DEVCONTAINER_PATH, config.devcontainerPath)]
: []

const identifier = exists(maybeSource) && exists(maybeIDFlag) ? maybeSource : id

const additionalFlags =
WorkspaceCommands.ADDITIONAL_FLAGS.length !== 0
? toMultipleFlagArg(WorkspaceCommands.ADDITIONAL_FLAGS)
Expand All @@ -137,6 +143,7 @@ export class WorkspaceCommands {
DEVPOD_COMMAND_UP,
identifier,
...maybeIDFlag,
...maybeSourceFlag,
...maybeIDEFlag,
...maybeProviderFlag,
...maybePrebuildRepositories,
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export type TWorkspaceStatusResult = Readonly<{
provider: TMaybe<string>
state: TMaybe<TWorkspace["status"]>
}>
export type TWorkspaceSourceType = "local" | "git" | "image"
export type TWorkspaceStartConfig = Readonly<{
id: string
prebuildRepositories?: string[]
Expand All @@ -162,6 +163,7 @@ export type TWorkspaceStartConfig = Readonly<{
// Instead of starting a workspace just by ID, the sourceConfig starts it with a `source/ID` combination
sourceConfig?: Readonly<{
source: string
type?: TWorkspaceSourceType
gitBranch: string | undefined
gitCommit: string | undefined
}>
Expand Down
19 changes: 14 additions & 5 deletions desktop/src/views/Workspaces/CreateWorkspace/CreateWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
useColorModeValue,
useToken,
} from "@chakra-ui/react"
import { useCallback, useEffect, useMemo } from "react"
import { useCallback, useEffect, useMemo, useState } from "react"
import { Controller, ControllerRenderProps } from "react-hook-form"
import { useNavigate } from "react-router"
import { Link as RouterLink, useSearchParams } from "react-router-dom"
Expand All @@ -39,7 +39,7 @@ import { Plus } from "../../../icons"
import { CommunitySvg, ProviderPlaceholderSvg } from "../../../images"
import { exists, getKeys, isEmpty, useFormErrors } from "../../../lib"
import { Routes } from "../../../routes"
import { TIDE } from "../../../types"
import { TIDE, TWorkspaceSourceType } from "../../../types"
import { useIDEs } from "../../../useIDEs"
import { useSetupProviderModal } from "../../Providers"
import { ProviderOptionsPopover } from "./ProviderOptionsPopover"
Expand All @@ -61,6 +61,7 @@ export function CreateWorkspace() {
const navigate = useNavigate()
const workspace = useWorkspace(undefined)
const [[providers]] = useProviders()
const [sourceType, setSourceType] = useState<TWorkspaceSourceType>("git")

const handleCreateWorkspace = useCallback(
({
Expand All @@ -81,17 +82,18 @@ export function CreateWorkspace() {
ideConfig: { name: defaultIDE },
sourceConfig: {
source: workspaceSource,
type: sourceType,
gitBranch,
gitCommit,
},
})

// set workspace id to show terminal
// set action id to show terminal
if (!isEmpty(actionID)) {
navigate(Routes.toAction(actionID, Routes.WORKSPACES))
}
},
[navigate, workspace]
[navigate, sourceType, workspace]
)

const {
Expand All @@ -105,6 +107,7 @@ export function CreateWorkspace() {
currentSource,
selectDevcontainerModal,
} = useCreateWorkspaceForm(searchParams, providers, ides, handleCreateWorkspace)

const {
sourceError,
providerError,
Expand Down Expand Up @@ -196,7 +199,13 @@ export function CreateWorkspace() {
name={FieldName.SOURCE}
control={control}
rules={{ required: true }}
render={({ field }) => <WorkspaceSourceInput field={field} />}
render={({ field }) => (
<WorkspaceSourceInput
field={field}
sourceType={sourceType}
onSourceTypeChanged={setSourceType}
/>
)}
/>
</HStack>
{exists(sourceError) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { FiFolder } from "react-icons/fi"
import { useBorderColor } from "../../../Theme"
import { client } from "../../../client"
import { FieldName, TFormValues } from "./types"
import { TWorkspaceSourceType } from "@/types"

// WARN: Make sure these match the regexes in /pkg/git/git.go
const GIT_REPOSITORY_REGEX = new RegExp("^([^@]*(?:git@)?@?[^@/]+\\/[^@/]+(\\/?[^@/]+)){2,}")
Expand Down Expand Up @@ -51,12 +52,30 @@ const ADVANCED_GIT_SETTING_TABS = [
type TAdvancedGitSetting = (typeof AdvancedGitSetting)[keyof typeof AdvancedGitSetting]
const INITIAL_ADVANCED_SETTINGS = { option: AdvancedGitSetting.BRANCH, value: "" }

const SOURCE_TYPE_MAP = {
0: "local",
1: "git",
2: "image",
local: 0,
git: 1,
image: 2,
}
type TWorkspaceSourceInputProps = Readonly<{
field: ControllerRenderProps<TFormValues, (typeof FieldName)["SOURCE"]>
sourceType: TWorkspaceSourceType
onSourceTypeChanged: (type: TWorkspaceSourceType) => void
}>
export function WorkspaceSourceInput({ field }: TWorkspaceSourceInputProps) {
export function WorkspaceSourceInput({
field,
sourceType,
onSourceTypeChanged,
}: TWorkspaceSourceInputProps) {
const inputBackgroundColor = useColorModeValue("white", "black")
const borderColor = useBorderColor()
const typeTabIndex = SOURCE_TYPE_MAP[sourceType]
const handleSourceTypeChanged = (index: number) => {
onSourceTypeChanged(SOURCE_TYPE_MAP[index as 0 | 1 | 2] as TWorkspaceSourceType)
}
const [tabIndex, setTabIndex] = useState(0)
const [advancedGitSettings, setAdvancedGitSettings] =
useState<Readonly<{ option: TAdvancedGitSetting | null; value: string }>>(
Expand Down Expand Up @@ -147,7 +166,7 @@ export function WorkspaceSourceInput({ field }: TWorkspaceSourceInputProps) {
advancedGitSettings.value.length === 0 || !isNaN(parseInt(advancedGitSettings.value))

return (
<Tabs width="90%" variant="muted" defaultIndex={1}>
<Tabs width="90%" variant="muted" index={typeTabIndex} onChange={handleSourceTypeChanged}>
<TabList>
<Tab>Folder</Tab>
<Tab>Git Repo</Tab>
Expand Down
1 change: 0 additions & 1 deletion pkg/image/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func getPodMetadata(token []byte) (string, string, error) {
if err != nil {
return "", "", fmt.Errorf("failed to get claims from kubernetes service account token: %w", err)
}
fmt.Fprintf(os.Stderr, "%+v\n", privateClaims)

kubeClaim := privateClaims.Kubernetes
// get serviceaccount name and imagepullsecret
Expand Down

0 comments on commit 98ebad2

Please sign in to comment.