Skip to content

Commit 2868999

Browse files
committed
[MD] Validate length of title to be less or equal than 32 characters
Signed-off-by: Zhongnan Su <szhongna@amazon.com>
1 parent 476cffc commit 2868999

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ describe('DataSourceManagement: Form Validation', () => {
4040
);
4141
expect(result).toBe(false);
4242
});
43+
test('should fail validation when title is longer than 32 characters', () => {
44+
form.title = 'test'.repeat(10);
45+
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
46+
expect(result).toBe(false);
47+
});
4348
test('should fail validation when endpoint is not valid', () => {
4449
form.endpoint = mockDataSourceAttributesWithAuth.endpoint;
4550
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);

src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const isTitleValid = (
5050
error: '',
5151
};
5252
/* Title validation */
53-
if (!title?.trim?.().length) {
53+
if (!title.trim().length) {
5454
isValid.valid = false;
5555
} else if (
5656
title.toLowerCase() !== existingTitle.toLowerCase() &&
@@ -62,6 +62,12 @@ export const isTitleValid = (
6262
isValid.error = i18n.translate('dataSourcesManagement.validation.titleExists', {
6363
defaultMessage: 'This title is already in use',
6464
});
65+
} else if (title.length > 32) {
66+
/* title length validation */
67+
isValid.valid = false;
68+
isValid.error = i18n.translate('dataSourcesManagement.validation.titleLength', {
69+
defaultMessage: 'Title must be less than 32 characters',
70+
});
6571
}
6672
return isValid;
6773
};

0 commit comments

Comments
 (0)