-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
15b8b9b
commit 51c54d4
Showing
22 changed files
with
96 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
...s/settings/data-model/fields/forms/select/utils/__tests__/getOptionValueFromLabel.test.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
...ront/src/modules/settings/data-model/fields/forms/select/utils/getOptionValueFromLabel.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...ont/src/modules/settings/data-model/validation-schemas/settingsCreateObjectInputSchema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import { settingsDataModelObjectAboutFormSchema } from '@/settings/data-model/objects/forms/components/SettingsDataModelObjectAboutForm'; | ||
import { CreateObjectInput } from '~/generated-metadata/graphql'; | ||
import { computeMetadataNameFromLabelOrThrow } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils'; | ||
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils'; | ||
|
||
export const settingsCreateObjectInputSchema = | ||
settingsDataModelObjectAboutFormSchema.transform<CreateObjectInput>( | ||
(values) => ({ | ||
...values, | ||
nameSingular: | ||
values.nameSingular ?? | ||
computeMetadataNameFromLabelOrThrow(values.labelSingular), | ||
computeMetadataNameFromLabel(values.labelSingular), | ||
namePlural: | ||
values.namePlural ?? | ||
computeMetadataNameFromLabelOrThrow(values.labelPlural), | ||
values.namePlural ?? computeMetadataNameFromLabel(values.labelPlural), | ||
isLabelSyncedWithName: values.isLabelSyncedWithName ?? true, | ||
}), | ||
); |
2 changes: 1 addition & 1 deletion
2
packages/twenty-front/src/pages/settings/data-model/constants/MetadataLabelValidPattern.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const METADATA_LABEL_VALID_PATTERN = /^[^0-9].*$/; | ||
export const METADATA_LABEL_VALID_PATTERN = /^.*$/; |
2 changes: 1 addition & 1 deletion
2
packages/twenty-front/src/pages/settings/data-model/constants/OptionValueValidPattern.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const OPTION_VALUE_VALID_PATTERN = /^[a-zA-Z0-9]+$/; | ||
export const OPTION_VALUE_VALID_PATTERN = /^[A-Z_][A-Z0-9_]*$/; |
22 changes: 2 additions & 20 deletions
22
...nt/src/pages/settings/data-model/utils/__tests__/compute-metadata-name-from-label.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
import { computeMetadataNameFromLabelOrThrow } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils'; | ||
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils'; | ||
|
||
describe('computeMetadataNameFromLabel', () => { | ||
it('throws if empty label', () => { | ||
const label = ' '; | ||
|
||
expect(() => computeMetadataNameFromLabelOrThrow(label)).toThrow(); | ||
}); | ||
|
||
it('computes name for 1 char long label', () => { | ||
const label = 'a'; | ||
|
||
expect(computeMetadataNameFromLabelOrThrow(label)).toEqual('a'); | ||
}); | ||
|
||
it('throws if label starts with digits', () => { | ||
const label = '1string'; | ||
|
||
expect(() => computeMetadataNameFromLabelOrThrow(label)).toThrow(); | ||
}); | ||
|
||
it('computes name for label with non-latin char', () => { | ||
const label = 'λλλ!'; | ||
|
||
expect(computeMetadataNameFromLabelOrThrow(label)).toEqual('lll'); | ||
expect(computeMetadataNameFromLabel(label)).toEqual('lll'); | ||
}); | ||
}); |
27 changes: 0 additions & 27 deletions
27
...ont/src/pages/settings/data-model/utils/__tests__/compute-option-value-from-label.test.ts
This file was deleted.
Oops, something went wrong.
23 changes: 18 additions & 5 deletions
23
...wenty-front/src/pages/settings/data-model/utils/compute-metadata-name-from-label.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
Oops, something went wrong.