[WIP] Core functionality for file diff collapsing

Review Request #9431 — Created Dec. 10, 2017 and discarded

Information

Review Board
release-3.0.x

Reviewers

When viewing the diff of a review request not all files need to be
viewed, for example minified files don't need to be reviewed. It is
also helpful to have a way to hide files you have already reviewed.

Now files can be collapsed and expanded as the user wishes. Also,
minified files are collapsed by default.

If a minified file is also a deleted, moved/copied, binary (I'm not
sure if this is even a possibility), or a new empty file then it will
not be collapsed by default because there will just be a short
message displayed instead of a large, one-line diff.

Collapsing a diff does not work especially elegantly when the file only
contains whitespace changes. In this case the Hide/Show whitespace
changes button can also be used to collapse the file. So the file
can't be viewed unless both buttons allow it to be. One fix for this
would be to hide the new button whenever a file is collapsed with the
Hide/Show whitespace changes button. (This fix can be done in a
separate review request)

A few small changes were also made related to chunk highlighting.
Previously the minimum height of the highlight was 1, this was changed
to 0 because when a chunk was highlighted then its file was collapsed
there would be a 1px tall highlight left behind.

Also, previously collapsing a file with either button would leave the
highlight in the same position. Now it will be updated to match the
shifted position of the chunk whenever either button is used to
collapse or expand.

A change I made to renderers.py had caused an error in the test
test_make_context_with_chunk_index, but this has been fixed now.

I have added tests to verify that the minified property added to
diffutils is working correctly (returns true if
depot_filename contains .min., and false otherwise).

Unit tests have also been added to verify that the new context
variable collapse_file is set properly in various situations.
A couple of the new tests
test_make_context_with_collapse_file_using_unchanged_file and
test_make_context_with_collapse_file_using_file_with_no_chunks
may be unnecessary, because I'm not sure if a file can have
'num_changes': 0 without having 'moved_or_copied': True
or 'num_chunks': 0 without 'newfile': True

Two new unit tests have been added to verify that the new onClick
event properly updates the classes of the button icon and tbodies
related to that file.

Preferably, additional unit tests would be written to verify that
the onClick event updates only the classes of elements related
to the desired file. I don't think this will be difficult, but
right now I'm not sure how to do it without doubling the size of
the html template in diffReviewableViewTests.js and possibly
needing to adjust many of the other tests in that file.
This is the only reason the review request is still WIP

Description From Last Updated

F841 local variable 'filediff' is assigned to but never used

reviewbotreviewbot

E231 missing whitespace after ','

reviewbotreviewbot

F841 local variable 'filediff' is assigned to but never used

reviewbotreviewbot

E231 missing whitespace after ','

reviewbotreviewbot

Col: 17 '$buttonIcon' is defined but never used.

reviewbotreviewbot

E501 line too long (80 > 79 characters)

reviewbotreviewbot

You could turn this into a one-liner if you wanted. height = chunkEl.clientHeight ? chunkEl.clientHeight + 1 : 0;

TB tbrockma
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

RC
Review request changed
Description:
   

When viewing the diff of a review request not all files need to be

    viewed, for example minified files don't need to be reviewed. It is
    also helpful to have a way to hide files you have already reviewed.

   
   

Now files can be collapsed and expanded as the user wishes. Also,

    minified files are collapsed by default.

   
   

If a minified file is also a deleted, moved/copied, binary (I'm not

    sure if this is even a possibility), or a new empty file then it will
    not be collapsed by default because there will just be a short
    message displayed instead of a large, one-line diff.

   
-  

-  
   

Collapsing a diff does not work especially elegantly when the file only

    contains whitespace changes. In this case the Hide/Show whitespace
    changes button can also be used to collapse the file. So the file
    can't be viewed unless both buttons allow it to be. One fix for this
    would be to hide the new button whenever a file is collapsed with the
    Hide/Show whitespace changes button.

  +
  +

  +
  +

A few small changes were also made related to chunk highlighting.

  +
  +

Previously the minimum height of the highlight was 1, this was changed

  + to 0 because when a chunk was highlighted then its file was collapsed
  + there would be a 1px tall highlight left behind.

  +
  +

Also, previously collapsing a file with either button would leave the

  + highlight in the same position. Now it will be updated to match the
  + shifted position of the chunk whenever either button is used to
  + collapse or expand.

Testing Done:
   

A change I made to renderers.py had caused an error in the test

    test_make_context_with_chunk_index, but this has been fixed now.

   
   

