Added tooltips for the graphs that represent diff change summaries in the diff viewer.
Review Request #7880 — Created Jan. 16, 2016 and submitted
Right now, the diff viewer shows graphs beside each modified file to show whether or not files were added/deleted, how many lines were inserted/changed/deleted, or if there was an error loading the diff information for a given file.
Users were able to depict what the graphs typically mean, however it was desired that tooltips were added for each of the icons to give a detailed description of the change summary for that file.
In my local environment I posted reviews with every type of modification to a file (as well as an erroneous diff of a file) to ensure tooltip was both correct and displaying properly.
| Description | From | Last Updated |
|---|---|---|
|
We already query this element once. We don't want to do it again, so let's pull it out into a … |
|
|
|
Make sure all new variables are declared with var at the top. Also, we only ever want one var statement … |
|
|
|
We should wrap this for translation, and use single quotes: tooltip = gettext('New file'); |
|
|
|
We should wrap this for translation, and use single quotes: tooltip = gettext('Deleted file'); |
|
|
|
There's not a ton of reason to have this be an "else if" -- we can just have this be … |
|
|
|
The translation utilities provide nice pluralization and formatting capabilities: tooltip += interpolate( ngettext('%s new line', '%s new lines', numInserts), [numInserts]) … |
|
|
|
There should be blank lines between blocks (like if statements, for loops, etc.) and other code. So, blank line here, … |
|
|
|
Alignment errors. |
|
|
|
Since we're using jquery, we can use the .attr method: $item.find('.diff-file-icon').attr('title', tooltip); We probably also don't need to gate it … |
|
|
|
We're querying the diff icon twice here as well. These sort of lookups are expensive, and we want to be … |
|
|
|
We should call this variable $fileIcon to indicate that it's a jquery. |
|
|
|
Trailing whitespace, and since we're indenting the second argument, let's put the first on its own line too: $fileIcon.attr( 'title', … |
|
|
|
Call this $fileIcon. |
|
|
|
How about tooltipParts instead of mods? |
|
|
|
Technically this should be %d instead of %s. |
|
|
|
%d |
|
|
|
%d |
|
|
|
Trailing whitespace. |
|
|
|
Trailing whitespace. |
|
-
-
-
-
There's not a ton of reason to have this be an "else if" -- we can just have this be an "else" clause and let the inner conditionals do this work.
-
The translation utilities provide nice pluralization and formatting capabilities:
tooltip += interpolate( ngettext('%s new line', '%s new lines', numInserts), [numInserts])It might also be nice to do this by creating an array of parts and using
', '.join(parts).There's also some trailing whitespace introduced in here.
-
Since we're using jquery, we can use the
.attrmethod:$item.find('.diff-file-icon').attr('title', tooltip);We probably also don't need to gate it in the if statement because if the tooltip is empty, we'll just set the title to an empty string.
-
-
We already query this element once. We don't want to do it again, so let's pull it out into a variable that both statements can use.
We also need to localize the text by calling
gettext('...').Along with this, we want more user-friendly error messages. "There was an error loading the diff. See the details below." sort of a thing.
-
Make sure all new variables are declared with
varat the top. Also, we only ever want onevarstatement per function. See how we do it in other blocks of code. -
There should be blank lines between blocks (like if statements, for loops, etc.) and other code. So, blank line here, and same with ones below.
-
-
We're querying the diff icon twice here as well. These sort of lookups are expensive, and we want to be as careful as possible to not do them more than once.
- Groups:
- Bugs:
- Change Summary:
-
Reduced DOM tree traversals by putting the element in a variable, utilized localization method for strings, declared variables properly, and cleaned up the generation of tooltip message.
-
Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/diffviewer/views/diffFileIndexView.js Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/diffviewer/views/diffFileIndexView.js
Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/diffviewer/views/diffFileIndexView.js Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/diffviewer/views/diffFileIndexView.js