Skip to content

Commit

Permalink
Merge pull request #190 from KleeGroup/results-selection
Browse files Browse the repository at this point in the history
Results selection
  • Loading branch information
Bernardstanislas committed Aug 18, 2015
2 parents 18f60d6 + 8991639 commit 7f7a06b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "focusjs-components",
"version": "0.4.4",
"version": "0.4.5",
"description": "Focus component repository.",
"main": "index.js",
"scripts": {
Expand Down
51 changes: 36 additions & 15 deletions src/page/search/common/component/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ let Results = {
action: undefined,
store: undefined,
resultsMap: undefined,
selectionResultsMap: undefined,
totalCount: undefined,
groupComponent: undefined,
lineComponentMapper: undefined,
Expand All @@ -54,11 +55,18 @@ let Results = {
resultsFacets: undefined
};
},
/**
* Initial state
* @return {Object} Initial state
*/
getInitialState() {
return ({
loading: false
});
},
/**
* Component will receive props
*/
componentWillReceiveProps() {
if (this.state.loading) {
this.setState({
Expand All @@ -82,8 +90,8 @@ let Results = {
<GroupWrapper
count={count}
groupComponent={this.props.groupComponent}
isUnique={true}
groupKey={key}
isUnique={true}
list={list}
renderResultsList={this._renderResultsList}
/>
Expand Down Expand Up @@ -120,23 +128,36 @@ let Results = {
* @return {HTML} the rendered component
*/
_renderResultsList(list, key, count, isUnique) {
let LineComponent = this.props.lineComponentMapper(key, list);
let {
lineComponentMapper,
idField,
isSelection,
lineSelectionHandler,
lineClickHandler,
lineOperationList,
scrollParentSelector,
selectionStatus,
selectionResultsMap
} = this.props;
let selectionData = selectionResultsMap[key] || [];
let LineComponent = lineComponentMapper(key, list);
let hasMoreData = isUnique !== undefined && isUnique && list.length < count;
return (
<div>
<ListSelection
data-focus='results-list'
data={list}
idField={this.props.idField}
isSelection={this.props.isSelection}
onSelection={this.props.lineSelectionHandler}
onLineClick={this.props.lineClickHandler}
data-focus='results-list'
fetchNextPage={this._onScrollReachedBottom}
hasMoreData={hasMoreData}
operationList={this.props.lineOperationList}
idField={idField}
isSelection={isSelection}
lineComponent={LineComponent}
parentSelector={this.props.scrollParentSelector}
selectionStatus={this.props.selectionStatus}
onLineClick={lineClickHandler}
onSelection={lineSelectionHandler}
operationList={lineOperationList}
parentSelector={scrollParentSelector}
selectionData={selectionData}
selectionStatus={selectionStatus}
/>
{this.state.loading &&
<div data-focus='loading-more-results'>
Expand All @@ -151,7 +172,6 @@ let Results = {
/**
* Construct the show all action
* @param {string} key the group key where the show all has been clicked
* @return {function} the show all handler
*/
_showAllHandler(key) {
if (this.props.resultsFacets[this.props.scopeFacetKey]) {
Expand Down Expand Up @@ -181,7 +201,7 @@ let Results = {
*/
_getGroupCounts(resultsMap) {
let groupKeys = keys(resultsMap);
if (groupKeys.length === 1) {
if (1 === groupKeys.length) {
return {
[groupKeys[0]]: {
count: this.props.totalCount
Expand Down Expand Up @@ -212,6 +232,7 @@ let Results = {
/**
* Facet selection handler
* @param {string} key the facet key
* @param {string} value the facet value
*/
_facetSelectionHandler(key, value) {
let selectedFacets = assign({}, this.props.store.getSelectedFacets(), {
Expand Down Expand Up @@ -247,17 +268,17 @@ let Results = {
*/
render() {
// If there is no result, render the given empty component
if (this.props.totalCount === 0) {
if (0 === this.props.totalCount) {
return this._renderEmptyResults();
}
// Filter groups with no results
let resultsMap = omit(this.props.resultsMap, (list) => {
return list.length === 0;
return 0 === list.length;
});
// Get the count for each group
let groupCounts = this._getGroupCounts(this.props.resultsMap);
// Check if there is only one group left
if (keys(resultsMap).length === 1) {
if (1 === keys(resultsMap).length) {
let key = keys(resultsMap)[0];
let list = resultsMap[key];
let count = groupCounts[key].count;
Expand Down

0 comments on commit 7f7a06b

Please sign in to comment.