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

[MD] Validate length of title to be no longer than 32 characters #6452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious whether title could be undefined. If yes, then calling trim function will throw exception. If no, then there is no concern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title will not be undefined, it's initialized with empty string
that's why in the function param, we didn't declare it to be optional param

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
Loading