From 32dd67a4e6b612f4961318f1e03be41b7df193db Mon Sep 17 00:00:00 2001 From: Siarhei Iukou Date: Thu, 19 Dec 2024 12:12:49 +0300 Subject: [PATCH 1/2] EPMRPP-97895 || Add validation on entered URL --- ui/src/components/{constans.js => constants.js} | 0 .../integrationFormFields/integrationFormFields.jsx | 6 +++--- .../components/integrationSettings/integrationSettings.jsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename ui/src/components/{constans.js => constants.js} (100%) diff --git a/ui/src/components/constans.js b/ui/src/components/constants.js similarity index 100% rename from ui/src/components/constans.js rename to ui/src/components/constants.js diff --git a/ui/src/components/integrationFormFields/integrationFormFields.jsx b/ui/src/components/integrationFormFields/integrationFormFields.jsx index e54f4ae..0d4566d 100644 --- a/ui/src/components/integrationFormFields/integrationFormFields.jsx +++ b/ui/src/components/integrationFormFields/integrationFormFields.jsx @@ -1,11 +1,11 @@ import React, { useEffect } from 'react'; -import { LABELS } from '../constans'; +import { LABELS } from '../constants'; export const IntegrationFormFields = (props) => { const { initialize, disabled, initialData, updateMetaData, ...extensionProps } = props; const { components: { FieldErrorHint, FieldElement, FieldText, FieldTextFlex }, - validators: { requiredField, btsUrl, btsProjectKey, btsIntegrationName, email }, + validators: { requiredField, btsJiraCloudUrl, btsProjectKey, btsIntegrationName, email }, constants: { SECRET_FIELDS_KEY }, } = extensionProps; @@ -33,7 +33,7 @@ export const IntegrationFormFields = (props) => { { const { data, goToPreviousPage, onUpdate, isGlobal, ...extensionProps } = props; From ab071d9dc767e6492f58503b14aa8ea9f97473ad Mon Sep 17 00:00:00 2001 From: Siarhei Iukou Date: Fri, 20 Dec 2024 05:30:54 +0300 Subject: [PATCH 2/2] EPMRPP-97895 || Code Review fix - 1 --- .../integrationFormFields.jsx | 3 ++- ui/src/components/utils.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 ui/src/components/utils.js diff --git a/ui/src/components/integrationFormFields/integrationFormFields.jsx b/ui/src/components/integrationFormFields/integrationFormFields.jsx index 0d4566d..eb68c5d 100644 --- a/ui/src/components/integrationFormFields/integrationFormFields.jsx +++ b/ui/src/components/integrationFormFields/integrationFormFields.jsx @@ -1,11 +1,12 @@ import React, { useEffect } from 'react'; import { LABELS } from '../constants'; +import { btsJiraCloudUrl } from '../utils'; export const IntegrationFormFields = (props) => { const { initialize, disabled, initialData, updateMetaData, ...extensionProps } = props; const { components: { FieldErrorHint, FieldElement, FieldText, FieldTextFlex }, - validators: { requiredField, btsJiraCloudUrl, btsProjectKey, btsIntegrationName, email }, + validators: { requiredField, btsProjectKey, btsIntegrationName, email }, constants: { SECRET_FIELDS_KEY }, } = extensionProps; diff --git a/ui/src/components/utils.js b/ui/src/components/utils.js new file mode 100644 index 0000000..37fecbc --- /dev/null +++ b/ui/src/components/utils.js @@ -0,0 +1,19 @@ +const regex = (regexStr) => (value) => RegExp(regexStr).test(value); +const trimValue = (value) => (typeof value === 'string' ? value.trim() : value); +const isEmpty = (value) => { + const trimmedValue = trimValue(value); + return trimmedValue === '' || trimmedValue === undefined || trimmedValue === null; +}; +const isNotEmpty = (value) => !isEmpty(value); +const composeValidators = (validators) => (value) => + validators.every((validator) => validator(value)); + +const jiraCloudUrl = composeValidators([ + isNotEmpty, + regex(/https:\/\/[^?]*.atlassian.(net|com)\/.*/), +]); + +const bindMessageToValidator = (validator, errorMessage) => (value) => + !validator(value) ? errorMessage : undefined; + +export const btsJiraCloudUrl = bindMessageToValidator(jiraCloudUrl, 'btsUrlHint');