From 27409218a08c9bd23bfe88f7b869c7cd86f571ef Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:06:31 -0700 Subject: [PATCH] [MD] Validate length of title to be less or equal than 32 characters (#6452) (#6476) Signed-off-by: Zhongnan Su (cherry picked from commit 236ec4e2f2315555cb0b86f13f67ecde078eae25) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] --- .../validation/datasource_form_validation.test.ts | 5 +++++ .../components/validation/datasource_form_validation.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts index d0ef842ad4f5..7b92a355e908 100644 --- a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts +++ b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.test.ts @@ -40,6 +40,11 @@ describe('DataSourceManagement: Form Validation', () => { ); expect(result).toBe(false); }); + test('should fail validation when title is longer than 32 characters', () => { + form.title = 'test'.repeat(10); + const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry); + expect(result).toBe(false); + }); test('should fail validation when endpoint is not valid', () => { form.endpoint = mockDataSourceAttributesWithAuth.endpoint; const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry); diff --git a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts index 32c87fbee7d1..c3a7f78db2cb 100644 --- a/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts +++ b/src/plugins/data_source_management/public/components/validation/datasource_form_validation.ts @@ -50,8 +50,14 @@ export const isTitleValid = ( error: '', }; /* Title validation */ - if (!title?.trim?.().length) { + if (!title.trim().length) { isValid.valid = false; + } else if (title.length > 32) { + /* title length validation */ + isValid.valid = false; + isValid.error = i18n.translate('dataSourcesManagement.validation.titleLength', { + defaultMessage: 'Title must be no longer than 32 characters', + }); } else if ( title.toLowerCase() !== existingTitle.toLowerCase() && Array.isArray(existingDatasourceNamesList) &&