Remove validation and unused vars for EE Lookup.

This commit is contained in:
Kia Lam
2021-09-23 10:23:51 -07:00
parent f06eb5e2f1
commit d7f1f0c7e6
4 changed files with 10 additions and 36 deletions

View File

@@ -24,9 +24,7 @@ function ExecutionEnvironmentLookup({
id, id,
globallyAvailable, globallyAvailable,
helperTextInvalid, helperTextInvalid,
isDefaultEnvironment,
isDisabled, isDisabled,
isGlobalDefaultEnvironment,
isValid, isValid,
onBlur, onBlur,
onChange, onChange,
@@ -40,7 +38,6 @@ function ExecutionEnvironmentLookup({
overrideLabel, overrideLabel,
}) { }) {
const location = useLocation(); const location = useLocation();
const { const {
request: fetchProject, request: fetchProject,
error: fetchProjectError, error: fetchProjectError,
@@ -199,26 +196,17 @@ function ExecutionEnvironmentLookup({
</> </>
); );
const renderLabel = ( const renderLabel = () => {
globalDefaultEnvironment,
defaultExecutionEnvironment
) => {
if (overrideLabel) { if (overrideLabel) {
return null; return null;
} }
if (globalDefaultEnvironment) {
return t`Global Default Execution Environment`;
}
if (defaultExecutionEnvironment) {
return t`Default Execution Environment`;
}
return t`Execution Environment`; return t`Execution Environment`;
}; };
return ( return (
<FormGroup <FormGroup
fieldId={id} fieldId={id}
label={renderLabel(isGlobalDefaultEnvironment, isDefaultEnvironment)} label={renderLabel()}
labelIcon={popoverContent && <Popover content={popoverContent} />} labelIcon={popoverContent && <Popover content={popoverContent} />}
helperTextInvalid={helperTextInvalid} helperTextInvalid={helperTextInvalid}
validated={isValid ? 'default' : 'error'} validated={isValid ? 'default' : 'error'}
@@ -239,8 +227,6 @@ ExecutionEnvironmentLookup.propTypes = {
value: ExecutionEnvironment, value: ExecutionEnvironment,
popoverContent: string, popoverContent: string,
onChange: func.isRequired, onChange: func.isRequired,
isDefaultEnvironment: bool,
isGlobalDefaultEnvironment: bool,
projectId: oneOfType([number, string]), projectId: oneOfType([number, string]),
organizationId: oneOfType([number, string]), organizationId: oneOfType([number, string]),
validate: func, validate: func,
@@ -251,8 +237,6 @@ ExecutionEnvironmentLookup.propTypes = {
ExecutionEnvironmentLookup.defaultProps = { ExecutionEnvironmentLookup.defaultProps = {
id: 'execution-environments', id: 'execution-environments',
popoverContent: '', popoverContent: '',
isDefaultEnvironment: false,
isGlobalDefaultEnvironment: false,
value: null, value: null,
projectId: null, projectId: null,
organizationId: null, organizationId: null,

View File

@@ -54,7 +54,6 @@ describe('ExecutionEnvironmentLookup', () => {
wrapper = mountWithContexts( wrapper = mountWithContexts(
<Formik> <Formik>
<ExecutionEnvironmentLookup <ExecutionEnvironmentLookup
isDefaultEnvironment
value={executionEnvironment} value={executionEnvironment}
onChange={() => {}} onChange={() => {}}
/> />
@@ -64,12 +63,9 @@ describe('ExecutionEnvironmentLookup', () => {
wrapper.update(); wrapper.update();
expect(ExecutionEnvironmentsAPI.read).toHaveBeenCalledTimes(1); expect(ExecutionEnvironmentsAPI.read).toHaveBeenCalledTimes(1);
expect(wrapper.find('ExecutionEnvironmentLookup')).toHaveLength(1); expect(wrapper.find('ExecutionEnvironmentLookup')).toHaveLength(1);
expect(
wrapper.find('FormGroup[label="Default Execution Environment"]').length
).toBe(1);
expect( expect(
wrapper.find('FormGroup[label="Execution Environment"]').length wrapper.find('FormGroup[label="Execution Environment"]').length
).toBe(0); ).toBe(1);
}); });
test('should fetch execution environments', async () => { test('should fetch execution environments', async () => {

View File

@@ -57,12 +57,10 @@ function Lookup(props) {
useField({ useField({
name: fieldName, name: fieldName,
validate: (val) => { validate: (val) => {
setTimeout(() => { if (!multiple && !val && typedText && typedText !== '') {
if (!multiple && !val && typedText && typedText !== '') { return t`That value was not found. Please enter or select a valid value.`;
return t`That value was not found. Please enter or select a valid value.`; }
} return validate(val);
return validate(val);
});
}, },
}); });

View File

@@ -231,9 +231,7 @@ EncryptedField.propTypes = {
}; };
const ExecutionEnvField = ({ name, config, isRequired = false }) => { const ExecutionEnvField = ({ name, config, isRequired = false }) => {
const validate = isRequired ? required(null) : null; const [field, meta, helpers] = useField({ name });
const [field, meta, helpers] = useField({ name, validate });
const isValid = !meta.error || !meta.touched;
return config ? ( return config ? (
<SettingGroup <SettingGroup
defaultValue={config.default ?? ''} defaultValue={config.default ?? ''}
@@ -242,15 +240,13 @@ const ExecutionEnvField = ({ name, config, isRequired = false }) => {
isRequired={isRequired} isRequired={isRequired}
label={config.label} label={config.label}
popoverContent={config.help_text} popoverContent={config.help_text}
validated={isValid ? 'default' : 'error'}
isDisabled={field.value === null} isDisabled={field.value === null}
onRevertCallback={() => helpers.setValue(config.default)}
> >
<ExecutionEnvironmentLookup <ExecutionEnvironmentLookup
onBlur={() => helpers.setTouched(true)}
value={field.value} value={field.value}
onChange={(value) => { onChange={(value) => {
helpers.setValue(value); helpers.setValue(value, false);
helpers.setTouched(true);
}} }}
overrideLabel overrideLabel
fieldName={name} fieldName={name}