Skip to content

Commit

Permalink
Merge pull request #249 from edx/mhughes/assets-page-paragon-search
Browse files Browse the repository at this point in the history
Update Search and Pagination on Assets Page & Edit Image Modal
  • Loading branch information
matthugs authored Sep 28, 2018
2 parents 2baa580 + 527bb5a commit 89b711e
Show file tree
Hide file tree
Showing 20 changed files with 562 additions and 1,015 deletions.
1,151 changes: 421 additions & 730 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "AGPL-3.0",
"dependencies": {
"@edx/edx-bootstrap": "^1.0.0",
"@edx/paragon": "3.1.2",
"@edx/paragon": "3.4.8",
"airbnb-prop-types": "^2.10.0",
"babel-polyfill": "^6.26.0",
"classnames": "^2.2.5",
Expand All @@ -30,7 +30,6 @@
"react-dropzone": "^4.2.3",
"react-intl": "^2.4.0",
"react-intl-translations-manager": "^5.0.1",
"react-paginate": "^5.0.0",
"react-redux": "^5.0.6",
"react-transition-group": "^2.2.1",
"redux": "^3.7.2",
Expand Down
1 change: 0 additions & 1 deletion src/components/AssetsList/AssetsList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

li span {
word-wrap: break-word;
width: 100%;
}

// from Bootstrap list-group-item class
Expand Down
2 changes: 1 addition & 1 deletion src/components/AssetsPage/AssetsPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const renderAssetsTableTest = () => {
};

const renderPaginationTest = () => {
expect(wrapper.find('Connect(Pagination)')).toHaveLength(1);
expect(wrapper.find('Connect(InjectIntl(Pagination))')).toHaveLength(1);
};

const rendersAssetsResultsCountTest = () => {
Expand Down
14 changes: 4 additions & 10 deletions src/components/AssetsSearch/AssetsSearch.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
@import 'edx-bootstrap';
@import "~@edx/paragon/src/SearchField/SearchField";

.form-inline {
margin-bottom: 0;
}

.form-inline label {
margin-right: 1.0rem;
font-weight: 600;
}

.form-inline button {
margin-left: 1.0rem;
padding: 0.625rem 0.9rem;
// Overriding SFE _var-reset rules which interfere with paragon search field functionality
.search-field .form-group.form-inline {
background-color: transparent
}
59 changes: 28 additions & 31 deletions src/components/AssetsSearch/AssetsSearch.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { SearchField } from '@edx/paragon';

import AssetsSearch from './index';
import { searchInitial } from './../../data/reducers/assets';
Expand All @@ -10,58 +11,54 @@ const defaultProps = {
courseDetails: {},
};

let wrapper;

describe('<AssetsSearch />', () => {
describe('renders', () => {
let wrapper;
let searchField;
beforeEach(() => {
wrapper = mountWithIntl(
<AssetsSearch
{...defaultProps}
/>,
);
searchField = wrapper.find(SearchField);
});
it('has label, input, and button in a form element', () => {
const searchForm = wrapper.find('form');

expect(searchForm).toHaveLength(1);
expect(searchForm.find('label')).toHaveLength(1);
expect(searchForm.find('input[type="search"]')).toHaveLength(1);
expect(searchForm.find('button[type="submit"]')).toHaveLength(1);
});
it('has correct styling', () => {
const button = wrapper.find('form').find('button[type="submit"]');
expect(wrapper.find('form').hasClass('form-group')).toEqual(true);
expect(wrapper.find('form').hasClass('form-inline')).toEqual(true);
expect(button.find('span.fa')).toHaveLength(1);
expect(button.find('span.fa').hasClass('fa-search')).toEqual(true);
it('has a paragon SearchField', () => {
expect(searchField).toHaveLength(1);
});
it('handles onChange callback correctly', () => {
const searchInput = wrapper.find('form input[type="search"]');

searchInput.simulate('change', { target: { value: 'edX' } });
searchField.prop('onChange')('edX');
expect(wrapper.state('value')).toEqual('edX');
});
it('calls updateSearch when submit button is clicked', () => {
const searchSpy = jest.fn();
describe('how updateSearch is called', () => {
let searchSpy;

wrapper.setProps({
updateSearch: searchSpy,
});
beforeEach(() => {
searchSpy = jest.fn();

const submitButton = wrapper.find('form button[type="submit"]');
const searchInput = wrapper.find('form input[type="search"]');
searchInput.simulate('change', { target: { value: 'edX' } });
submitButton.simulate('submit');
wrapper.setProps({
updateSearch: searchSpy,
});
searchField.prop('onChange')('edX');
searchField.prop('onSubmit')();
});

expect(searchSpy).toHaveBeenCalledTimes(1);
expect(searchSpy).toHaveBeenCalledWith('edX', defaultProps.courseDetails);
it('calls updateSearch when submit button is clicked', () => {
expect(searchSpy).toHaveBeenCalledTimes(1);
expect(searchSpy).toHaveBeenCalledWith('edX', defaultProps.courseDetails);
});
it('calls updateSearch when clear button is clicked', () => {
searchField.prop('onClear')();
expect(searchSpy).toHaveBeenCalledTimes(2);
expect(searchSpy).toHaveBeenLastCalledWith('', defaultProps.courseDetails);
});
});
it('updates search input text when search redux state is updated', () => {
const searchInput = wrapper.find('form input[type="search"]');
wrapper.setProps({ assetsSearch: { search: 'foobar' } }, () => {
searchField = wrapper.find(SearchField);
expect(wrapper.state('value')).toEqual('foobar');
expect(searchInput.instance().value).toEqual('foobar');
expect(searchField.prop('value')).toEqual('foobar');
});
});
});
Expand Down
5 changes: 5 additions & 0 deletions src/components/AssetsSearch/displayMessages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const messages = defineMessages({
defaultMessage: 'Submit search',
description: 'Label for search submit button that has a magnifying glass icon',
},
assetsClearSearchButtonLabel: {
id: 'assetsClearSearchButtonLabel',
defaultMessage: 'Clear search',
description: 'Label for a button that clears the search applied to a table.',
},
});

export default messages;
55 changes: 19 additions & 36 deletions src/components/AssetsSearch/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { Button, Icon, InputText } from '@edx/paragon';
import FontAwesomeStyles from 'font-awesome/css/font-awesome.min.css';
import { SearchField } from '@edx/paragon';

import WrappedMessage from '../../utils/i18n/formattedMessageWrapper';
import messages from './displayMessages';
Expand All @@ -14,7 +12,6 @@ export default class AssetsSearch extends React.Component {
this.state = { value: props.assetsSearch.search };

this.handleChange = this.handleChange.bind(this);
this.submit = this.submit.bind(this);
}

componentWillReceiveProps(nextProps) {
Expand All @@ -23,49 +20,35 @@ export default class AssetsSearch extends React.Component {
}
}

submit(event) {
submit = () => {
this.props.updateSearch(this.state.value, this.props.courseDetails);
event.preventDefault(); // prevent the page from navigating to the form action URL
}

handleChange(value) {
this.setState({ value });
}

handleClear = () => {
// relying on `submit` introduces as state update race
// condition
this.props.updateSearch('', this.props.courseDetails);
}

render() {
// TODO: InputText creates its own form-group div. Nesting them is not semantic.
// Once Paragon's asInput is refactored, use only one form-group element.
return (
<form
className="form-group form-inline justify-content-end"
onSubmit={this.submit}
>
<InputText
name="search"
className={['form-inline']}
type="search"
inline
label={<WrappedMessage message={messages.assetsSearchInputLabel} />}
value={this.state.value}
<div className="form-group form-inline justify-content-end">
<SearchField
onSubmit={this.submit}
onChange={this.handleChange}
inputGroupAppend={(
<Button
buttonType="primary"
type="submit"
label={
<WrappedMessage message={messages.assetsSearchSubmitLabel}>{
txt => (
<Icon
className={[classNames(FontAwesomeStyles.fa, FontAwesomeStyles['fa-search'])]}
screenReaderText={txt}
/>
)
}</WrappedMessage>
}
/>
)}
onClear={this.handleClear}
inputLabel={<WrappedMessage message={messages.assetsSearchInputLabel} />}
screenReaderText={{
clearButton: <WrappedMessage message={messages.assetsClearSearchButtonLabel} />,
searchButton: <WrappedMessage message={messages.assetsSearchSubmitLabel} />,
}}
value={this.state.value}
/>
</form>
</div>
);
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/components/CourseChecklist/CourseChecklist.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ $success-color: theme-color("success");
text-decoration: none;
}

.checklist-item {
&:not(:hover) {
.checklist-item-link {
@include sr_only();
}
}
}

//complete checklist item style
.checklist-item-complete {
box-shadow: -5px 0 0 0 $success-color;
Expand Down
8 changes: 4 additions & 4 deletions src/components/EditImageModal/EditImageModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('EditImageModal', () => {


it('no Pagination component', () => {
expect(getModalBody(editImageModal).find('Connect(Pagination)')).toHaveLength(0);
expect(getModalBody(editImageModal).find('Pagination')).toHaveLength(0);
});
});

Expand Down Expand Up @@ -244,7 +244,7 @@ describe('EditImageModal', () => {
});

it('a Pagination component', () => {
expect(getModalBody(editImageModal).find('Connect(Pagination)')).toHaveLength(1);
expect(getModalBody(editImageModal).find('Connect(InjectIntl(Pagination))')).toHaveLength(1);
});
});

Expand Down Expand Up @@ -294,7 +294,7 @@ describe('EditImageModal', () => {
});

it('no Pagination component', () => {
expect(getModalBody(editImageModal).find('Connect(Pagination)')).toHaveLength(0);
expect(getModalBody(editImageModal).find('Pagination')).toHaveLength(0);
});
});

Expand Down Expand Up @@ -345,7 +345,7 @@ describe('EditImageModal', () => {
});

it('no Pagination component', () => {
expect(getModalBody(editImageModal).find('Connect(Pagination)')).toHaveLength(0);
expect(getModalBody(editImageModal).find('Pagination')).toHaveLength(0);
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion src/components/Pagination/Pagination.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
$pagination-disabled-bg: transparent;

@import 'edx-bootstrap';
@import '~@edx/paragon/src/Pagination/Pagination';

.pagination {
justify-content: center;
Expand All @@ -11,7 +14,6 @@
}

.page-item {
min-width: 50px;
text-align: center;
}

Expand All @@ -29,3 +31,6 @@
@extend .disabled;
}
}
.page-item.disabled .page-link {
background-color: $pagination-disabled-bg;
}
Loading

0 comments on commit 89b711e

Please sign in to comment.