Skip to content
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

fix: Validation when creating a new data model #14049

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
101657f
Move validation logic into hook
ErlingHauan Nov 11, 2024
71222a1
Remove period and space from regex
ErlingHauan Nov 11, 2024
289aeb4
Add separate case for empty name
ErlingHauan Nov 11, 2024
e554177
Rename createNewOpen --> isCreateNewOpen
ErlingHauan Nov 11, 2024
60dd1d5
Clear error on reopened popover, and autofocus input field
ErlingHauan Nov 11, 2024
718d122
Add check for max length
ErlingHauan Nov 11, 2024
8b0fa8e
Add check for C# reserved keyword
ErlingHauan Nov 12, 2024
4706506
Write tests for useValidateSchemaName
ErlingHauan Nov 13, 2024
f9c3df6
Update text resources
ErlingHauan Nov 13, 2024
099eff3
Fix bug where invalid model could be created with enter key
ErlingHauan Nov 14, 2024
9b5f3dd
Move hooks into 'hooks' folder
ErlingHauan Nov 14, 2024
c9864ae
Merge branch 'main' into 13364-validation-issues-when-creating-a-new-…
ErlingHauan Nov 14, 2024
539a955
Fix PR comments
ErlingHauan Nov 18, 2024
d655960
Merge branch 'main' into 13364-validation-issues-when-creating-a-new-…
ErlingHauan Nov 18, 2024
8a9b1ab
Fix type import
ErlingHauan Nov 18, 2024
8786bf9
Merge branch '13364-validation-issues-when-creating-a-new-model' of h…
ErlingHauan Nov 18, 2024
3f8917b
Add test case for " " and "."
ErlingHauan Nov 18, 2024
d3cda35
Remove Norwegian characters from test for '-', '_'
ErlingHauan Nov 18, 2024
e6c7bc9
Update reserved keyword text
ErlingHauan Nov 19, 2024
59613fc
Update text for schema_editor.enum_empty
ErlingHauan Nov 19, 2024
60d56d1
Fix most PR comments
ErlingHauan Nov 19, 2024
adfad0d
Fix datamodel landing page spacing
ErlingHauan Nov 19, 2024
2317835
Remove dataModels parameter from useValidateSchemaName
ErlingHauan Nov 20, 2024
454c681
Memoize result of mergeJsonAndXsdData
ErlingHauan Nov 20, 2024
2c0e044
Merge branch '13364-validation-issues-when-creating-a-new-model' of h…
ErlingHauan Nov 20, 2024
8b7b717
Fix test
ErlingHauan Nov 20, 2024
cf8db9d
Fix TopToolbar test by adding query data for JSON and XSD models
ErlingHauan Nov 20, 2024
a89ae52
Remove fetching of data model names and data type names from useValid…
ErlingHauan Nov 21, 2024
66b9b89
Add tests for extractDataTypeNamesFromAppMetadata
ErlingHauan Nov 21, 2024
392939b
Remove data model query mocks from TopToolbar tests
ErlingHauan Nov 21, 2024
9294019
Remove unused import
ErlingHauan Nov 21, 2024
cc349d6
Fix linting error
ErlingHauan Nov 21, 2024
a38fdf0
Refactoring
ErlingHauan Nov 22, 2024
b5363a5
Fix import paths in XSDUpload test
ErlingHauan Nov 22, 2024
fcc0e6a
Change folder structure
ErlingHauan Nov 22, 2024
a1014bc
Merge main to branch
ErlingHauan Nov 22, 2024
559753c
Move DATA_MODEL_NAME_MAX_LENGTH into the hook where it is used
ErlingHauan Nov 22, 2024
e3e6531
Make extractDataTypeNamesFromAppMetadata more concise
ErlingHauan Nov 26, 2024
59067e8
Merge branch 'main' into 13364-validation-issues-when-creating-a-new-…
ErlingHauan Nov 26, 2024
32cb739
Disallow Norwegian characters in name
ErlingHauan Nov 29, 2024
4a34646
Merge branch 'main' into 13364-validation-issues-when-creating-a-new-…
ErlingHauan Nov 29, 2024
a48ebcf
Fix PR comments
ErlingHauan Nov 29, 2024
2ab7e81
Fix type error
ErlingHauan Nov 29, 2024
0eff4c7
Move expect inside for loop
ErlingHauan Nov 29, 2024
a8cdd9a
Merge branch 'main' into 13364-validation-issues-when-creating-a-new-…
JamalAlabdullah Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@
"schema_editor.error_data_type_name_exists": "Modellen kan ikke ha samme navn som datatyper i løsningen.",
"schema_editor.error_depth": "Du kan ikke plassere denne gruppen her, fordi skjemaet får for mange nivåer.",
"schema_editor.error_invalid_child": "Du kan ikke plassere denne komponenttypen i denne gruppen.",
"schema_editor.error_invalid_datamodel_name": "Navnet er ugyldig. Det første tegnet må være en stor eller liten bokstav fra a til z. Deretter kan du bruke små eller store bokstaver fra a til å, tall, understrek og bindestrek.",
"schema_editor.error_invalid_datamodel_name": "Navnet er ugyldig. Det første tegnet må være en stor eller liten bokstav fra a til z. Deretter kan du bruke små eller store bokstaver, tall, understrek og bindestrek.",
standeren marked this conversation as resolved.
Show resolved Hide resolved
"schema_editor.error_model_name_exists": "Modellnavnet {{newModelName}} er allerede i bruk.",
"schema_editor.error_reserved_keyword": "Systemet bruker allerede dette navnet. Velg et annet navn.",
"schema_editor.error_upload_data_model_id_exists_override_option": "Det finnes allerede en datamodell med dette navnet. Vil du overskrive den?",
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/shared/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export const PROTECTED_TASK_NAME_CUSTOM_RECEIPT = 'CustomReceipt';
export const PREVIEW_MOCK_PARTY_ID = '51001';
export const PREVIEW_MOCK_INSTANCE_GUID = 'f1e23d45-6789-1bcd-8c34-56789abcdef0';
export const MEDIA_QUERY_MAX_WIDTH = '(max-width: 1024px)';
export const DATA_MODEL_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_\-æÆøØåÅ]*$/;
export const DATA_MODEL_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_\-]*$/;
35 changes: 10 additions & 25 deletions frontend/packages/shared/src/hooks/useValidateSchemaName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,6 @@ describe('useValidateSchemaName', () => {
});

