Skip to content

Commit

Permalink
fix(ui): allow dot in the key of variant (#2887)
Browse files Browse the repository at this point in the history
* fix(ui): allow dot in the key of variant

closes #2882

* fix issues
  • Loading branch information
erka authored Mar 21, 2024
1 parent 8f47c58 commit 3f8e7bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ui/src/components/flags/VariantForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import Loading from '~/components/Loading';
import MoreInfo from '~/components/MoreInfo';
import { useError } from '~/data/hooks/error';
import { useSuccess } from '~/data/hooks/success';
import { jsonValidation, keyValidation } from '~/data/validations';
import { jsonValidation, keyWithDotValidation } from '~/data/validations';
import { IVariant, IVariantBase } from '~/types/Variant';

const variantValidationSchema = Yup.object({
key: keyValidation,
key: keyWithDotValidation,
attachment: jsonValidation
});

Expand Down
13 changes: 12 additions & 1 deletion ui/src/data/validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { contextValidation } from './validations';
import { contextValidation, keyWithDotValidation } from './validations';

describe('contextValidation', () => {
it('should accept valid input', () => {
Expand All @@ -18,3 +18,14 @@ describe('contextValidation', () => {
expect(result).toEqual(false);
});
});

describe('keyWithDotValidation', () => {
it('should accept key with dot', () => {
const result = keyWithDotValidation.isValidSync('2.0');
expect(result).toEqual(true);
});
it('should not accept key with invalid values', () => {
const result = keyWithDotValidation.isValidSync('key]');
expect(result).toEqual(false);
});
});
7 changes: 7 additions & 0 deletions ui/src/data/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export const keyValidation = Yup.string()
'Only letters, numbers, hypens and underscores allowed'
);

export const keyWithDotValidation = Yup.string()
.required('Required')
.matches(
/^[-_,A-Za-z0-9.]+$/,
'Only letters, numbers, hypens, dots and underscores allowed'
);

export const requiredValidation = Yup.string().required('Required');

export const jsonValidation = Yup.string()
Expand Down

0 comments on commit 3f8e7bd

Please sign in to comment.