mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 11:27:36 -02:30
Adds FieldWithPrompt component to handle fields that are also promptable
This commit is contained in:
@@ -0,0 +1,91 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { withI18n } from '@lingui/react';
|
||||||
|
import { t } from '@lingui/macro';
|
||||||
|
import { Tooltip } from '@patternfly/react-core';
|
||||||
|
import { CheckboxField } from '@components/FormField';
|
||||||
|
import { QuestionCircleIcon as PFQuestionCircleIcon } from '@patternfly/react-icons';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
const QuestionCircleIcon = styled(PFQuestionCircleIcon)`
|
||||||
|
margin-left: 10px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const FieldHeader = styled.div`
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding-bottom: var(--pf-c-form__label--PaddingBottom);
|
||||||
|
|
||||||
|
label {
|
||||||
|
--pf-c-form__label--PaddingBottom: 0px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledCheckboxField = styled(CheckboxField)`
|
||||||
|
--pf-c-check__label--FontSize: var(--pf-c-form__label--FontSize);
|
||||||
|
`;
|
||||||
|
|
||||||
|
function FieldWithPrompt({
|
||||||
|
children,
|
||||||
|
fieldId,
|
||||||
|
i18n,
|
||||||
|
isRequired,
|
||||||
|
label,
|
||||||
|
promptId,
|
||||||
|
promptName,
|
||||||
|
promptValidate,
|
||||||
|
tooltip,
|
||||||
|
tooltipMaxWidth,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="pf-c-form__group">
|
||||||
|
<FieldHeader>
|
||||||
|
<div>
|
||||||
|
<label className="pf-c-form__label" htmlFor={fieldId}>
|
||||||
|
<span className="pf-c-form__label-text">{label}</span>
|
||||||
|
{isRequired && (
|
||||||
|
<span className="pf-c-form__label-required" aria-hidden="true">
|
||||||
|
*
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</label>
|
||||||
|
{tooltip && (
|
||||||
|
<Tooltip
|
||||||
|
content={tooltip}
|
||||||
|
maxWidth={tooltipMaxWidth}
|
||||||
|
position="right"
|
||||||
|
>
|
||||||
|
<QuestionCircleIcon />
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<StyledCheckboxField
|
||||||
|
id={promptId}
|
||||||
|
label={i18n._(t`Prompt On Launch`)}
|
||||||
|
name={promptName}
|
||||||
|
validate={promptValidate}
|
||||||
|
/>
|
||||||
|
</FieldHeader>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldWithPrompt.propTypes = {
|
||||||
|
fieldId: PropTypes.string.isRequired,
|
||||||
|
isRequired: PropTypes.bool,
|
||||||
|
label: PropTypes.string.isRequired,
|
||||||
|
promptId: PropTypes.string.isRequired,
|
||||||
|
promptValidate: PropTypes.func,
|
||||||
|
tooltip: PropTypes.node,
|
||||||
|
tooltipMaxWidth: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
FieldWithPrompt.defaultProps = {
|
||||||
|
isRequired: false,
|
||||||
|
promptValidate: () => {},
|
||||||
|
tooltip: null,
|
||||||
|
tooltipMaxWidth: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withI18n()(FieldWithPrompt);
|
||||||
1
awx/ui_next/src/components/FieldWithPrompt/index.js
Normal file
1
awx/ui_next/src/components/FieldWithPrompt/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default } from './FieldWithPrompt';
|
||||||
@@ -21,6 +21,7 @@ import FormField, {
|
|||||||
FieldTooltip,
|
FieldTooltip,
|
||||||
FormSubmitError,
|
FormSubmitError,
|
||||||
} from '@components/FormField';
|
} from '@components/FormField';
|
||||||
|
import FieldWithPrompt from '@components/FieldWithPrompt';
|
||||||
import FormRow from '@components/FormRow';
|
import FormRow from '@components/FormRow';
|
||||||
import CollapsibleSection from '@components/CollapsibleSection';
|
import CollapsibleSection from '@components/CollapsibleSection';
|
||||||
import { required } from '@util/validators';
|
import { required } from '@util/validators';
|
||||||
@@ -227,37 +228,31 @@ class JobTemplateForm extends Component {
|
|||||||
type="text"
|
type="text"
|
||||||
label={i18n._(t`Description`)}
|
label={i18n._(t`Description`)}
|
||||||
/>
|
/>
|
||||||
<Field
|
<FieldWithPrompt
|
||||||
name="job_type"
|
fieldId="template-job-type"
|
||||||
validate={required(null, i18n)}
|
label={i18n._(t`Job Type`)}
|
||||||
onBlur={handleBlur}
|
promptId="template-ask-job-type-on-launch"
|
||||||
|
promptName="ask_job_type_on_launch"
|
||||||
|
isRequired
|
||||||
>
|
>
|
||||||
{({ form, field }) => {
|
<Field
|
||||||
const isValid = !form.touched.job_type || !form.errors.job_type;
|
name="job_type"
|
||||||
return (
|
validate={required(null, i18n)}
|
||||||
<FormGroup
|
onBlur={handleBlur}
|
||||||
fieldId="template-job-type"
|
>
|
||||||
helperTextInvalid={form.errors.job_type}
|
{({ form, field }) => {
|
||||||
isRequired
|
const isValid = !form.touched.job_type || !form.errors.job_type;
|
||||||
isValid={isValid}
|
return (
|
||||||
label={i18n._(t`Job Type`)}
|
|
||||||
>
|
|
||||||
<FieldTooltip
|
|
||||||
content={i18n._(t`For job templates, select run to execute
|
|
||||||
the playbook. Select check to only check playbook syntax,
|
|
||||||
test environment setup, and report problems without
|
|
||||||
executing the playbook.`)}
|
|
||||||
/>
|
|
||||||
<AnsibleSelect
|
<AnsibleSelect
|
||||||
isValid={isValid}
|
isValid={isValid}
|
||||||
id="template-job-type"
|
id="template-job-type"
|
||||||
data={jobTypeOptions}
|
data={jobTypeOptions}
|
||||||
{...field}
|
{...field}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
);
|
||||||
);
|
}}
|
||||||
}}
|
</Field>
|
||||||
</Field>
|
</FieldWithPrompt>
|
||||||
<Field
|
<Field
|
||||||
name="inventory"
|
name="inventory"
|
||||||
validate={required(i18n._(t`Select a value for this field`), i18n)}
|
validate={required(i18n._(t`Select a value for this field`), i18n)}
|
||||||
@@ -613,6 +608,7 @@ const FormikApp = withFormik({
|
|||||||
? summary_fields.inventory.organization_id
|
? summary_fields.inventory.organization_id
|
||||||
: null;
|
: null;
|
||||||
return {
|
return {
|
||||||
|
ask_job_type_on_launch: template.ask_job_type_on_launch || false,
|
||||||
name: template.name || '',
|
name: template.name || '',
|
||||||
description: template.description || '',
|
description: template.description || '',
|
||||||
job_type: template.job_type || 'run',
|
job_type: template.job_type || 'run',
|
||||||
|
|||||||
Reference in New Issue
Block a user