Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #33288 - Enter key fix for content view filter modal #9659

Merged
merged 1 commit into from Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions webpack/scenes/ContentViews/Details/Filters/Add/CVFilterAddModal.js
Expand Up @@ -5,8 +5,10 @@ import { useDispatch, useSelector } from 'react-redux';
import { STATUS } from 'foremanReact/constants';
import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';
import { Modal, ModalVariant, Form, FormGroup, TextInput, ActionGroup, Button, Radio, TextArea,
Split, SplitItem, Select, SelectOption } from '@patternfly/react-core';
import {
Modal, ModalVariant, Form, FormGroup, TextInput, ActionGroup, Button, Radio, TextArea,
Split, SplitItem, Select, SelectOption,
} from '@patternfly/react-core';
import { addCVFilterRule, createContentViewFilter } from '../../ContentViewDetailActions';
import {
selectCreateContentViewFilter, selectCreateContentViewFilterStatus,
Expand All @@ -16,7 +18,7 @@ import {
import { FILTER_TYPES } from '../../../ContentViewsConstants';
import ContentType from '../ContentType';

const CVFilterAddModal = ({ cvId, show, setIsOpen }) => {
const CVFilterAddModal = ({ cvId, show, onClose }) => {
const [inclusion, setInclusion] = useState(true);
const [name, setName] = useState('');
const [description, setDescription] = useState('');
Expand Down Expand Up @@ -83,12 +85,10 @@ const CVFilterAddModal = ({ cvId, show, setIsOpen }) => {
title={__('Create filter')}
variant={ModalVariant.large}
isOpen={show}
onClose={() => {
setIsOpen(false);
}}
onClose={onClose}
appendTo={document.body}
>
<Form>
<Form onSubmit={onSave}>
<FormGroup label={__('Name')} isRequired fieldId="name">
<TextInput
isRequired
Expand Down Expand Up @@ -154,12 +154,12 @@ const CVFilterAddModal = ({ cvId, show, setIsOpen }) => {
<Button
aria-label="create_filter"
variant="primary"
isDisabled={saving}
onClick={() => onSave()}
isDisabled={saving || name.length === 0}
type="submit"
Andrewgdewar marked this conversation as resolved.
Show resolved Hide resolved
>
{__('Create filter')}
</Button>
<Button variant="link" onClick={() => setIsOpen(false)}>
<Button variant="link" onClick={onClose}>
{__('Cancel')}
</Button>
</ActionGroup>
Expand All @@ -171,11 +171,11 @@ const CVFilterAddModal = ({ cvId, show, setIsOpen }) => {
CVFilterAddModal.propTypes = {
cvId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
show: PropTypes.bool.isRequired,
setIsOpen: PropTypes.func,
onClose: PropTypes.func,
};

CVFilterAddModal.defaultProps = {
setIsOpen: null,
onClose: null,
};

export default CVFilterAddModal;
Expand Up @@ -33,7 +33,7 @@ test('Can save content view filter from form', (done) => {
fireEvent.change(getByLabelText('input_name'), { target: { value: 'test' } });
fireEvent.change(getByLabelText('input_description'), { target: { value: 'Creating filter' } });

getByLabelText('create_filter').click();
fireEvent.submit(getByLabelText('create_filter'));
assertNockRequest(createFilterscope, done);
});

Expand All @@ -45,7 +45,7 @@ test('Closes content view filter form upon save', async (done) => {
fireEvent.change(getByLabelText('input_name'), { target: { value: 'test' } });
fireEvent.change(getByLabelText('input_description'), { target: { value: 'Creating filter' } });

getByLabelText('create_filter').click();
fireEvent.submit(getByLabelText('create_filter'));
await patientlyWaitFor(() => {
expect(queryByText('Description')).not.toBeInTheDocument();
});
Expand Down
Expand Up @@ -153,7 +153,7 @@ const ContentViewFilters = ({ cvId }) => {
<CVFilterAddModal
cvId={cvId}
show={addModalOpen}
setIsOpen={setAddModalOpen}
onClose={() => setAddModalOpen(false)}
aria-label="add_filter_modal"
/>}
</>
Expand Down