Skip to content

Commit

Permalink
feat(archive-viewer): address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Dec 18, 2019
1 parent 50686b2 commit 301b57c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ filename=Filename
last_modified_date=Last modified date
# Label for size column name
size=Size
# Shown as search accessibility label.
search=Search
# Shown as the title in the breadcrumbs while searching.
search_results=Search Results
# Shown as a placeholder in the search bar.
Expand Down
29 changes: 10 additions & 19 deletions src/lib/viewers/archive/ArchiveExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,41 +117,32 @@ class ArchiveExplorer extends React.Component {
};

/**
* Handle click event, update fullPath state, reset search and view
* Handle item click event, update fullPath state, reset search and view
*
* @param {Object} cellValue - the cell being clicked
* @return {void}
*/
handleClick = ({ fullPath }) => this.setState({ view: VIEW_FOLDER, fullPath, searchQuery: '' });
handleItemClick = ({ fullPath }) => this.setState({ view: VIEW_FOLDER, fullPath, searchQuery: '' });

/**
* Handle click event, update fullPath state
* Handle breadcrumb click event, update fullPath state
*
* @param {string} fullPath - target folder path
* @return {void}
*/
handleClickFullPath = fullPath => this.setState({ fullPath });
handleBreadcrumbClick = fullPath => this.setState({ fullPath });

/**
* Handle search input, update view state
*
* @param {string} query - raw query string in the search bar
* @return {void}
*/
handleSearch = query => {
const trimmedQuery = query.trim();
const newState = {
handleSearch = query =>
this.setState({
searchQuery: query,
};

if (!query) {
newState.view = VIEW_FOLDER;
} else if (trimmedQuery) {
newState.view = VIEW_SEARCH;
}

this.setState(newState);
};
view: query.trim() ? VIEW_SEARCH : VIEW_FOLDER,
});

/**
* Filter item collection for search query
Expand Down Expand Up @@ -182,12 +173,12 @@ class ArchiveExplorer extends React.Component {
<Internationalize language={language} messages={elementsMessages}>
<div className="bp-ArchiveExplorer">
<SearchBar onSearch={this.handleSearch} searchQuery={searchQuery} />
<Breadcrumbs fullPath={fullPath} onClick={this.handleClickFullPath} view={view} />
<Breadcrumbs fullPath={fullPath} onClick={this.handleBreadcrumbClick} view={view} />
<VirtualizedTable rowData={itemList} rowGetter={this.getRowData(itemList)}>
{intl => [
<Column
key={KEY_NAME}
cellRenderer={itemNameCellRenderer(intl, this.handleClick)}
cellRenderer={itemNameCellRenderer(intl, this.handleItemClick)}
dataKey={KEY_NAME}
disableSort
flexGrow={3}
Expand Down
38 changes: 17 additions & 21 deletions src/lib/viewers/archive/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@ import React from 'react';
import PropTypes from 'prop-types';
import './SearchBar.scss';

class SearchBar extends React.PureComponent {
static propTypes = {
onSearch: PropTypes.func.isRequired,
searchQuery: PropTypes.string.isRequired,
};
const SearchBar = ({ onSearch, searchQuery }) => {
return (
<div className="bp-SearchBar">
<input
aria-label={__('search')}
onChange={({ currentTarget }) => onSearch(currentTarget.value)}
placeholder={__('search_placeholder')}
type="search"
value={searchQuery}
/>
</div>
);
};

render() {
const { onSearch, searchQuery } = this.props;
const search = ({ currentTarget }) => onSearch(currentTarget.value);
return (
<div className="bp-SearchBar">
<input
aria-label="search"
onChange={search}
placeholder={__('search_placeholder')}
type="search"
value={searchQuery}
/>
</div>
);
}
}
SearchBar.propTypes = {
onSearch: PropTypes.func.isRequired,
searchQuery: PropTypes.string.isRequired,
};

export default SearchBar;
12 changes: 6 additions & 6 deletions src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ describe('lib/viewers/archive/ArchiveExplorer', () => {
});
});

describe('handleClick()', () => {
it('should set state when handleClick() is called', () => {
describe('handleItemClick()', () => {
it('should set state when handleItemClick() is called', () => {
const component = shallow(<ArchiveExplorer itemCollection={data} />);

component.instance().handleClick({ fullPath: 'test/subfolder/' });
component.instance().handleItemClick({ fullPath: 'test/subfolder/' });

expect(component.state().fullPath).to.equal('test/subfolder/');
expect(component.state().view).to.equal(VIEWS.VIEW_FOLDER);
expect(component.state().searchQuery).to.equal('');
});
});

describe('handleClickFullPath()', () => {
it('should set state when handleClickFullPath() is called', () => {
describe('handleBreadcrumbClick()', () => {
it('should set state when handleBreadcrumbClick() is called', () => {
const component = shallow(<ArchiveExplorer itemCollection={data} />);

component.instance().handleClickFullPath('test/subfolder/');
component.instance().handleBreadcrumbClick('test/subfolder/');

expect(component.state().fullPath).to.equal('test/subfolder/');
});
Expand Down

0 comments on commit 301b57c

Please sign in to comment.