-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/logs paging active #318
Conversation
It introduces two new variables to the status: logsFilter: function that selects the relevant logs (we use it to show only the logs that include the selected datasets). logsPageLast: index of the last page that we have retrieved so far. The Log dialog now contains a new action, a flat button that allows it to load logs from previous pages. There are new semantics for the getLogs() function: if it returns null, then there are no more log pages (so we do not need to request more). Also, the pages are a positive number, that is, page 1 is the page previous to the last one (instead of it being page -1).
Remove the optimization for not retrieving the dataStore multiple times unnecessarily. It turns out that it is negligible, and thus it is better to have a simpler code.
So, when concatenated, the position of the last log is predictable (it is in position 0), and also of the most recent log (it is in the last position of the array).
When requesting a new log page in the log dialog, it will now show a button that includes the date of the last log retrieved so far.
So we show the correct date in the button to get older log pages.
src/DataSets/DataSets.component.js
Outdated
@@ -74,6 +74,10 @@ const DataSets = React.createClass({ | |||
}; | |||
}, | |||
|
|||
tr(text, variables={}) { |
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.
Very minor: variables={}
is idiomatic Python for keyword args, but AFAIK in JS is idiomatic to write the spaces: variables = {}
src/DataSets/DataSets.component.js
Outdated
if (Array.isArray(datasets)) { | ||
const ids = datasets.map(ds => ds.id); | ||
const idsSet = new Set(ids); | ||
this.state.logsFilter = log => log.datasets.some(ds => idsSet.has(ds.id)); |
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.
Imperatively modifying this.state is forbidden in React (except the initial set in a constructor) -> this.setState({...})
.
src/DataSets/DataSets.component.js
Outdated
} | ||
|
||
let title = this.tr("logs"); | ||
if (Array.isArray(datasets)) { |
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.
This kind of checks is a hint that a refactor is needed. I see openLogs
is called on the global button onClick
, it gets the mouse event, which is what is being compared here. I'd create a separate openAllLogs
method for that action.
src/DataSets/DataSets.component.js
Outdated
addLogs(pages) { | ||
// Add logs from the given log pages (to the already loaded logs if any). | ||
if (!Array.isArray(pages)) | ||
pages = [this.state.logsPageLast + 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.
To avoid this check+rebinding of pages
, we can make sure the caller sends the correct values. I think the check is needed in onClick={this.addLogs}
.
src/DataSets/DataSets.component.js
Outdated
this.setState({logsPageLast: -1}); | ||
} else { | ||
const logsOldestDate = logs.length > 0 ? logs[logs.length - 1].date : null; | ||
logs = _(logs).filter(this.state.logsFilter).value(); |
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.
Avoid rebinding/reuse of variables, create new const
values with descriptive names -> const filteredLogs = ...
src/DataSets/DataSets.component.js
Outdated
@@ -303,21 +332,37 @@ const DataSets = React.createClass({ | |||
|
|||
const logActions = [ | |||
<FlatButton | |||
label={this.getTranslation('close')} | |||
label={(this.state.logsPageLast < 0 ? this.tr("logs_no_older") : this.tr("logs_older")) + |
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.
Too much logic for a prop, we can use a variable.
src/DataSets/log.js
Outdated
const store = await getStore(); | ||
const logsPageCurrent = await store.get('logs-page-current').catch(() => 0); | ||
const pagesNames = pages.map(n => 'logs-page-' + mod(logsPageCurrent - n, maxLogPages)); | ||
const logs = await Promise.all(pagesNames.map(name => store.get(name).catch(() => null))); |
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 seen there is a way to avoid 404 on non-existing pages. The store has a method to get the current keys. Thus we could also remove the catch
, which might mask real problems (network issues/implementation bugs). Just an idea:
const storeKeys = new Set(await store.getKeys());
const existingPageNames = pagesNames.filter(name => storeKeys.has(name));
const logs = await Promise.all(existingPageNames.map(name => store.get(name)));
src/DataSets/DataSets.component.js
Outdated
@@ -303,21 +332,37 @@ const DataSets = React.createClass({ | |||
|
|||
const logActions = [ | |||
<FlatButton | |||
label={this.getTranslation('close')} | |||
label={(this.state.logsPageLast < 0 ? this.tr("logs_no_older") : this.tr("logs_older")) + |
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.
Related to the 404 avoidance for non-existing pages, I was thinking we could use the same idea: since we already know the existing pages in the store, we can hide the button if we are sure there is no more data to load.
@@ -303,21 +332,37 @@ const DataSets = React.createClass({ | |||
|
|||
const logActions = [ | |||
<FlatButton |
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.
A question about the UX, @adrianq : does it make sense to move this action inside the logs box, as a center button? this way the user only sees it when it really makes sense.
- Apply styling (spaces/indent) - Create wrapper methods openAllLogs/addNextLog - Render loadMoreLogs button only if necessary - Move loadMoreLogs button to logs list - Abstract logs.getCurrentPage - Refactor getLogs - Fix: Clear always next page in the circular buffer - Format date in logs rendering.
I've applied all my proposed changes and some extra refactor. Also implements the "sharing: save only on changes" feature, which requires EyeSeeTea/d2-ui#20 |
Task "Sharing: Move logging to parent component, so it logs only once when dialog is closed." -> Done. Ready to test again. |
Add a "get more logs" button that loads logs from previous pages.
There are no changes to the dataStore configuration, we just use it appropriately in the main application to show older logs on request.