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 … |
chipx86 | |
Make sure all new variables are declared with var at the top. Also, we only ever want one var statement … |
chipx86 | |
We should wrap this for translation, and use single quotes: tooltip = gettext('New file'); |
david | |
We should wrap this for translation, and use single quotes: tooltip = gettext('Deleted file'); |
david | |
There's not a ton of reason to have this be an "else if" -- we can just have this be … |
david | |
The translation utilities provide nice pluralization and formatting capabilities: tooltip += interpolate( ngettext('%s new line', '%s new lines', numInserts), [numInserts]) … |
david | |
There should be blank lines between blocks (like if statements, for loops, etc.) and other code. So, blank line here, … |
chipx86 | |
Alignment errors. |
chipx86 | |
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 … |
david | |
We're querying the diff icon twice here as well. These sort of lookups are expensive, and we want to be … |
chipx86 | |
We should call this variable $fileIcon to indicate that it's a jquery. |
david | |
Trailing whitespace, and since we're indenting the second argument, let's put the first on its own line too: $fileIcon.attr( 'title', … |
david | |
Call this $fileIcon. |
david | |
How about tooltipParts instead of mods? |
david | |
Technically this should be %d instead of %s. |
brennie | |
%d |
brennie | |
%d |
brennie | |
Trailing whitespace. |
david | |
Trailing whitespace. |
david |
-
-
-
-
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
.attr
method:$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
var
at the top. Also, we only ever want onevar
statement 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