Skip to content

Commit ebb7c52

Browse files
authored
feat: allow users to define empty env values in builds (#606)
* feat: allow users to define empty env values in builds * fix: improve extra arguments error display * fix: extra arguments value label
1 parent 6896aed commit ebb7c52

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/pages/builds/create-edit/create-edit.validator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { array, boolean, mixed, object, string } from 'yup'
33
const envVarSchema = object({
44
name: string()
55
.required('Environment variable name is required')
6-
.matches(/^[a-zA-Z_][a-zA-Z0-9_]*$/, 'Invalid environment variable name'),
7-
value: string().required('Environment variable value is required'),
6+
.matches(/^-*[a-zA-Z_][a-zA-Z0-9_-]*$/, 'Invalid environment variable name'),
7+
value: string().optional(),
88
})
99

1010
const commonModeSchema = object({

src/pages/builds/create-edit/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ export default function CreateEditBuilds({
150150
}
151151
}
152152

153+
const extraArgumentsError = () => {
154+
const envVarErrors = errors?.mode?.[`${watch('mode.type')}`]?.envVars
155+
if (!envVarErrors) return undefined
156+
const idx = envVarErrors.findIndex((envVar) => envVar?.name?.message)
157+
if (idx === -1) return undefined
158+
const message = envVarErrors[idx]?.name?.message?.toString()
159+
return `Error in argument ${Number(idx) + 1}: ${message}`
160+
}
161+
153162
if (isLoading || isError || (buildName && !watch('name')))
154163
return <PaperLayout loading title={t('TITLE_CONTAINER_IMAGE')} />
155164

@@ -304,11 +313,12 @@ export default function CreateEditBuilds({
304313
title='Extra arguments'
305314
subTitle='Additional arguments to pass on to the build executor'
306315
keyLabel='Name'
307-
valueLabel='Value'
316+
valueLabel='Value (optional)'
308317
addLabel='Add argument'
309318
compressed
310319
name={`mode.${watch('mode.type')}.envVars`}
311320
{...register(`mode.${watch('mode.type')}.envVars`)}
321+
errorText={extraArgumentsError()}
312322
/>
313323

314324
<Divider sx={{ mt: 2, mb: 2 }} />

0 commit comments

Comments
 (0)