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:
softwarefactory-project-zuul[bot]
2021-03-15 13:53:35 +00:00
committed by GitHub
3 changed files with 43 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,9 +1,15 @@
import React from 'react';
import { t } from '@lingui/macro';
import { useField } from 'formik';
import styled from 'styled-components';
import { Alert } from '@patternfly/react-core';
import InventoryStep from './InventoryStep';
import StepName from './StepName';
const InventoryAlert = styled(Alert)`
margin-bottom: 16px;
`;
const STEP_ID = 'inventory';
export default function useInventoryStep(
@@ -21,7 +27,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 +42,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 +53,23 @@ function getStep(launchConfig, i18n, formError) {
{i18n._(t`Inventory`)}
</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,
};
}