mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 22:46:01 -03:30
Add validate for CredentialLookup using required prop
When using `CredentialLookup` with required prop. The `validate` argument must be provided to the `useField`. See: https://github.com/ansible/awx/issues/8184
This commit is contained in:
@@ -23,9 +23,11 @@ import { VariablesField } from '../../../components/CodeMirrorInput';
|
|||||||
|
|
||||||
function ContainerGroupFormFields({ i18n, instanceGroup }) {
|
function ContainerGroupFormFields({ i18n, instanceGroup }) {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const [overrideField] = useField('override');
|
const [overrideField] = useField('override');
|
||||||
|
|
||||||
const onCredentialChange = useCallback(
|
const onCredentialChange = useCallback(
|
||||||
|
|||||||
@@ -28,12 +28,21 @@ const instanceGroup = {
|
|||||||
is_controller: false,
|
is_controller: false,
|
||||||
is_isolated: false,
|
is_isolated: false,
|
||||||
is_containerized: false,
|
is_containerized: false,
|
||||||
credential: null,
|
credential: 3,
|
||||||
policy_instance_percentage: 46,
|
policy_instance_percentage: 46,
|
||||||
policy_instance_minimum: 12,
|
policy_instance_minimum: 12,
|
||||||
policy_instance_list: [],
|
policy_instance_list: [],
|
||||||
pod_spec_override: '',
|
pod_spec_override: '',
|
||||||
summary_fields: {
|
summary_fields: {
|
||||||
|
credential: {
|
||||||
|
id: 3,
|
||||||
|
name: 'test',
|
||||||
|
description: 'Simple one',
|
||||||
|
kind: 'kubernetes_bearer_token',
|
||||||
|
cloud: false,
|
||||||
|
kubernetes: true,
|
||||||
|
credential_type_id: 17,
|
||||||
|
},
|
||||||
user_capabilities: {
|
user_capabilities: {
|
||||||
edit: true,
|
edit: true,
|
||||||
delete: true,
|
delete: true,
|
||||||
@@ -101,7 +110,7 @@ describe('<ContainerGroupForm/>', () => {
|
|||||||
.find('Checkbox[aria-label="Customize pod specification"]')
|
.find('Checkbox[aria-label="Customize pod specification"]')
|
||||||
.prop('isChecked')
|
.prop('isChecked')
|
||||||
).toBeFalsy();
|
).toBeFalsy();
|
||||||
expect(wrapper.find('CredentialLookup').prop('value')).toBeFalsy();
|
expect(wrapper.find('CredentialLookup').prop('value').name).toBe('test');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should update form values', () => {
|
test('should update form values', () => {
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const AzureSubForm = ({ autoPopulateCredential, i18n }) => {
|
const AzureSubForm = ({ autoPopulateCredential, i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const CloudFormsSubForm = ({ i18n }) => {
|
const CloudFormsSubForm = ({ i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const GCESubForm = ({ autoPopulateCredential, i18n }) => {
|
const GCESubForm = ({ autoPopulateCredential, i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const OpenStackSubForm = ({ autoPopulateCredential, i18n }) => {
|
const OpenStackSubForm = ({ autoPopulateCredential, i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const SatelliteSubForm = ({ autoPopulateCredential, i18n }) => {
|
const SatelliteSubForm = ({ autoPopulateCredential, i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const TowerSubForm = ({ autoPopulateCredential, i18n }) => {
|
const TowerSubForm = ({ autoPopulateCredential, i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const VMwareSubForm = ({ autoPopulateCredential, i18n }) => {
|
const VMwareSubForm = ({ autoPopulateCredential, i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ import {
|
|||||||
EnabledValueField,
|
EnabledValueField,
|
||||||
HostFilterField,
|
HostFilterField,
|
||||||
} from './SharedFields';
|
} from './SharedFields';
|
||||||
|
import { required } from '../../../../util/validators';
|
||||||
|
|
||||||
const VirtualizationSubForm = ({ autoPopulateCredential, i18n }) => {
|
const VirtualizationSubForm = ({ autoPopulateCredential, i18n }) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
const [credentialField, credentialMeta, credentialHelpers] = useField(
|
const [credentialField, credentialMeta, credentialHelpers] = useField({
|
||||||
'credential'
|
name: 'credential',
|
||||||
);
|
validate: required(i18n._(t`Select a value for this field`), i18n),
|
||||||
|
});
|
||||||
|
|
||||||
const handleCredentialUpdate = useCallback(
|
const handleCredentialUpdate = useCallback(
|
||||||
value => {
|
value => {
|
||||||
|
|||||||
Reference in New Issue
Block a user