mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-10 09:31:24 +00:00
chore: remove validation for connection option and arguments from json schema form (#12881)
This commit is contained in:
parent
a183fc67e2
commit
a74e5bf217
@ -27,7 +27,7 @@ import { isEmpty, isUndefined } from 'lodash';
|
|||||||
import { LoadingState } from 'Models';
|
import { LoadingState } from 'Models';
|
||||||
import React, { FunctionComponent, useEffect, useRef, useState } from 'react';
|
import React, { FunctionComponent, useEffect, useRef, useState } from 'react';
|
||||||
import { getPipelineServiceHostIp } from 'rest/ingestionPipelineAPI';
|
import { getPipelineServiceHostIp } from 'rest/ingestionPipelineAPI';
|
||||||
import { customValidate, transformErrors } from 'utils/formUtils';
|
import { transformErrors } from 'utils/formUtils';
|
||||||
import { ConfigData } from '../../../interface/service.interface';
|
import { ConfigData } from '../../../interface/service.interface';
|
||||||
import { formatFormDataForRender } from '../../../utils/JSONSchemaFormUtils';
|
import { formatFormDataForRender } from '../../../utils/JSONSchemaFormUtils';
|
||||||
import Loader from '../../Loader/Loader';
|
import Loader from '../../Loader/Loader';
|
||||||
@ -114,7 +114,6 @@ const FormBuilder: FunctionComponent<Props> = ({
|
|||||||
className={classNames('rjsf', props.className, {
|
className={classNames('rjsf', props.className, {
|
||||||
'no-header': !showFormHeader,
|
'no-header': !showFormHeader,
|
||||||
})}
|
})}
|
||||||
customValidate={customValidate}
|
|
||||||
formContext={{ handleFocus: onFocus }}
|
formContext={{ handleFocus: onFocus }}
|
||||||
formData={localFormData}
|
formData={localFormData}
|
||||||
idSeparator="/"
|
idSeparator="/"
|
||||||
|
@ -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();
|
|
||||||
});
|
|
||||||
});
|
|
@ -10,7 +10,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { FormProps } from '@rjsf/core';
|
|
||||||
import { ErrorTransformer } from '@rjsf/utils';
|
import { ErrorTransformer } from '@rjsf/utils';
|
||||||
import {
|
import {
|
||||||
Divider,
|
Divider,
|
||||||
@ -34,7 +33,6 @@ import { UserTeamSelectableList } from 'components/common/UserTeamSelectableList
|
|||||||
import { UserSelectDropdownProps } from 'components/common/UserTeamSelectableList/UserTeamSelectableList.interface';
|
import { UserSelectDropdownProps } from 'components/common/UserTeamSelectableList/UserTeamSelectableList.interface';
|
||||||
import SliderWithInput from 'components/SliderWithInput/SliderWithInput';
|
import SliderWithInput from 'components/SliderWithInput/SliderWithInput';
|
||||||
import { SliderWithInputProps } from 'components/SliderWithInput/SliderWithInput.interface';
|
import { SliderWithInputProps } from 'components/SliderWithInput/SliderWithInput.interface';
|
||||||
import { VALID_OBJECT_KEY_REGEX } from 'constants/regex.constants';
|
|
||||||
import { FieldProp, FieldTypes } from 'interface/FormUtils.interface';
|
import { FieldProp, FieldTypes } from 'interface/FormUtils.interface';
|
||||||
import { compact, startCase } from 'lodash';
|
import { compact, startCase } from 'lodash';
|
||||||
import TagSuggestion, {
|
import TagSuggestion, {
|
||||||
@ -233,31 +231,3 @@ export const transformErrors: ErrorTransformer = (errors) => {
|
|||||||
|
|
||||||
return compact(errorRet);
|
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;
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user