Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Paginate My Shots #3657

Merged
merged 15 commits into from
Oct 31, 2017
Merged

Paginate My Shots #3657

merged 15 commits into from
Oct 31, 2017

Conversation

chenba
Copy link
Collaborator

@chenba chenba commented Oct 19, 2017

Fix #3391

@chenba chenba requested a review from flodolo as a code owner October 19, 2017 18:46
@ianb ianb self-requested a review October 20, 2017 17:00
ianb
ianb previously requested changes Oct 23, 2017
Copy link
Contributor

@ianb ianb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, mostly a bunch of small comments.

const queryParams = {};

Object.keys(searchKeys).forEach(x => {
if (typeof model[searchKeys[x]] !== "undefined" && model[searchKeys[x]] !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do model[searchKeys[x]] !== undefined here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let qs = queryString.parse(window.location.search)

Object.keys(searchKeys).forEach(x => {
if (typeof qs[x] !== "undefined") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do qs[x] !== undefined here – typeof is only necessary for top-level variables (e.g., typeof someVar !== "undefined")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

refreshModel();
};

exports.onChangePage = function(pageNumber) {
pageNumber = (pageNumber && parseInt(pageNumber)) || 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some linter somewhere is apt to warn about not using parseInt(pageNumber, 10) here. Though I'm unsure why it needs parseInt at all? Seems like it should pass through as a normal number.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I think it's the remnants of earlier code that I didn't update after some refactoring. At one point the page number could also come from the query string, making it a string instead of a number.

👍

} else if (!queryParam[x] && qs[x]) {
delete qs[x];
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this is updating qs? Couldn't you just use queryParam below to construct the query string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poor naming on my part. The queryParam argument contains only the key/value pair(s) to update. I'll rename and add a comment.

});

if (Object.keys(qs).length) {
let newQueryString = Object.keys(qs).map(x => `${x}=${encodeURIComponent(qs[x])}`).join('&');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the name should also be quoted, i.e., ${encodeURIComponent(x)}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh! This should've been updated to use stringify from query-string.

👍

function updateHistory(queryParam) {
let url = exports.getNewUrl(queryParam);
window.history.pushState(null, "", url);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with search parameters too? My impression from this code is that it's meant to handle the two parameters at the same time. To enable search you can set DISABLE_SEARCH="", then /shots?q=something will search. Actually I think it'll work regardless, we only hide the search input box, so you can edit the URL and do a search that way. Anyway, would be good to test together.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I had the search feature enabled while I was working on this. 👍

function _render(shots) {
req.shots = shots;
function _render(shotsPage) {
Object.assign(req, shotsPage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me a bit uncomfortable, because there's arbitrary attributes being added to the request now. I'd rather req.shotsPage = shotsPage or else explicitly assigning the individual variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -87,6 +88,62 @@ class Body extends React.Component {
</div>;
}

renderPageNavigation() {
if (parseInt(this.props.totalShots) === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: parseInt(..., 10)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

let totalPages = Math.ceil(this.props.totalShots / this.props.shotsPerPage);
let prevLink = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are prevLink and nextLink functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They certainly don't need to be. 👍

@@ -15,6 +15,9 @@ const PNG_HEADER = Buffer.from(PNG_HEADER_BASE64, "base64");
const JPEG_HEADER_BASE64 = "/9g=";
const JPEG_HEADER = Buffer.from(JPEG_HEADER_BASE64, "base64").slice(0, 2);


const SHOTS_PER_PAGE = 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 seems like a small number. I think 24 would be better. Also divisible by 2, 3, or 4 columns. Well, our current flow isn't a real grid, but I think we intend to turn it back into a grid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ianb
Copy link
Contributor

ianb commented Oct 23, 2017

Note: for little stuff like this, sometimes we keep track / acknowledge the issues by thumbsuping each comment as you address it.

@chenba chenba dismissed ianb’s stale review October 23, 2017 21:24

Made changes based on feedback.

@ianb
Copy link
Contributor

ianb commented Oct 26, 2017

This is ready to land, but I'm going to wait a bit on it so it's not part of the next server release

@ianb ianb merged commit 5bd4583 into mozilla-services:master Oct 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants