Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Refactoring builders [do not merge] #1919

Closed
wants to merge 92 commits into from

Conversation

annthurium
Copy link

This pull request extracts a PatchBuffer out of the common code in (three) places we build up TextBuffers with Markers organized into MarkerLayers (hunks, patches, additions, deletions, unchanged lines...). It also adds operations to the PatchBuffer model that will let us build them and manipulate them as you expand and collapse individual patches, preserving marker locations.

Also, we changed test/builders/patch.js to build "raw" what-the-diff output and use the "real" builders to build model objects and getting our tests green where those are used.

vanessayuenn and others added 30 commits January 14, 2019 19:45
Co-Authored-By: Vanessa Yuen <vanessayuenn@users.noreply.github.com>
...not sure how we would get into this situation, but it seems like an 
important case to cover.
unnecessary console output during tests is a bummer.
Copy link
Author

@annthurium annthurium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good so far -- just found a few nits to address.

@@ -19,6 +19,7 @@ export default class PullRequestReviewsController extends React.Component {
),
}),
getBufferRowForDiffPosition: PropTypes.func.isRequired,
isPatchTooLargeOrCollapsed: PropTypes.func.isRequired,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a really long name -- can you come up with something more concise?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just isPatchCollapsed?

}
}

isPatchTooLargeOrCollapsed = filePatchPath => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above - this name is too long and the line length linters are gonna be unhappy.

};
return shallow(
<PullRequestCommentsView
isPatchTooLargeOrCollapsed={sinon.stub().returns(false)}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this variable name is too long

@@ -16,7 +16,7 @@ export default class CommitDetailController extends React.Component {
this.state = {
messageCollapsible: this.props.commit.isBodyLong(),
messageOpen: !this.props.commit.isBodyLong(),
};
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind adding the missing semicolon here?

Copy link
Contributor

@simurai simurai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition. Before merging we might should rethink the position of the icon.

@@ -42,12 +49,32 @@ export default class FilePatchHeaderView extends React.Component {
<header className="github-FilePatchView-header">
<span className="github-FilePatchView-title">
{this.renderTitle()}
{this.renderCollapseButton()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move the chevron icon to the left? So that the position doesn't jump when there are more buttons. Alternative would be to move it all the way to the right.

export const DEFAULT_OPTIONS = {
// Number of lines after which we consider the diff "large"
// TODO: Set this based on performance measurements
largeDiffThreshold: 100,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simurai: how many lines do you think constitutes a large diff? Not just from a performance perspective, but from a user experience perspective. Like how many lines is disruptive to a user when they're trying to read, because often large diffs are the result of auto generated code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.. will large diffs be collapsed by default or there is a "load" button? Maybe if the diff is so large that it fills the whole scroll height. Then I can uncollapse only if I'm really interested in that file. 100 seems fine. 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@vanessayuenn vanessayuenn Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm we were using 1000 lines as the threshold before, but that's for performance reasons. 100 does seem a bit small though considering it's counting both deleted and added lines. 🤔

300 seems a bit more reasonable, but still an arbitrary number.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but still an arbitrary number.

Would this be good as a package option then? Pick a value that should work for most users, but let people who need to configure it. Also, would that be something that can be refined by metrics?

@codecov
Copy link

codecov bot commented Jan 25, 2019

Codecov Report

Merging #1919 into master will decrease coverage by 1.29%.
The diff coverage is 81.41%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1919     +/-   ##
=========================================
- Coverage    92.1%   90.81%   -1.3%     
=========================================
  Files         189      190      +1     
  Lines       10783    11184    +401     
  Branches     1580     1624     +44     
=========================================
+ Hits         9932    10157    +225     
- Misses        851     1027    +176
Impacted Files Coverage Δ
lib/controllers/pr-reviews-controller.js 100% <ø> (ø) ⬆️
lib/controllers/commit-detail-controller.js 100% <ø> (ø) ⬆️
lib/models/repository-states/present.js 93.14% <100%> (-6.86%) ⬇️
lib/models/patch/builder.js 100% <100%> (ø) ⬆️
lib/views/file-patch-header-view.js 92.3% <42.85%> (-7.7%) ⬇️
lib/views/pr-review-comments-view.js 95% <50%> (-5%) ⬇️
lib/views/multi-file-patch-view.js 99.51% <60%> (-0.49%) ⬇️
lib/models/patch/file-patch.js 89.44% <67.3%> (-10.56%) ⬇️
lib/models/patch/patch.js 92.2% <73.56%> (-7.8%) ⬇️
lib/models/patch/patch-buffer.js 77.85% <77.85%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b509125...aa41930. Read the comment docs.

@todo
Copy link

todo bot commented Jan 25, 2019

Set this based on performance measurements

// TODO: Set this based on performance measurements
largeDiffThreshold: 100,
// Map of file path (relative to repository root) to Patch render status (EXPANDED, COLLAPSED, TOO_LARGE)
renderStatusOverrides: {},
};


This comment was generated by todo based on a TODO comment in e6a74b0 in #1919. cc @atom.

@todo
Copy link

todo bot commented Jan 25, 2019

Set this based on performance measurements

// TODO: Set this based on performance measurements
largeDiffThreshold: 100,
// Map of file path (relative to repository root) to Patch render status (EXPANDED, COLLAPSED, TOO_LARGE)
renderStatusOverrides: {},
};


This comment was generated by todo based on a TODO comment in aa41930 in #1919. cc @atom.

@todo
Copy link

todo bot commented Jan 25, 2019

do something with large diff too

// TODO: do something with large diff too
}
const [hunks, patchMarker] = buildHunks(contentChangeDiff, patchBuffer);
const patch = new Patch({status, hunks, marker: patchMarker});


This comment was generated by todo based on a TODO comment in e6a74b0 in #1919. cc @atom.

@todo
Copy link

todo bot commented Jan 25, 2019

do something with large diff too

// TODO: do something with large diff too
}
const [hunks, patchMarker] = buildHunks(contentChangeDiff, patchBuffer);
const patch = new Patch({status, hunks, marker: patchMarker});


This comment was generated by todo based on a TODO comment in aa41930 in #1919. cc @atom.

simurai added a commit that referenced this pull request Jan 25, 2019
Copy link
Contributor

@vanessayuenn vanessayuenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! 🚢

@@ -19,6 +19,7 @@ export default class PullRequestReviewsController extends React.Component {
),
}),
getBufferRowForDiffPosition: PropTypes.func.isRequired,
isPatchTooLargeOrCollapsed: PropTypes.func.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just isPatchCollapsed?

@@ -27,13 +29,26 @@ export default class ChangedFileContainer extends React.Component {
constructor(props) {
super(props);
autobind(this, 'fetchData', 'renderWithData');

this.lastMultiFilePatch = null;
this.sub = new CompositeDisposable();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one line comment -- not part of a review.

@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';
import {CompositeDisposable} from 'event-kit';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lalalala

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants