-
Notifications
You must be signed in to change notification settings - Fork 77
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
add pagination to results table #96
Conversation
For some reason, I can't make it work with
but it does work with the regular one :) The solution looks good in terms of UI, and anything else :D Good work! |
@ITAYC0HEN had the same problem, you need to do a rebuild first ( |
Looks good! But there are a few things that don't make sense after this change:
|
Thanks, fixed this :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to use lazy loading in the table
If you're up for lazy load then you can reconsider pagination in favor of. lazy load scrolling (like Facebook, Twitter feeds, VT results) |
You forgot mwdb! Yeah, that's a viable solution too. Anything that will make it possible to reduce a number of queries to the backend for a finished large query. I prefer paging, but I can see lazy load working here too. |
src/mqueryfront/src/QueryPage.js
Outdated
}); | ||
|
||
if (newShouldRequest) { | ||
let nextTimeout = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Querying every 50ms may be too extreme. Maybe just hardcode this to 1000ms
?
src/mqueryfront/src/QueryPage.js
Outdated
}) | ||
.catch(() => { | ||
this.setState({ | ||
shouldRequest: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this variable used anywhere? If not, we can remove this safely.
src/mqueryfront/src/QueryPage.js
Outdated
|
||
if ( | ||
["done", "cancelled", "failed", "expired"].indexOf( | ||
response.data.job.status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.data.job probably can be made a local variable
src/mqueryfront/src/QueryPage.js
Outdated
.then((response) => { | ||
let newShouldRequest = true; | ||
|
||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move setState above this, and return in if, instead of using a temprary vraiable here?
src/mqueryfront/src/QueryPage.js
Outdated
let newShouldRequest = true; | ||
|
||
if ( | ||
["done", "cancelled", "failed", "expired"].indexOf( | ||
response.data.job.status | ||
) !== -1 | ||
) { | ||
if (response.data.job.files_processed >= response.data.job.total_files) { | ||
newShouldRequest = false; | ||
} | ||
} | ||
|
||
this.setState({ | ||
job: response.data.job, | ||
}); | ||
|
||
if (newShouldRequest) { | ||
let nextTimeout = | ||
response.data.matches.length >= LIMIT ? 50 : 1000; | ||
this.timeout = setTimeout( | ||
() => this.loadJob(), | ||
nextTimeout | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All my suggestions in one comment:
let newShouldRequest = true; | |
if ( | |
["done", "cancelled", "failed", "expired"].indexOf( | |
response.data.job.status | |
) !== -1 | |
) { | |
if (response.data.job.files_processed >= response.data.job.total_files) { | |
newShouldRequest = false; | |
} | |
} | |
this.setState({ | |
job: response.data.job, | |
}); | |
if (newShouldRequest) { | |
let nextTimeout = | |
response.data.matches.length >= LIMIT ? 50 : 1000; | |
this.timeout = setTimeout( | |
() => this.loadJob(), | |
nextTimeout | |
); | |
} | |
let job = response.data.job; | |
this.setState({ | |
job: job, | |
matches: response.data.matches, | |
}); | |
let doneStatuses = ["done", "cancelled", "failed", "expired"]; | |
let isDone = doneStatuses.indexOf(job.status) !== -1; | |
let processedAll = job.files_processed >= job.total_files; | |
if (isDone && processedAll) { | |
return; | |
} | |
this.timeout = setTimeout(() => this.loadJob(), 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this rewrite it also shows a bug (that I think was there even before your changes) - if the job is cancelled/failed but it didn't process all files, mquery will keep querying the backend. Maybe it should be ||
instead of &&
?
@@ -63,13 +64,29 @@ class QueryResultsStatus extends Component { | |||
constructor(props) { | |||
super(props); | |||
|
|||
this.state = { | |||
activePage: 1, | |||
itemPerPage: 20, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plural:
itemPerPage: 20, | |
itemsPerPage: 20, |
|
||
if (this.props.job.status === "expired") { | ||
return ReturnExpiredJob(this.props.job.error); | ||
} | ||
|
||
// var indexOfLastMatch = this.state.activePage * this.state.itemPerPage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary comments
<div> | ||
<Pagination | ||
activePage={this.state.activePage} | ||
itemsCountPerPage={this.state.itemPerPage} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
itemsCountPerPage={this.state.itemPerPage} | |
itemsCountPerPage={this.state.itemsPerPage} |
handlePageChange(pageNumber) { | ||
this.setState({ activePage: pageNumber }); | ||
this.sendResultsActivePage(pageNumber); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary empty line
src/mqueryfront/src/QueryPage.js
Outdated
|
||
loadMatches() { | ||
const LIMIT = 20; | ||
let OFFSET = (this.state.activePage - 1) * 20 + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why +1
?
Nitpick: doing a new query should reset active page number (if i go to the 8th page, run a new query, pagination will automatically start at the 8th page) |
And also: please rebase your changes on the master, since there are merge conflicts |
src/app.py
Outdated
files_processed=job.get("files_processed", 0), | ||
files_matched=job.get("files_matched", 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
files_processed=job.get("files_processed", 0), | |
files_matched=job.get("files_matched", 0), | |
files_processed=int(job.get("files_processed", 0)), | |
files_matched=int(job.get("files_matched", 0)), |
d4cc2d5
to
5d7b3cc
Compare
@@ -164,6 +184,19 @@ class QueryResultsStatus extends Component { | |||
</thead> | |||
<tbody>{matches}</tbody> | |||
</table> | |||
{lenMatches > 20 && ( | |||
<div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think div is unnecessary here?
src/mqueryfront/src/QueryPage.js
Outdated
let doneStatuses = ["done", "cancelled", "failed", "expired"]; | ||
let isDone = doneStatuses.indexOf(job.status) !== -1; | ||
let processedAll = job.files_processed >= job.total_files; | ||
if (isDone && processedAll) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still &&
? If nothing else changed, this will cause infinite loop of requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also confirmed it locally. Test plan:
- start a big query
- stop it in a middle such that files_processed < total_files (remember that they're strings)
- observe that requests are repeated in the loop every 1s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to go as soon as tests pass
* Add pagination to results table
Close issue #39 #37