From 64ea71abc5ea9a80de6829b2f49ec25e1f851c7c Mon Sep 17 00:00:00 2001 From: Zhongnan Su Date: Mon, 15 Apr 2024 06:54:23 +0000 Subject: [PATCH] [MD] Validate length of title to be less or equal than 32 characters Signed-off-by: Zhongnan Su --- CHANGELOG.md | 1 + .../validation/datasource_form_validation.test.ts | 5 +++++ .../components/validation/datasource_form_validation.ts | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc9b07e9665..2c823709af2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,6 +119,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [BUG][Multiple Datasource] Refactor read-only component to cover more edge cases ([#6416](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6416)) - [BUG] Fix for checkForFunctionProperty so that order does not matter ([#6248](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6248)) - [BUG][Multiple Datasource] Validation succeed as long as status code in response is 200 ([#6399](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6399)) +- [BUG][Multiple Datasource] Add validation for title length to be no longer than 32 characters [#6452](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6452)) ### 🚞 Infrastructure 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 d0ef842ad4f..7b92a355e90 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 32c87fbee7d..c3a7f78db2c 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) &&