Adds warning message to inventory step when launching wfjt or creating node with wfjt

This commit is contained in:
mabashian 2021-03-03 13:20:30 -05:00
parent 3903e88a47
commit 75746f2c69
3 changed files with 37 additions and 4 deletions

View File

@ -17,7 +17,7 @@ const QS_CONFIG = getQSConfig('inventory', {
order_by: 'name',
});
function InventoryStep({ i18n }) {
function InventoryStep({ i18n, warningMessage = null }) {
const [field, meta, helpers] = useField({
name: 'inventory',
});
@ -68,6 +68,7 @@ function InventoryStep({ i18n }) {
return (
<>
{warningMessage}
<OptionsList
value={field.value ? [field.value] : []}
options={inventories}

View File

@ -47,4 +47,20 @@ describe('InventoryStep', () => {
expect(InventoriesAPI.read).toHaveBeenCalled();
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);
});
});

View File

@ -1,6 +1,7 @@
import React from 'react';
import { t } from '@lingui/macro';
import { useField } from 'formik';
import { Alert } from '@patternfly/react-core';
import InventoryStep from './InventoryStep';
import StepName from './StepName';
@ -21,7 +22,7 @@ export default function useInventoryStep(
!meta.value;
return {
step: getStep(launchConfig, i18n, formError),
step: getStep(launchConfig, i18n, formError, resource),
initialValues: getInitialValues(launchConfig, resource),
isReady: true,
contentError: null,
@ -36,7 +37,7 @@ export default function useInventoryStep(
},
};
}
function getStep(launchConfig, i18n, formError) {
function getStep(launchConfig, i18n, formError, resource) {
if (!launchConfig.ask_inventory_on_launch) {
return null;
}
@ -47,7 +48,22 @@ function getStep(launchConfig, i18n, formError) {
{i18n._(t`Inventory`)}
</StepName>
),
component: <InventoryStep i18n={i18n} />,
component: (
<InventoryStep
i18n={i18n}
warningMessage={
resource.type === 'workflow_job_template' ? (
<Alert
variant="warning"
isInline
title={i18n._(
t`This inventory is applied to all job template nodes within this workflow that prompt for an inventory.`
)}
/>
) : null
}
/>
),
enableNext: true,
};
}