Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
MUIR-277: align pagination with new Search API
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmcelwee committed Aug 3, 2018
1 parent 9dba20f commit 94c1678
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
35 changes: 24 additions & 11 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,30 @@ export default config => {
payload: { query: searchQuery, ...optionalArgs }
});

// TODO: send a request directly to middle-tier
// with query options, queryText, combined query object as object
return searchAPI.search(searchQuery, optionalArgs).then(
data => dispatch(receiveSuccessfulSearch(data, optionalArgs)),
error => {
dispatch({
type: types.SEARCH_FAILURE,
payload: { error: error.message, ...optionalArgs }
});
}
);
// TODO: consider changing shape of state instead of modifying
// shape of query here
const { page, pageLength, ...muirSearchQuery } = searchQuery;
return searchAPI
.search(
{
...muirSearchQuery,
options: {
start:
pageLength && page ? pageLength * (page - 1) + 1 : undefined,
pageLength: pageLength
}
},
optionalArgs
)
.then(
data => dispatch(receiveSuccessfulSearch(data, optionalArgs)),
error => {
dispatch({
type: types.SEARCH_FAILURE,
payload: { error: error.message, ...optionalArgs }
});
}
);
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe('search', () => {
.then(() => {
expect(selectors.getPage(store.getState())).toEqual(2);
expect(mockSearch).toHaveBeenCalledWith(
expect.objectContaining({ page: 2 }),
expect.objectContaining({ options: { pageLength: 10, start: 11 } }),
expect.anything()
);
done();
Expand Down

0 comments on commit 94c1678

Please sign in to comment.