Skip to content

Commit

Permalink
fix(desktop): reconfigure provider options when changing suboptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbreuninger committed Jun 12, 2024
1 parent bb2f25d commit 4d68996
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions desktop/src/client/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const DEVPOD_FLAG_USE = "--use"
export const DEVPOD_FLAG_NAME = "--name"
export const DEVPOD_FLAG_SINGLE_MACHINE = "--single-machine"
export const DEVPOD_FLAG_DRY = "--dry"
export const DEVPOD_FLAG_RECONFIGURE = "--reconfigure"
export const DEVPOD_FLAG_SKIP_REQUIRED = "--skip-required"
export const DEVPOD_FLAG_TIMEOUT = "--timeout"
export const DEVPOD_FLAG_DEVCONTAINER_PATH = "--devcontainer-path"
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/client/providers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export class ProvidersClient implements TDebuggable {

public async setOptionsDry(
id: TProviderID,
{ options }: TConfigureProviderConfig
{ options, reconfigure }: TConfigureProviderConfig
): Promise<Result<TProviderOptions | undefined>> {
return ProviderCommands.SetProviderOptions(id, options, false, true)
return ProviderCommands.SetProviderOptions(id, options, false, true, reconfigure)
}

public async configure(
Expand Down
6 changes: 5 additions & 1 deletion desktop/src/client/providers/providerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DEVPOD_FLAG_JSON_LOG_OUTPUT,
DEVPOD_FLAG_JSON_OUTPUT,
DEVPOD_FLAG_NAME,
DEVPOD_FLAG_RECONFIGURE,
DEVPOD_FLAG_SINGLE_MACHINE,
DEVPOD_FLAG_USE,
} from "../constants"
Expand Down Expand Up @@ -153,11 +154,13 @@ export class ProviderCommands {
id: TProviderID,
rawOptions: Record<string, unknown>,
reuseMachine: boolean,
dry?: boolean
dry?: boolean,
reconfigure?: boolean
) {
const optionsFlag = serializeRawOptions(rawOptions)
const maybeResuseMachineFlag = reuseMachine ? [DEVPOD_FLAG_SINGLE_MACHINE] : []
const maybeDry = dry ? [DEVPOD_FLAG_DRY] : []
const maybeReconfigure = reconfigure ? [DEVPOD_FLAG_RECONFIGURE] : []

const result = await ProviderCommands.newCommand([
DEVPOD_COMMAND_PROVIDER,
Expand All @@ -166,6 +169,7 @@ export class ProviderCommands {
...optionsFlag,
...maybeResuseMachineFlag,
...maybeDry,
...maybeReconfigure,
DEVPOD_FLAG_JSON_LOG_OUTPUT,
]).run()
if (result.err) {
Expand Down
1 change: 1 addition & 0 deletions desktop/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export type TConfigureProviderConfig = Readonly<{
options: Record<string, string>
useAsDefaultProvider?: boolean
reuseMachine?: boolean
reconfigure?: boolean
}>
export type TProviderManager = Readonly<{
remove: TRunnable<TWithProviderID> &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,24 +393,24 @@ function ConfigureOptionsForm({
}

function stripOptionChildren(
configuredOptions: { [key: string]: string },
optionsProp: TProviderOptions | undefined,
configuredOptions: Record<string, string>,
allOptions: TProviderOptions | undefined,
id: string
) {
// filter children
optionsProp?.[id]?.children?.forEach((child) => {
allOptions?.[id]?.children?.forEach((child) => {
delete configuredOptions[child]
stripOptionChildren(configuredOptions, optionsProp, child)
stripOptionChildren(configuredOptions, allOptions, child)
})
}

function filterOptions(
configuredOptions: TFieldValues,
optionsProp: TProviderOptions | undefined
allOptions: TProviderOptions | undefined
): Record<string, string> {
const newOptions: Record<string, string> = {}
Object.keys(configuredOptions).forEach((option) => {
if (exists(configuredOptions[option]) && exists(optionsProp?.[option])) {
if (exists(configuredOptions[option]) && exists(allOptions?.[option])) {
newOptions[option] = configuredOptions[option] + ""
}
})
Expand All @@ -429,7 +429,9 @@ function useOptions(
const { data: queryOptions, error: queryError } = useQuery<TProviderOptions | undefined, Error>({
queryKey: QueryKeys.providerSetOptions(providerID),
queryFn: async () => {
return (await client.providers.setOptionsDry(providerID, { options: {} })).unwrap()
return (
await client.providers.setOptionsDry(providerID, { options: {}, reconfigure: false })
).unwrap()
},
})

Expand All @@ -450,7 +452,10 @@ function useOptions(
}

return (
await client.providers.setOptionsDry(providerID, { options: filteredOptions })
await client.providers.setOptionsDry(providerID, {
options: filteredOptions,
reconfigure: true,
})
).unwrap()
},
onSuccess(data) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/options/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func ResolveOptions(
// loop and resolve options, as soon as we encounter a new dynamic option it will get filled
resolvedOptionValues, dynamicOptionDefinitions, err := resolve.Resolve(
ctx,
devConfig.DynamicProviderOptionDefinitions(provider.Name),
nil,
provider.Options,
devConfig.ProviderOptions(provider.Name),
)
Expand Down

0 comments on commit 4d68996

Please sign in to comment.