Fix transliteration for metadata + transliterate select options (#5430)

## Context 
Fixes #5403

Transliteration is now integrated to form validation through the schema.
While it does not impede inputting an invalid value, it impedes
submitting a form that will fail as the transliteration is not possible.
Until then we were only performing the transliteration at save time in
the front-end, but it's best to provide the information as soon as
possible. Later we will add helpers to guide the user (eg "This name is
not valid": https://github.com/twentyhq/twenty/issues/5428).

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Marie
2024-05-15 21:43:58 +02:00
committed by GitHub
parent e9a7a8a4a3
commit 63387424c3
18 changed files with 151 additions and 87 deletions

View File

@ -1,15 +1,14 @@
import snakeCase from 'lodash.snakecase';
export const getOptionValueFromLabel = (label: string) => {
// Remove accents
const unaccentedLabel = label
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '');
// Remove special characters
const noSpecialCharactersLabel = unaccentedLabel.replace(
/[^a-zA-Z0-9 ]/g,
'',
);
import { computeOptionValueFromLabelOrThrow } from '~/pages/settings/data-model/utils/compute-option-value-from-label.utils';
return snakeCase(noSpecialCharactersLabel).toUpperCase();
export const getOptionValueFromLabel = (label: string) => {
let transliteratedLabel = label;
try {
transliteratedLabel = computeOptionValueFromLabelOrThrow(label);
} catch (error) {
return label;
}
return snakeCase(transliteratedLabel).toUpperCase();
};