mirror of
https://github.com/ansible/awx.git
synced 2026-05-24 00:57:48 -02:30
Merge pull request #9468 from mabashian/8789-workflow-inv-prompt
Adds warning message to inventory step when launching wfjt or creating node with wfjt Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -17,7 +17,7 @@ const QS_CONFIG = getQSConfig('inventory', {
|
|||||||
order_by: 'name',
|
order_by: 'name',
|
||||||
});
|
});
|
||||||
|
|
||||||
function InventoryStep({ i18n }) {
|
function InventoryStep({ i18n, warningMessage = null }) {
|
||||||
const [field, meta, helpers] = useField({
|
const [field, meta, helpers] = useField({
|
||||||
name: 'inventory',
|
name: 'inventory',
|
||||||
});
|
});
|
||||||
@@ -68,6 +68,7 @@ function InventoryStep({ i18n }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{warningMessage}
|
||||||
<OptionsList
|
<OptionsList
|
||||||
value={field.value ? [field.value] : []}
|
value={field.value ? [field.value] : []}
|
||||||
options={inventories}
|
options={inventories}
|
||||||
|
|||||||
@@ -47,4 +47,20 @@ describe('InventoryStep', () => {
|
|||||||
expect(InventoriesAPI.read).toHaveBeenCalled();
|
expect(InventoriesAPI.read).toHaveBeenCalled();
|
||||||
expect(wrapper.find('OptionsList').prop('options')).toEqual(inventories);
|
expect(wrapper.find('OptionsList').prop('options')).toEqual(inventories);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should show warning message when one is passed in', async () => {
|
||||||
|
let wrapper;
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Formik>
|
||||||
|
<InventoryStep
|
||||||
|
warningMessage={<div id="test-warning-message">TEST</div>}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
|
||||||
|
expect(wrapper.find('div#test-warning-message').length).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { useField } from 'formik';
|
import { useField } from 'formik';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { Alert } from '@patternfly/react-core';
|
||||||
import InventoryStep from './InventoryStep';
|
import InventoryStep from './InventoryStep';
|
||||||
import StepName from './StepName';
|
import StepName from './StepName';
|
||||||
|
|
||||||
|
const InventoryAlert = styled(Alert)`
|
||||||
|
margin-bottom: 16px;
|
||||||
|
`;
|
||||||
|
|
||||||
const STEP_ID = 'inventory';
|
const STEP_ID = 'inventory';
|
||||||
|
|
||||||
export default function useInventoryStep(
|
export default function useInventoryStep(
|
||||||
@@ -21,7 +27,7 @@ export default function useInventoryStep(
|
|||||||
!meta.value;
|
!meta.value;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
step: getStep(launchConfig, i18n, formError),
|
step: getStep(launchConfig, i18n, formError, resource),
|
||||||
initialValues: getInitialValues(launchConfig, resource),
|
initialValues: getInitialValues(launchConfig, resource),
|
||||||
isReady: true,
|
isReady: true,
|
||||||
contentError: null,
|
contentError: null,
|
||||||
@@ -36,7 +42,7 @@ export default function useInventoryStep(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function getStep(launchConfig, i18n, formError) {
|
function getStep(launchConfig, i18n, formError, resource) {
|
||||||
if (!launchConfig.ask_inventory_on_launch) {
|
if (!launchConfig.ask_inventory_on_launch) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -47,7 +53,23 @@ function getStep(launchConfig, i18n, formError) {
|
|||||||
{i18n._(t`Inventory`)}
|
{i18n._(t`Inventory`)}
|
||||||
</StepName>
|
</StepName>
|
||||||
),
|
),
|
||||||
component: <InventoryStep i18n={i18n} />,
|
component: (
|
||||||
|
<InventoryStep
|
||||||
|
i18n={i18n}
|
||||||
|
warningMessage={
|
||||||
|
resource.type === 'workflow_job_template' ? (
|
||||||
|
<InventoryAlert
|
||||||
|
ouiaId="InventoryStep-alert"
|
||||||
|
variant="warning"
|
||||||
|
isInline
|
||||||
|
title={i18n._(
|
||||||
|
t`This inventory is applied to all job template nodes within this workflow (${resource.name}) that prompt for an inventory.`
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
),
|
||||||
enableNext: true,
|
enableNext: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user