chore: remove validation for connection option and arguments from json schema form (#12881)

This commit is contained in:
Sachin Chaurasiya 2023-08-16 12:53:38 +05:30 committed by GitHub
parent a183fc67e2
commit a74e5bf217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 130 deletions

View File

@ -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<Props> = ({
className={classNames('rjsf', props.className, {
'no-header': !showFormHeader,
})}
customValidate={customValidate}
formContext={{ handleFocus: onFocus }}
formData={localFormData}
idSeparator="/"

View File

@ -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();
});
});

View File

@ -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;
};