mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 00:08:44 -03:30
disables prompt on launch checkbox
This commit is contained in:
@@ -23,6 +23,7 @@ function FieldWithPrompt({
|
|||||||
promptId,
|
promptId,
|
||||||
promptName,
|
promptName,
|
||||||
tooltip,
|
tooltip,
|
||||||
|
isDisabled,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="pf-c-form__group">
|
<div className="pf-c-form__group">
|
||||||
@@ -39,6 +40,7 @@ function FieldWithPrompt({
|
|||||||
{tooltip && <FieldTooltip content={tooltip} />}
|
{tooltip && <FieldTooltip content={tooltip} />}
|
||||||
</div>
|
</div>
|
||||||
<StyledCheckboxField
|
<StyledCheckboxField
|
||||||
|
isDisabled={isDisabled}
|
||||||
id={promptId}
|
id={promptId}
|
||||||
label={i18n._(t`Prompt on launch`)}
|
label={i18n._(t`Prompt on launch`)}
|
||||||
name={promptName}
|
name={promptName}
|
||||||
|
|||||||
@@ -9,10 +9,19 @@ const QuestionCircleIcon = styled(PFQuestionCircleIcon)`
|
|||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function CheckboxField({ id, name, label, tooltip, validate, ...rest }) {
|
function CheckboxField({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
label,
|
||||||
|
tooltip,
|
||||||
|
validate,
|
||||||
|
isDisabled,
|
||||||
|
...rest
|
||||||
|
}) {
|
||||||
const [field] = useField({ name, validate });
|
const [field] = useField({ name, validate });
|
||||||
return (
|
return (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
isDisabled={isDisabled}
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
label={
|
label={
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ function CredentialLookup({
|
|||||||
history,
|
history,
|
||||||
i18n,
|
i18n,
|
||||||
tooltip,
|
tooltip,
|
||||||
|
isDisabled,
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
result: { count, credentials, relatedSearchableKeys, searchableKeys },
|
result: { count, credentials, relatedSearchableKeys, searchableKeys },
|
||||||
@@ -108,6 +109,7 @@ function CredentialLookup({
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
required={required}
|
required={required}
|
||||||
qsConfig={QS_CONFIG}
|
qsConfig={QS_CONFIG}
|
||||||
|
isDisabled={isDisabled}
|
||||||
renderOptionsList={({ state, dispatch, canDelete }) => (
|
renderOptionsList={({ state, dispatch, canDelete }) => (
|
||||||
<OptionsList
|
<OptionsList
|
||||||
value={state.selectedItems}
|
value={state.selectedItems}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import OptionsList from '../OptionsList';
|
|||||||
import useRequest from '../../util/useRequest';
|
import useRequest from '../../util/useRequest';
|
||||||
import { getQSConfig, parseQueryString } from '../../util/qs';
|
import { getQSConfig, parseQueryString } from '../../util/qs';
|
||||||
import LookupErrorMessage from './shared/LookupErrorMessage';
|
import LookupErrorMessage from './shared/LookupErrorMessage';
|
||||||
|
import FieldWithPrompt from '../FieldWithPrompt';
|
||||||
|
|
||||||
const QS_CONFIG = getQSConfig('inventory', {
|
const QS_CONFIG = getQSConfig('inventory', {
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -17,7 +18,18 @@ const QS_CONFIG = getQSConfig('inventory', {
|
|||||||
order_by: 'name',
|
order_by: 'name',
|
||||||
});
|
});
|
||||||
|
|
||||||
function InventoryLookup({ value, onChange, onBlur, required, i18n, history }) {
|
function InventoryLookup({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
onBlur,
|
||||||
|
i18n,
|
||||||
|
history,
|
||||||
|
required,
|
||||||
|
isPromptableField,
|
||||||
|
fieldId,
|
||||||
|
promptId,
|
||||||
|
promptName,
|
||||||
|
}) {
|
||||||
const {
|
const {
|
||||||
result: {
|
result: {
|
||||||
inventories,
|
inventories,
|
||||||
@@ -61,7 +73,70 @@ function InventoryLookup({ value, onChange, onBlur, required, i18n, history }) {
|
|||||||
fetchInventories();
|
fetchInventories();
|
||||||
}, [fetchInventories]);
|
}, [fetchInventories]);
|
||||||
|
|
||||||
return (
|
return isPromptableField ? (
|
||||||
|
<>
|
||||||
|
<FieldWithPrompt
|
||||||
|
fieldId={fieldId}
|
||||||
|
isRequired={required}
|
||||||
|
label={i18n._(t`Inventory`)}
|
||||||
|
promptId={promptId}
|
||||||
|
promptName={promptName}
|
||||||
|
isDisabled={!canEdit}
|
||||||
|
tooltip={i18n._(t`Select the inventory containing the hosts
|
||||||
|
you want this job to manage.`)}
|
||||||
|
>
|
||||||
|
<Lookup
|
||||||
|
id="inventory-lookup"
|
||||||
|
header={i18n._(t`Inventory`)}
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
onBlur={onBlur}
|
||||||
|
required={required}
|
||||||
|
isLoading={isLoading}
|
||||||
|
isDisabled={!canEdit}
|
||||||
|
qsConfig={QS_CONFIG}
|
||||||
|
renderOptionsList={({ state, dispatch, canDelete }) => (
|
||||||
|
<OptionsList
|
||||||
|
value={state.selectedItems}
|
||||||
|
options={inventories}
|
||||||
|
optionCount={count}
|
||||||
|
searchColumns={[
|
||||||
|
{
|
||||||
|
name: i18n._(t`Name`),
|
||||||
|
key: 'name__icontains',
|
||||||
|
isDefault: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n._(t`Created By (Username)`),
|
||||||
|
key: 'created_by__username__icontains',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: i18n._(t`Modified By (Username)`),
|
||||||
|
key: 'modified_by__username__icontains',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
sortColumns={[
|
||||||
|
{
|
||||||
|
name: i18n._(t`Name`),
|
||||||
|
key: 'name',
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
searchableKeys={searchableKeys}
|
||||||
|
relatedSearchableKeys={relatedSearchableKeys}
|
||||||
|
multiple={state.multiple}
|
||||||
|
header={i18n._(t`Inventory`)}
|
||||||
|
name="inventory"
|
||||||
|
qsConfig={QS_CONFIG}
|
||||||
|
readOnly={!canDelete}
|
||||||
|
selectItem={item => dispatch({ type: 'SELECT_ITEM', item })}
|
||||||
|
deselectItem={item => dispatch({ type: 'DESELECT_ITEM', item })}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<LookupErrorMessage error={error} />
|
||||||
|
</FieldWithPrompt>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
<>
|
<>
|
||||||
<Lookup
|
<Lookup
|
||||||
id="inventory-lookup"
|
id="inventory-lookup"
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ function Lookup(props) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { isModalOpen, selectedItems } = state;
|
const { isModalOpen, selectedItems } = state;
|
||||||
const canDelete = !required || (multiple && value.length > 1);
|
const canDelete =
|
||||||
|
(!required || (multiple && value.length > 1)) && !isDisabled;
|
||||||
let items = [];
|
let items = [];
|
||||||
if (multiple) {
|
if (multiple) {
|
||||||
items = value;
|
items = value;
|
||||||
@@ -110,11 +111,7 @@ function Lookup(props) {
|
|||||||
>
|
>
|
||||||
<SearchIcon />
|
<SearchIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<ChipHolder
|
<ChipHolder isDisabled={isDisabled} className="pf-c-form-control">
|
||||||
isDisabled={isDisabled}
|
|
||||||
// css="background-color: #d2d2d2"
|
|
||||||
className="pf-c-form-control"
|
|
||||||
>
|
|
||||||
<ChipGroup numChips={5} totalChips={items.length}>
|
<ChipGroup numChips={5} totalChips={items.length}>
|
||||||
{items.map(item =>
|
{items.map(item =>
|
||||||
renderItemChip({
|
renderItemChip({
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
JobTemplatesAPI,
|
JobTemplatesAPI,
|
||||||
LabelsAPI,
|
LabelsAPI,
|
||||||
ProjectsAPI,
|
ProjectsAPI,
|
||||||
|
InventoriesAPI,
|
||||||
} from '../../../api';
|
} from '../../../api';
|
||||||
import JobTemplateEdit from './JobTemplateEdit';
|
import JobTemplateEdit from './JobTemplateEdit';
|
||||||
|
|
||||||
@@ -181,6 +182,12 @@ JobTemplatesAPI.readCredentials.mockResolvedValue({
|
|||||||
ProjectsAPI.readPlaybooks.mockResolvedValue({
|
ProjectsAPI.readPlaybooks.mockResolvedValue({
|
||||||
data: mockRelatedProjectPlaybooks,
|
data: mockRelatedProjectPlaybooks,
|
||||||
});
|
});
|
||||||
|
InventoriesAPI.readOptions.mockResolvedValue({
|
||||||
|
data: { actions: { GET: {}, POST: {} } },
|
||||||
|
});
|
||||||
|
ProjectsAPI.readOptions.mockResolvedValue({
|
||||||
|
data: { actions: { GET: {}, POST: {} } },
|
||||||
|
});
|
||||||
LabelsAPI.read.mockResolvedValue({ data: { results: [] } });
|
LabelsAPI.read.mockResolvedValue({ data: { results: [] } });
|
||||||
CredentialsAPI.read.mockResolvedValue({
|
CredentialsAPI.read.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -234,17 +234,15 @@ function JobTemplateForm({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FieldWithPrompt>
|
</FieldWithPrompt>
|
||||||
<FieldWithPrompt
|
<>
|
||||||
fieldId="template-inventory"
|
|
||||||
isRequired={!askInventoryOnLaunchField.value}
|
|
||||||
label={i18n._(t`Inventory`)}
|
|
||||||
promptId="template-ask-inventory-on-launch"
|
|
||||||
promptName="ask_inventory_on_launch"
|
|
||||||
tooltip={i18n._(t`Select the inventory containing the hosts
|
|
||||||
you want this job to manage.`)}
|
|
||||||
>
|
|
||||||
<InventoryLookup
|
<InventoryLookup
|
||||||
value={inventory}
|
value={inventory}
|
||||||
|
fieldId="template-inventory"
|
||||||
|
promptId="template-ask-inventory-on-launch"
|
||||||
|
promptName="ask_inventory_on_launch"
|
||||||
|
isPromptableField
|
||||||
|
tooltip={i18n._(t`Select the inventory containing the hosts
|
||||||
|
you want this job to manage.`)}
|
||||||
onBlur={() => inventoryHelpers.setTouched()}
|
onBlur={() => inventoryHelpers.setTouched()}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
inventoryHelpers.setValue(value ? value.id : null);
|
inventoryHelpers.setValue(value ? value.id : null);
|
||||||
@@ -263,7 +261,7 @@ function JobTemplateForm({
|
|||||||
{inventoryMeta.error}
|
{inventoryMeta.error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</FieldWithPrompt>
|
</>
|
||||||
<ProjectLookup
|
<ProjectLookup
|
||||||
value={projectField.value}
|
value={projectField.value}
|
||||||
onBlur={() => projectHelpers.setTouched()}
|
onBlur={() => projectHelpers.setTouched()}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
ProjectsAPI,
|
ProjectsAPI,
|
||||||
CredentialsAPI,
|
CredentialsAPI,
|
||||||
CredentialTypesAPI,
|
CredentialTypesAPI,
|
||||||
|
InventoriesAPI,
|
||||||
} from '../../../api';
|
} from '../../../api';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
@@ -111,14 +112,23 @@ describe('<JobTemplateForm />', () => {
|
|||||||
JobTemplatesAPI.updateWebhookKey.mockReturnValue({
|
JobTemplatesAPI.updateWebhookKey.mockReturnValue({
|
||||||
data: { webhook_key: 'webhook key' },
|
data: { webhook_key: 'webhook key' },
|
||||||
});
|
});
|
||||||
ProjectsAPI.readPlaybooks.mockReturnValue({
|
JobTemplatesAPI.updateWebhookKey.mockReturnValue({
|
||||||
data: ['debug.yml'],
|
data: { webhook_key: 'webhook key' },
|
||||||
});
|
});
|
||||||
ProjectsAPI.readDetail.mockReturnValue({
|
ProjectsAPI.readDetail.mockReturnValue({
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
id: 1,
|
id: 1,
|
||||||
allow_override: true,
|
allow_override: true,
|
||||||
});
|
});
|
||||||
|
ProjectsAPI.readPlaybooks.mockReturnValue({
|
||||||
|
data: ['debug.yml'],
|
||||||
|
});
|
||||||
|
InventoriesAPI.readOptions.mockResolvedValue({
|
||||||
|
data: { actions: { GET: {}, POST: {} } },
|
||||||
|
});
|
||||||
|
ProjectsAPI.readOptions.mockResolvedValue({
|
||||||
|
data: { actions: { GET: {}, POST: {} } },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function PlaybookSelect({ projectId, isValid, field, onBlur, onError, i18n }) {
|
|||||||
});
|
});
|
||||||
return opts;
|
return opts;
|
||||||
}, [projectId, i18n]),
|
}, [projectId, i18n]),
|
||||||
[field.value]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -110,23 +110,21 @@ function WorkflowJobTemplateForm({
|
|||||||
value={organizationField.value}
|
value={organizationField.value}
|
||||||
isValid={!organizationMeta.error}
|
isValid={!organizationMeta.error}
|
||||||
/>
|
/>
|
||||||
|
<>
|
||||||
<FieldWithPrompt
|
|
||||||
fieldId="wfjt-inventory"
|
|
||||||
label={i18n._(t`Inventory`)}
|
|
||||||
promptId="wfjt-ask-inventory-on-launch"
|
|
||||||
promptName="ask_inventory_on_launch"
|
|
||||||
tooltip={i18n._(
|
|
||||||
t`Select an inventory for the workflow. This inventory is applied to all job template nodes that prompt for an inventory.`
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<InventoryLookup
|
<InventoryLookup
|
||||||
|
promptId="wfjt-ask-inventory-on-launch"
|
||||||
|
promptName="ask_inventory_on_launch"
|
||||||
|
tooltip={i18n._(
|
||||||
|
t`Select an inventory for the workflow. This inventory is applied to all job template nodes that prompt for an inventory.`
|
||||||
|
)}
|
||||||
|
fieldId="wfjt-inventory"
|
||||||
|
isPromptableField
|
||||||
value={inventoryField.value}
|
value={inventoryField.value}
|
||||||
onBlur={() => inventoryHelpers.setTouched()}
|
onBlur={() => inventoryHelpers.setTouched()}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
inventoryHelpers.setValue(value);
|
inventoryHelpers.setValue(value);
|
||||||
}}
|
}}
|
||||||
required={askInventoryOnLaunchField.value}
|
required={!askInventoryOnLaunchField.value}
|
||||||
touched={inventoryMeta.touched}
|
touched={inventoryMeta.touched}
|
||||||
error={inventoryMeta.error}
|
error={inventoryMeta.error}
|
||||||
/>
|
/>
|
||||||
@@ -139,8 +137,7 @@ function WorkflowJobTemplateForm({
|
|||||||
{inventoryMeta.error}
|
{inventoryMeta.error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</FieldWithPrompt>
|
</>
|
||||||
|
|
||||||
<FieldWithPrompt
|
<FieldWithPrompt
|
||||||
fieldId="wjft-limit"
|
fieldId="wjft-limit"
|
||||||
label={i18n._(t`Limit`)}
|
label={i18n._(t`Limit`)}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
LabelsAPI,
|
LabelsAPI,
|
||||||
OrganizationsAPI,
|
OrganizationsAPI,
|
||||||
InventoriesAPI,
|
InventoriesAPI,
|
||||||
|
ProjectsAPI,
|
||||||
|
CredentialTypesAPI,
|
||||||
} from '../../../api';
|
} from '../../../api';
|
||||||
|
|
||||||
jest.mock('../../../api/models/CredentialTypes');
|
jest.mock('../../../api/models/CredentialTypes');
|
||||||
@@ -18,6 +20,8 @@ jest.mock('../../../api/models/WorkflowJobTemplates');
|
|||||||
jest.mock('../../../api/models/Labels');
|
jest.mock('../../../api/models/Labels');
|
||||||
jest.mock('../../../api/models/Organizations');
|
jest.mock('../../../api/models/Organizations');
|
||||||
jest.mock('../../../api/models/Inventories');
|
jest.mock('../../../api/models/Inventories');
|
||||||
|
jest.mock('../../../api/models/Projects');
|
||||||
|
jest.mock('../../../api/models/Credentials');
|
||||||
|
|
||||||
describe('<WorkflowJobTemplateForm/>', () => {
|
describe('<WorkflowJobTemplateForm/>', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
@@ -71,6 +75,15 @@ describe('<WorkflowJobTemplateForm/>', () => {
|
|||||||
{ id: 2, name: 'Bar' },
|
{ id: 2, name: 'Bar' },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
CredentialTypesAPI.read.mockResolvedValue({
|
||||||
|
data: { results: [{ id: 1 }] },
|
||||||
|
});
|
||||||
|
InventoriesAPI.readOptions.mockResolvedValue({
|
||||||
|
data: { actions: { GET: {}, POST: {} } },
|
||||||
|
});
|
||||||
|
ProjectsAPI.readOptions.mockResolvedValue({
|
||||||
|
data: { actions: { GET: {}, POST: {} } },
|
||||||
|
});
|
||||||
|
|
||||||
history = createMemoryHistory({
|
history = createMemoryHistory({
|
||||||
initialEntries: ['/templates/workflow_job_template/6/edit'],
|
initialEntries: ['/templates/workflow_job_template/6/edit'],
|
||||||
|
|||||||
Reference in New Issue
Block a user