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 AO pagination #1383

Merged
merged 2 commits into from
Oct 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions fec/fec/static/js/legal/Pagination.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
const React = require('react');

function Pagination(props) {
function interceptHandleChange(increment) {
const syntheticEvent = { target: { name: 'from_hit', value: props.from_hit + increment } };
function interceptHandleChange(offset) {

// from_hit is a zero-based index
let updatedFromHit = props.from_hit + offset;

// when from_hit is less than 0, reset to 0 (ensures no negative value)
if (updatedFromHit < 0) {
updatedFromHit = 0;
}
// ensures that from_hit is less than result count
else if (updatedFromHit >= props.resultCount) {
updatedFromHit = props.resultCount - 1;
}

// create an event to update from_hit
const syntheticEvent = {
target: {
name: 'from_hit',
value: updatedFromHit
}
};
props.handleChange(syntheticEvent);
}

Expand All @@ -11,10 +30,10 @@ function Pagination(props) {
{props.from_hit + 1}&ndash;{props.from_hit + props.advisory_opinions.length} of {props.resultCount}</div>
<div className="dataTables_paginate">
{props.from_hit > 0 ? <a className="paginate_button previous"
onClick={() => interceptHandleChange(-props.advisory_opinions.length)}>Previous</a>
onClick={() => interceptHandleChange(-20)}>Previous</a>
: <span className="paginate_button previous is-disabled">Previous</span> }
{props.from_hit + props.advisory_opinions.length < props.resultCount ? <a className="paginate_button next"
onClick={() => interceptHandleChange(props.advisory_opinions.length)}>Next</a>
onClick={() => interceptHandleChange(20)}>Next</a>
: <span className="paginate_button next is-disabled">Next</span> }
</div>
</div> : null
Expand Down