describe('regular expressions', () => {
it('should disallow Norwegian characters at start of name', () => {
const { result } = renderUseValidateSchemaName();
const invalidFirstCharacters = ['æ', 'ø', 'å', 'Æ', 'Ø', 'Å'];

invalidFirstCharacters.forEach((char) => {
act(() => {
result.current.validateName(char);
});

expect(result.current.nameError).toBe(
textMock('schema_editor.error_invalid_datamodel_name'),
);
});
});

it('should allow Norwegian characters in rest of name', () => {
const { result } = renderUseValidateSchemaName();

act(() => {
result.current.validateName('aÆØÅæøå');
});

expect(result.current.nameError).toBe('');
});

it('should disallow numbers at start of name', () => {
const { result } = renderUseValidateSchemaName();
const invalidFirstCharacters = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
Expand Down Expand Up @@ -178,6 +153,16 @@ describe('useValidateSchemaName', () => {
);
});
});

it('should disallow Norwegian characters in name', () => {
const { result } = renderUseValidateSchemaName();

act(() => {
result.current.validateName('aÆØÅæøå');
standeren marked this conversation as resolved.
Show resolved Hide resolved
});

expect(result.current.nameError).toBe(textMock('schema_editor.error_invalid_datamodel_name'));
});
});
});

Expand Down
Loading