Skip to content

Commit

Permalink
[MD] Validate length of title to be less or equal than 32 characters
Browse files Browse the repository at this point in the history
Signed-off-by: Zhongnan Su <szhongna@amazon.com>
  • Loading branch information
zhongnansu committed Apr 16, 2024
1 parent ce85706 commit 043f98c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down

0 comments on commit 043f98c

Please sign in to comment.