Skip to content

Commit

Permalink
Merge branch 'develop' into master-to-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
APiankouski authored Dec 20, 2024
2 parents 0ddc53f + 5736aff commit d4152f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useEffect } from 'react';
import { LABELS } from '../constans';
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, btsUrl, btsProjectKey, btsIntegrationName, email },
validators: { requiredField, btsProjectKey, btsIntegrationName, email },
constants: { SECRET_FIELDS_KEY },
} = extensionProps;

Expand Down Expand Up @@ -33,7 +34,7 @@ export const IntegrationFormFields = (props) => {
<FieldElement
name="url"
label={LABELS.URL}
validate={btsUrl}
validate={btsJiraCloudUrl}
disabled={disabled}
isRequired
dataAutomationId="linkToBTSField"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import { LABELS } from '../constans';
import { LABELS } from '../constants';

export const IntegrationSettings = (props) => {
const { data, goToPreviousPage, onUpdate, isGlobal, ...extensionProps } = props;
Expand Down
19 changes: 19 additions & 0 deletions ui/src/components/utils.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit d4152f0

Please sign in to comment.