validation on Select field (#8316)

fix #8204
I changed "API keys" to "API values".
Stopped inputting special characters in Select field option keys.

@lucasbordeau please check the changes and tell me if I need to do any
other changes. :)

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
Ketan Mehta
2024-11-14 22:16:18 +05:30
committed by GitHub
parent 15b8b9b158
commit 51c54d4c5b
22 changed files with 96 additions and 204 deletions

View File

@ -1,9 +1,22 @@
import { METADATA_NAME_VALID_PATTERN } from '~/pages/settings/data-model/constants/MetadataNameValidPattern';
import { transliterateAndFormatOrThrow } from '~/pages/settings/data-model/utils/transliterate-and-format.utils';
import camelCase from 'lodash.camelcase';
import { slugify } from 'transliteration';
export const computeMetadataNameFromLabelOrThrow = (label: string): string => {
if (label === '') {
export const computeMetadataNameFromLabel = (label: string): string => {
const prefixedLabel = /^\d/.test(label) ? `n${label}` : label;
if (prefixedLabel === '') {
return '';
}
return transliterateAndFormatOrThrow(label, METADATA_NAME_VALID_PATTERN);
const formattedString = slugify(prefixedLabel, {
trim: true,
separator: '_',
allowedChars: 'a-zA-Z0-9',
});
if (formattedString === '') {
throw new Error('Invalid label');
}
return camelCase(formattedString);
};