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

EPMRPP-87023 || No UI validation on Create/Edit Gitlab integration modals when user enters non-digits in project ID field #3

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
3 changes: 2 additions & 1 deletion ui/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"react/prop-types": "off"
"react/prop-types": "off",
"no-else-return": "off"
},
"settings": {
"import/resolver": {
Expand Down
20 changes: 16 additions & 4 deletions ui/src/components/integrationFormFields/integrationFormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ const INTEGRATION_NAME = 'integrationName';
const URL = 'url';
const PROJECT = 'project';
const API_TOKEN = 'apiToken';
const MAX_LENGTH = 55;

const projectIdValidator =
(requiredFieldValidator: (value: string) => string | undefined) => (value: string) => {
if (requiredFieldValidator(value)) {
return `Project ID should have length from 1 to ${MAX_LENGTH}`;
} else if (!value.match(/^\d+$/)) {
return 'Project ID should contain only digits';
} else {
return undefined;
}
};

export const IntegrationFormFields: FC<IntegrationFormFieldsInterface> = (props) => {
const { initialize, disabled, lineAlign, initialData, updateMetaData, ...extensionProps } = props;
const {
components: { FieldErrorHint, FieldElement, FieldText, FieldTextFlex },
validators: { requiredField, btsUrl, btsProjectId, btsIntegrationName },
validators: { requiredField, btsUrl, btsIntegrationName },
constants: { SECRET_FIELDS_KEY },
} = extensionProps;

Expand All @@ -33,7 +45,7 @@ export const IntegrationFormFields: FC<IntegrationFormFieldsInterface> = (props)
isRequired
>
<FieldErrorHint provideHint={false}>
<FieldText maxLength={55} defaultWidth={false} />
<FieldText maxLength={MAX_LENGTH} defaultWidth={false} />
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to remove maxLength property for the fields as discussed previously?
In case it is set, user input will be cut while doing copy-paste.
Discuss with BA.

</FieldErrorHint>
</FieldElement>
<FieldElement name={URL} label={LABELS.URL} validate={btsUrl} disabled={disabled} isRequired>
Expand All @@ -44,12 +56,12 @@ export const IntegrationFormFields: FC<IntegrationFormFieldsInterface> = (props)
<FieldElement
name={PROJECT}
label={LABELS.PROJECT}
validate={btsProjectId}
validate={projectIdValidator(requiredField)}
disabled={disabled}
isRequired
>
<FieldErrorHint provideHint={false}>
<FieldText maxLength={55} defaultWidth={false} />
<FieldText maxLength={MAX_LENGTH} defaultWidth={false} />
</FieldErrorHint>
</FieldElement>
<FieldElement
Expand Down