-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validation on Select field #8316
Merged
FelixMalfait
merged 9 commits into
twentyhq:main
from
ketanMehtaa:change_label_API_keys_To_API_values
Nov 14, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0b9ad92
changed api keys to api values
ketanMehtaa 9be6cb6
Merge branch 'main' of https://github.com/ketanMehtaa/twenty into cha…
ketanMehtaa a27d0fc
Improve algo
FelixMalfait 57b3924
Improve
FelixMalfait 2442146
Merge branch 'main' into change_label_API_keys_To_API_values
FelixMalfait 4701a8d
Backend fix
FelixMalfait 010cf80
PR Comments
FelixMalfait 27670b2
Big rename
FelixMalfait 0520c84
Fix test
FelixMalfait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the label value