From 35ba74d265bd2aeeb44ef2175f3e3736a5ddafc8 Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Wed, 7 Oct 2020 13:21:41 -0400 Subject: [PATCH] Merge FieldTooltip and DetailPopover into single Popover component --- .../AdHocCommands/AdHocCredentialStep.jsx | 4 +- .../AdHocCommands/AdHocDetailsStep.jsx | 11 ++-- .../CodeMirrorInput/CodeMirrorField.jsx | 4 +- .../CodeMirrorInput/VariablesDetail.jsx | 8 ++- .../CodeMirrorInput/VariablesField.jsx | 5 +- .../CodeMirrorInput/VariablesField.test.jsx | 2 +- .../src/components/DetailList/CodeDetail.jsx | 25 ++++++++- .../src/components/DetailList/Detail.jsx | 6 +-- .../DetailPopover/DetailPopover.jsx | 51 ------------------- .../src/components/DetailPopover/index.js | 1 - .../FieldWithPrompt/FieldWithPrompt.jsx | 5 +- .../FieldWithPrompt/FieldWithPrompt.test.jsx | 10 ++-- .../components/FormField/ArrayTextField.jsx | 4 +- .../components/FormField/CheckboxField.jsx | 15 ++---- .../src/components/FormField/FieldTooltip.jsx | 35 ------------- .../src/components/FormField/FormField.jsx | 10 ++-- .../components/FormField/PasswordField.jsx | 4 +- awx/ui_next/src/components/FormField/index.js | 1 - .../src/components/HostForm/HostForm.jsx | 5 +- .../LaunchPrompt/steps/OtherPromptsStep.jsx | 11 ++-- .../LaunchPrompt/steps/SurveyStep.jsx | 7 +-- .../components/Lookup/CredentialLookup.jsx | 4 +- .../Lookup/InstanceGroupsLookup.jsx | 4 +- .../src/components/Lookup/ProjectLookup.jsx | 4 +- .../src/components/Popover/Popover.jsx | 51 +++++++++++++++++++ awx/ui_next/src/components/Popover/index.js | 1 + .../Application/shared/ApplicationForm.jsx | 10 ++-- .../BecomeMethodField.jsx | 6 +-- .../CredentialFormFields/CredentialField.jsx | 7 ++- .../CredentialPluginField.jsx | 4 +- .../CredentialPluginPrompt/MetadataStep.jsx | 17 ++----- .../Credential/shared/ExternalTestModal.jsx | 22 ++------ .../InventorySourceDetail.jsx | 10 ++-- .../Inventory/shared/InventorySourceForm.jsx | 8 ++- .../InventorySourceSubForms/SCMSubForm.jsx | 4 +- .../InventorySourceSubForms/SharedFields.jsx | 8 ++- .../screens/Project/shared/ProjectForm.jsx | 8 ++- .../shared/ProjectSubForms/ManualSubForm.jsx | 5 +- .../screens/Setting/shared/SettingDetail.jsx | 1 - .../Template/Survey/SurveyQuestionForm.jsx | 4 +- .../Template/shared/JobTemplateForm.jsx | 10 ++-- .../Template/shared/WebhookSubForm.jsx | 10 ++-- .../shared/WorkflowJobTemplateForm.jsx | 10 ++-- .../src/screens/User/shared/UserTokenForm.jsx | 10 ++-- 44 files changed, 193 insertions(+), 249 deletions(-) delete mode 100644 awx/ui_next/src/components/DetailPopover/DetailPopover.jsx delete mode 100644 awx/ui_next/src/components/DetailPopover/index.js delete mode 100644 awx/ui_next/src/components/FormField/FieldTooltip.jsx create mode 100644 awx/ui_next/src/components/Popover/Popover.jsx create mode 100644 awx/ui_next/src/components/Popover/index.js diff --git a/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx b/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx index 9a1f4fb094..fa6f931c24 100644 --- a/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx +++ b/awx/ui_next/src/components/AdHocCommands/AdHocCredentialStep.jsx @@ -6,7 +6,7 @@ import PropTypes from 'prop-types'; import { useField } from 'formik'; import { Form, FormGroup } from '@patternfly/react-core'; import { CredentialsAPI } from '../../api'; -import { FieldTooltip } from '../FormField'; +import Popover from '../Popover'; import { getQSConfig, parseQueryString, mergeParams } from '../../util/qs'; import useRequest from '../../util/useRequest'; @@ -72,7 +72,7 @@ function AdHocCredentialStep({ i18n, credentialTypeId, onEnableLaunch }) { } helperTextInvalid={credentialMeta.error} labelIcon={ - {i18n._(t`Enable privilege escalation`)}   - {i18n._(t`Enables creation of a provisioning diff --git a/awx/ui_next/src/components/CodeMirrorInput/CodeMirrorField.jsx b/awx/ui_next/src/components/CodeMirrorInput/CodeMirrorField.jsx index d08ab12674..35ebf32721 100644 --- a/awx/ui_next/src/components/CodeMirrorInput/CodeMirrorField.jsx +++ b/awx/ui_next/src/components/CodeMirrorInput/CodeMirrorField.jsx @@ -12,7 +12,7 @@ import { import { useField } from 'formik'; import { FormGroup } from '@patternfly/react-core'; import CodeMirrorInput from './CodeMirrorInput'; -import { FieldTooltip } from '../FormField'; +import Popover from '../Popover'; function CodeMirrorField({ id, @@ -37,7 +37,7 @@ function CodeMirrorField({ isRequired={isRequired} validated={isValid ? 'default' : 'error'} label={label} - labelIcon={} + labelIcon={} > {helpText && ( - + )} @@ -122,9 +122,13 @@ VariablesDetail.propTypes = { value: oneOfType([shape({}), arrayOf(string), string]).isRequired, label: node.isRequired, rows: number, + dataCy: string, + helpText: string, }; VariablesDetail.defaultProps = { rows: null, + dataCy: '', + helpText: '', }; export default VariablesDetail; diff --git a/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx b/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx index 9268771e0f..1db21fdf04 100644 --- a/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx +++ b/awx/ui_next/src/components/CodeMirrorInput/VariablesField.jsx @@ -5,10 +5,11 @@ import { t } from '@lingui/macro'; import { useField } from 'formik'; import styled from 'styled-components'; import { Split, SplitItem } from '@patternfly/react-core'; -import { CheckboxField, FieldTooltip } from '../FormField'; +import { CheckboxField } from '../FormField'; import MultiButtonToggle from '../MultiButtonToggle'; import { yamlToJson, jsonToYaml, isJsonString } from '../../util/yaml'; import CodeMirrorInput from './CodeMirrorInput'; +import Popover from '../Popover'; import { JSON_MODE, YAML_MODE } from './constants'; const FieldHeader = styled.div` @@ -43,7 +44,7 @@ function VariablesField({ - {tooltip && } + {tooltip && } { )} ); - expect(wrapper.find('Popover').length).toBe(1); + expect(wrapper.find('Popover[data-cy="the-field"]').length).toBe(1); }); it('should submit value through Formik', async () => { diff --git a/awx/ui_next/src/components/DetailList/CodeDetail.jsx b/awx/ui_next/src/components/DetailList/CodeDetail.jsx index 9b9a2f0568..a3a4918605 100644 --- a/awx/ui_next/src/components/DetailList/CodeDetail.jsx +++ b/awx/ui_next/src/components/DetailList/CodeDetail.jsx @@ -1,17 +1,30 @@ import 'styled-components/macro'; import React from 'react'; -import { shape, node, number, oneOf } from 'prop-types'; +import { shape, node, number, oneOf, string } from 'prop-types'; import { TextListItemVariants } from '@patternfly/react-core'; import { DetailName, DetailValue } from './Detail'; import CodeMirrorInput from '../CodeMirrorInput'; +import Popover from '../Popover'; + +function CodeDetail({ + value, + label, + mode, + rows, + fullHeight, + helpText, + dataCy, +}) { + const labelCy = dataCy ? `${dataCy}-label` : null; + const valueCy = dataCy ? `${dataCy}-value` : null; -function CodeDetail({ value, label, mode, rows, fullHeight }) { return ( <>
{label} + {helpText && ( + + )}
( @@ -61,9 +61,7 @@ const Detail = ({ id={dataCy} > {label} - {helpText && ( - - )} + {helpText && } setShowPopover(false)} - > - - - ); -} - -DetailPopover.propTypes = { - content: node, - header: node, - id: string, -}; -DetailPopover.defaultProps = { - content: null, - header: null, - id: 'detail-popover', -}; - -export default DetailPopover; diff --git a/awx/ui_next/src/components/DetailPopover/index.js b/awx/ui_next/src/components/DetailPopover/index.js deleted file mode 100644 index 02b42518c5..0000000000 --- a/awx/ui_next/src/components/DetailPopover/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './DetailPopover'; diff --git a/awx/ui_next/src/components/FieldWithPrompt/FieldWithPrompt.jsx b/awx/ui_next/src/components/FieldWithPrompt/FieldWithPrompt.jsx index fd82ae9c7e..8c9051e67e 100644 --- a/awx/ui_next/src/components/FieldWithPrompt/FieldWithPrompt.jsx +++ b/awx/ui_next/src/components/FieldWithPrompt/FieldWithPrompt.jsx @@ -3,7 +3,8 @@ import { bool, node, string } from 'prop-types'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; import styled from 'styled-components'; -import { CheckboxField, FieldTooltip } from '../FormField'; +import { CheckboxField } from '../FormField'; +import Popover from '../Popover'; const FieldHeader = styled.div` display: flex; @@ -38,7 +39,7 @@ function FieldWithPrompt({ )} - {tooltip && } + {tooltip && } { wrapper.unmount(); }); - test('Required asterisk and Tooltip hidden when not required and tooltip not provided', () => { + test('Required asterisk and Popover hidden when not required and tooltip not provided', () => { wrapper = mountWithContexts( { ); expect(wrapper.find('.pf-c-form__label-required')).toHaveLength(0); - expect(wrapper.find('Tooltip')).toHaveLength(0); + expect(wrapper.find('Popover')).toHaveLength(0); }); - test('Required asterisk and Tooltip shown when required and tooltip provided', () => { + test('Required asterisk and Popover shown when required and tooltip provided', () => { wrapper = mountWithContexts( { ); expect(wrapper.find('.pf-c-form__label-required')).toHaveLength(1); - expect(wrapper.find('Popover')).toHaveLength(1); + expect(wrapper.find('Popover[data-cy="job-template-limit"]').length).toBe( + 1 + ); }); }); diff --git a/awx/ui_next/src/components/FormField/ArrayTextField.jsx b/awx/ui_next/src/components/FormField/ArrayTextField.jsx index 862d48901b..d32493b41b 100644 --- a/awx/ui_next/src/components/FormField/ArrayTextField.jsx +++ b/awx/ui_next/src/components/FormField/ArrayTextField.jsx @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { useField } from 'formik'; import { FormGroup, TextArea } from '@patternfly/react-core'; -import FieldTooltip from './FieldTooltip'; +import Popover from '../Popover'; function ArrayTextField(props) { const { @@ -30,7 +30,7 @@ function ArrayTextField(props) { isRequired={isRequired} validated={isValid ? 'default' : 'error'} label={label} - labelIcon={} + labelIcon={} >