Skip to content

Commit 4da219d

Browse files
committed
feat: update build infra form to support buildx driver type and adjust submit handling
1 parent 9581b45 commit 4da219d

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/Pages/GlobalConfigurations/BuildInfra/UseBuildInfraForm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ const useBuildInfraForm = ({
331331
const currentInput = structuredClone(profileInput)
332332
const currentInputErrors = structuredClone(profileInputErrors)
333333
const targetPlatform =
334-
'targetPlatform' in data && Object.hasOwn(data, 'targetPlatform') ? data.targetPlatform : ''
334+
data && 'targetPlatform' in data && Object.hasOwn(data, 'targetPlatform') ? data.targetPlatform : ''
335335
const currentConfiguration = currentInput.configurations[targetPlatform]
336336
const lastSavedConfiguration = profileResponse.profile.configurations[targetPlatform] || currentConfiguration
337337

@@ -754,8 +754,8 @@ const useBuildInfraForm = ({
754754
setProfileInputErrors(currentInputErrors)
755755
}
756756

757-
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
758-
e.preventDefault()
757+
const handleSubmit = async (event?: FormEvent<HTMLFormElement>) => {
758+
event?.preventDefault()
759759
// Since considering '' as a valid error message
760760
const hasErrors =
761761
Object.keys(profileInputErrors).filter(

src/Pages/GlobalConfigurations/BuildInfra/types.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,27 @@ export type BuildInfraConfigurationMapTypeWithoutDefaultFallback = {
225225

226226
export type BuildInfraConfigurationMapType = Record<BuildInfraConfigTypes, BuildInfraConfigurationType>
227227

228+
export enum BuildXDriverType {
229+
KUBERNETES = 'kubernetes',
230+
DOCKER_CONTAINER = 'docker-container',
231+
}
232+
228233
interface BuildInfraProfileBaseDTO {
229234
id?: number
230235
name?: string
231236
description: string
232237
type: BuildInfraProfileVariants
233238
appCount?: number
234239
active?: boolean
235-
useK8sDriver?: boolean
240+
/**
241+
* @default `BuildXDriverType.KUBERNETES`
242+
*/
243+
buildxDriverType: BuildXDriverType
236244
}
237245

238-
export interface BuildInfraProfileBase extends BuildInfraProfileBaseDTO {}
246+
export interface BuildInfraProfileBase extends Omit<BuildInfraProfileBaseDTO, 'buildxDriverType'> {
247+
useK8sDriver?: boolean
248+
}
239249

240250
export interface BuildInfraProfileInfoDTO extends BuildInfraProfileBaseDTO {
241251
configurations: BuildInfraPlatformConfigurationMapDTO
@@ -412,7 +422,7 @@ export interface UseBuildInfraFormResponseType {
412422
profileInputErrors: ProfileInputErrorType
413423
handleProfileInputChange: ({ action, data }: HandleProfileInputChangeType) => void
414424
loadingActionRequest: boolean
415-
handleSubmit: (e: FormEvent<HTMLFormElement>) => Promise<void>
425+
handleSubmit: (e?: FormEvent<HTMLFormElement>) => Promise<void>
416426
}
417427

418428
export interface BuildInfraConfigFormProps

src/Pages/GlobalConfigurations/BuildInfra/utils.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
BuildInfraProfileVariants,
3535
BuildInfraToleranceOperatorType,
3636
BuildInfraToleranceValueType,
37+
BuildXDriverType,
3738
CreateBuildInfraProfileType,
3839
GetBaseProfileObjectParamsType,
3940
GetPlatformConfigurationsWithDefaultValuesParamsType,
@@ -112,7 +113,9 @@ const getBaseProfileObject = ({
112113
profile,
113114
canConfigureUseK8sDriver,
114115
}: GetBaseProfileObjectParamsType): BuildInfraProfileBase => {
115-
const parsedUseK8sDriverValue = profile?.useK8sDriver || true
116+
const parsedUseK8sDriverValue = profile.buildxDriverType
117+
? profile.buildxDriverType === BuildXDriverType.KUBERNETES
118+
: true
116119
const useK8sDriver = canConfigureUseK8sDriver ? parsedUseK8sDriverValue : null
117120

118121
if (fromCreateView) {
@@ -335,7 +338,9 @@ export const getBuildInfraProfilePayload = (
335338
type: profileInput.type,
336339
configurations,
337340
...(canConfigureUseK8sDriver && {
338-
useK8sDriver: profileInput.useK8sDriver,
341+
buildxDriverType: profileInput.useK8sDriver
342+
? BuildXDriverType.KUBERNETES
343+
: BuildXDriverType.DOCKER_CONTAINER,
339344
}),
340345
}
341346
return payload

0 commit comments

Comments
 (0)