Skip to content

Commit b64a23a

Browse files
committed
feat(form): add validation rules and duplicate name check for environment variables
1 parent 8bb93c4 commit b64a23a

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

client/src/components/apps/form.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,9 @@
845845
v-model="envvar.name"
846846
:label="$t('global.name')"
847847
:counter="60"
848+
:rules="getEnvNameRules(envvar.name, index)"
849+
:error="isDuplicateEnvVar(envvar.name, index)"
850+
:error-messages="isDuplicateEnvVar(envvar.name, index) ? [$t('app.form.duplicateEnvVar')] : []"
848851
></v-text-field>
849852
</v-col>
850853
<v-col cols="12" md="6">
@@ -1770,6 +1773,11 @@ export default defineComponent({
17701773
{ title: this.$t('app.form.newValue'), key: 'newValue' },
17711774
];
17721775
},
1776+
duplicateEnvVarNames() {
1777+
const names = this.envVars.map(env => env.name.trim()).filter(name => name !== '');
1778+
const duplicates = names.filter((name, index) => names.indexOf(name) !== index);
1779+
return [...new Set(duplicates)];
1780+
},
17731781
},
17741782
watch: {
17751783
advanced(newValue) {
@@ -2551,6 +2559,25 @@ export default defineComponent({
25512559
}
25522560
}
25532561
},
2562+
isDuplicateEnvVar(name: string, currentIndex: number) {
2563+
if (!name || name.trim() === '') return false;
2564+
const trimmedName = name.trim();
2565+
return this.envVars.some((env, index) =>
2566+
index !== currentIndex && env.name.trim() === trimmedName
2567+
);
2568+
},
2569+
getEnvNameRules(name: string, index: number) {
2570+
const baseRules = [
2571+
(v: any) => !!v || this.$t('app.form.envNameRequired'),
2572+
(v: any) => v.length <= 60 || this.$t('app.form.envNameTooLong'),
2573+
(v: any) => /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v) || this.$t('app.form.envNameInvalidChars'),
2574+
];
2575+
2576+
const duplicateRule = (v: any) =>
2577+
!this.isDuplicateEnvVar(v, index) || this.$t('app.form.duplicateEnvVar');
2578+
2579+
return [...baseRules, duplicateRule];
2580+
},
25542581
addSAAnnotationLine() {
25552582
this.sAAnnotations.push({
25562583
annotation: "",

client/src/locale/de-CH.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ const messages = {
229229
variableName: 'Variable Name',
230230
currentValue: 'Aktuälle Wert',
231231
newValue: 'Neue Wert',
232+
envNameRequired: 'Name vo dr Umgäbigsvariable isch erforderlich',
233+
envNameTooLong: 'Name muess weniger als 60 Zeiche ha',
234+
envNameInvalidChars: 'Nur Buechstabe, Zahle und Underscore erlaubt. Muess mit Buechstab oder Underscore aafange',
235+
duplicateEnvVar: 'Name vo dr Umgäbigsvariable existiert bereits',
232236
},
233237
strategy: {
234238
name: 'Strategie',

client/src/locale/de.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ const messages = {
231231
variableName: 'Variablenname',
232232
currentValue: 'Aktueller Wert',
233233
newValue: 'Neuer Wert',
234+
envNameRequired: 'Name der Umgebungsvariable ist erforderlich',
235+
envNameTooLong: 'Name muss weniger als 60 Zeichen haben',
236+
envNameInvalidChars: 'Nur Buchstaben, Zahlen und Unterstriche erlaubt. Muss mit Buchstaben oder Unterstrich beginnen',
237+
duplicateEnvVar: 'Name der Umgebungsvariable existiert bereits',
234238
},
235239
strategy: {
236240
name: 'Strategie',

client/src/locale/en.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ const messages = {
174174
variableName: 'Variable Name',
175175
currentValue: 'Current Value',
176176
newValue: 'New Value',
177+
envNameRequired: 'Environment variable name is required',
178+
envNameTooLong: 'Name must be less than 60 characters',
179+
envNameInvalidChars: 'Only letters, numbers and underscores allowed. Must start with letter or underscore',
180+
duplicateEnvVar: 'Environment variable name already exists',
177181
},
178182
strategy: {
179183
name: 'Strategy',

client/src/locale/ja.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ const messages = {
230230
variableName: '変数名',
231231
currentValue: '現在の値',
232232
newValue: '新しい値',
233+
envNameRequired: '環境変数名は必須です',
234+
envNameTooLong: '名前は60文字未満である必要があります',
235+
envNameInvalidChars: '文字、数字、アンダースコアのみ使用可能。文字またはアンダースコアで開始する必要があります',
236+
duplicateEnvVar: '環境変数名は既に存在しています',
233237
},
234238
strategy: {
235239
name: '戦略',

client/src/locale/pt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ const messages = {
172172
variableName: 'Nome da Variável',
173173
currentValue: 'Valor Atual',
174174
newValue: 'Novo Valor',
175+
envNameRequired: 'Nome da variável de ambiente é obrigatório',
176+
envNameTooLong: 'Nome deve ter menos de 60 caracteres',
177+
envNameInvalidChars: 'Apenas letras, números e underscore permitidos. Deve começar com letra ou underscore',
178+
duplicateEnvVar: 'Nome da variável de ambiente já existe',
175179
},
176180
strategy: {
177181
name: 'Estratégia',

client/src/locale/zhHans.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ const messages = {
229229
variableName: '变量名',
230230
currentValue: '当前值',
231231
newValue: '新值',
232+
envNameRequired: '环境变量名是必需的',
233+
envNameTooLong: '名称必须少于60个字符',
234+
envNameInvalidChars: '只允许字母、数字和下划线。必须以字母或下划线开头',
235+
duplicateEnvVar: '环境变量名已存在',
232236
},
233237
strategy: {
234238
name: '策略',

0 commit comments

Comments
 (0)