I have added tests to verify that the minified property added to

    diffutils is working correctly (ie, returns true if
    depot_filename contains .min., and false if not.

   
  +

Two new unit tests have been added to verify that the new onClick

  + event properly updates the classes of the button icon and tbodies
  + related to that file.

  +
   

   
~  

Additional front end tests need to be added to verify that the

~   new onclick function properly updates the classes of the
~   corresponding diff and only that diff.

  ~

Preferably, additional unit tests would be written to verify that

  ~ the onClick event updates only the classes of elements related
  ~ to the desired file. I don't think this will be difficult, but
  + right now I'm not sure how to do it without doubling the size of
  + the html template in diffReviewableViewTests.js and possibly
  + needing to adjust many of the other tests in that file.

   
   

Other tests needed to verify the default state of files.

    (only collapsed upon loading the page if it is minified and not
    deleted, copied, moved, binary, or new-empty).

  +
  +

Other tests needed to verify the additional chunk highlighting

  + updates work as expected. (when a file is collapsed or expanded,
  + the highlighting is updated).

Commit:
a2eeaba62db64487228cbac243a6e508dd1a289e
bbf41e8a9df370741e75491d7e6d4c75e8b37cdf

Checks run (1 failed, 1 succeeded)

flake8 passed.
JSHint failed.

JSHint

RC
Review request changed
Description:
   

When viewing the diff of a review request not all files need to be

    viewed, for example minified files don't need to be reviewed. It is
    also helpful to have a way to hide files you have already reviewed.

   
   

Now files can be collapsed and expanded as the user wishes. Also,

    minified files are collapsed by default.

   
   

If a minified file is also a deleted, moved/copied, binary (I'm not

    sure if this is even a possibility), or a new empty file then it will
    not be collapsed by default because there will just be a short
    message displayed instead of a large, one-line diff.

   
   

Collapsing a diff does not work especially elegantly when the file only

    contains whitespace changes. In this case the Hide/Show whitespace
    changes button can also be used to collapse the file. So the file
    can't be viewed unless both buttons allow it to be. One fix for this
    would be to hide the new button whenever a file is collapsed with the
    Hide/Show whitespace changes button.

   
   

   
~  

A few small changes were also made related to chunk highlighting.

~  
  ~

A few small changes were also made related to chunk highlighting.

  ~ Previously the minimum height of the highlight was 1, this was changed
-  

Previously the minimum height of the highlight was 1, this was changed

    to 0 because when a chunk was highlighted then its file was collapsed
    there would be a 1px tall highlight left behind.

   
   

Also, previously collapsing a file with either button would leave the

    highlight in the same position. Now it will be updated to match the
    shifted position of the chunk whenever either button is used to
    collapse or expand.

Testing Done:
   

A change I made to renderers.py had caused an error in the test

    test_make_context_with_chunk_index, but this has been fixed now.

   
   

I have added tests to verify that the minified property added to

~   diffutils is working correctly (ie, returns true if
~   depot_filename contains .min., and false if not.

  ~ diffutils is working correctly (returns true if
  ~ depot_filename contains .min., and false otherwise).

  +
  +

Unit tests have also been added to verify that the new context

  + variable collapse_file is set properly in various situations.
  + A couple of the new tests
  + test_make_context_with_collapse_file_using_unchanged_file and
  + test_make_context_with_collapse_file_using_file_with_no_chunks
  + may be unnecessary, because I'm not sure if a file can have
  + 'num_changes': 0 without having 'moved_or_copied': True
  + or 'num_chunks': 0 without 'newfile': True

   
   

Two new unit tests have been added to verify that the new onClick

    event properly updates the classes of the button icon and tbodies
    related to that file.

   
   

   
   

Preferably, additional unit tests would be written to verify that

    the onClick event updates only the classes of elements related
    to the desired file. I don't think this will be difficult, but
    right now I'm not sure how to do it without doubling the size of
    the html template in diffReviewableViewTests.js and possibly
    needing to adjust many of the other tests in that file.

-  
-  

Other tests needed to verify the default state of files.

-   (only collapsed upon loading the page if it is minified and not
-   deleted, copied, moved, binary, or new-empty).

-  
-  

Other tests needed to verify the additional chunk highlighting

-   updates work as expected. (when a file is collapsed or expanded,
-   the highlighting is updated).

Commit:
bbf41e8a9df370741e75491d7e6d4c75e8b37cdf
84007a82efcc02f34d627d624f09a744a746be46

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

RC
RC
TB
  1. 
      
  2. Show all issues

    You could turn this into a one-liner if you wanted.

    height = chunkEl.clientHeight ? chunkEl.clientHeight + 1 : 0;

  3. 
      
david
Review request changed
Status:
Discarded