diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/FormBuilder/FormBuilder.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/FormBuilder/FormBuilder.tsx index 397a797a452..0fb654e7c31 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/FormBuilder/FormBuilder.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/FormBuilder/FormBuilder.tsx @@ -27,7 +27,7 @@ import { isEmpty, isUndefined } from 'lodash'; import { LoadingState } from 'Models'; import React, { FunctionComponent, useEffect, useRef, useState } from 'react'; import { getPipelineServiceHostIp } from 'rest/ingestionPipelineAPI'; -import { customValidate, transformErrors } from 'utils/formUtils'; +import { transformErrors } from 'utils/formUtils'; import { ConfigData } from '../../../interface/service.interface'; import { formatFormDataForRender } from '../../../utils/JSONSchemaFormUtils'; import Loader from '../../Loader/Loader'; @@ -114,7 +114,6 @@ const FormBuilder: FunctionComponent = ({ className={classNames('rjsf', props.className, { 'no-header': !showFormHeader, })} - customValidate={customValidate} formContext={{ handleFocus: onFocus }} formData={localFormData} idSeparator="/" diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/formUtils.test.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/formUtils.test.tsx deleted file mode 100644 index ec8b0783051..00000000000 --- a/openmetadata-ui/src/main/resources/ui/src/utils/formUtils.test.tsx +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2023 Collate. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { FormValidation } from '@rjsf/utils'; -import { customValidate } from './formUtils'; - -describe('customValidate', () => { - it('should add error message when connectionArguments have invalid object keys', () => { - const formData = { - connectionArguments: { - validKey: 'value', - '"invalidKey"': 'value', - }, - connectionOptions: { - option1: 'value', - }, - }; - const errors = { - addError: jest.fn(), - connectionOptions: { - addError: jest.fn(), - }, - connectionArguments: { - addError: jest.fn(), - }, - }; - - customValidate?.(formData, errors as unknown as FormValidation); - - expect(errors.connectionArguments.addError).toHaveBeenCalledWith( - 'message.invalid-object-key' - ); - expect(errors.connectionOptions.addError).not.toHaveBeenCalled(); - }); - - it('should add error message when connectionOptions have invalid object keys', () => { - const formData = { - connectionArguments: { - validKey: 'value', - }, - connectionOptions: { - option1: 'value', - 'invalid Key': 'value', - }, - }; - const errors = { - addError: jest.fn(), - connectionOptions: { - addError: jest.fn(), - }, - connectionArguments: { - addError: jest.fn(), - }, - }; - - customValidate?.(formData, errors as unknown as FormValidation); - - expect(errors.connectionArguments.addError).not.toHaveBeenCalled(); - expect(errors.connectionOptions.addError).toHaveBeenCalledWith( - 'message.invalid-object-key' - ); - }); - - it('should not add error message when all object keys are valid', () => { - const formData = { - connectionArguments: { - validKey1: 'value', - validKey2: 'value', - }, - connectionOptions: { - option1: 'value', - option2: 'value', - }, - }; - const errors = { - connectionArguments: { - addError: jest.fn(), - }, - connectionOptions: { - addError: jest.fn(), - }, - }; - - customValidate?.(formData, errors as unknown as FormValidation); - - expect(errors.connectionArguments.addError).not.toHaveBeenCalled(); - expect(errors.connectionOptions.addError).not.toHaveBeenCalled(); - }); -}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/formUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/formUtils.tsx index 6fcd3182218..7b88f9f935a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/formUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/formUtils.tsx @@ -10,7 +10,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { FormProps } from '@rjsf/core'; import { ErrorTransformer } from '@rjsf/utils'; import { Divider, @@ -34,7 +33,6 @@ import { UserTeamSelectableList } from 'components/common/UserTeamSelectableList import { UserSelectDropdownProps } from 'components/common/UserTeamSelectableList/UserTeamSelectableList.interface'; import SliderWithInput from 'components/SliderWithInput/SliderWithInput'; import { SliderWithInputProps } from 'components/SliderWithInput/SliderWithInput.interface'; -import { VALID_OBJECT_KEY_REGEX } from 'constants/regex.constants'; import { FieldProp, FieldTypes } from 'interface/FormUtils.interface'; import { compact, startCase } from 'lodash'; import TagSuggestion, { @@ -233,31 +231,3 @@ export const transformErrors: ErrorTransformer = (errors) => { return compact(errorRet); }; - -export const customValidate: FormProps['customValidate'] = ( - formData, - errors -) => { - const { connectionArguments = {}, connectionOptions = {} } = formData; - - const connectionArgumentsKeys = Object.keys(connectionArguments); - const connectionOptionsKeys = Object.keys(connectionOptions); - - const connectionArgumentsHasError = connectionArgumentsKeys.some( - (key) => !VALID_OBJECT_KEY_REGEX.test(key) - ); - - const connectionOptionsHasError = connectionOptionsKeys.some( - (key) => !VALID_OBJECT_KEY_REGEX.test(key) - ); - - if (connectionArgumentsHasError && errors?.connectionArguments) { - errors.connectionArguments?.addError(i18n.t('message.invalid-object-key')); - } - - if (connectionOptionsHasError && errors?.connectionOptions) { - errors.connectionOptions?.addError(i18n.t('message.invalid-object-key')); - } - - return errors; -};