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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
a8bea5f
when diff is decided to be "too large", we skip hunk building and ret…
vanessayuenn Jan 14, 2019
e2862ea
visually display the diff gate
vanessayuenn Jan 14, 2019
a9db48f
experimenting wiht a DelayedPatch but idk
vanessayuenn Jan 16, 2019
f621d49
Delayed patch parsing
smashwilson Jan 16, 2019
a729493
Correct pre-existing markers after building patch hunks
smashwilson Jan 16, 2019
68926e5
:shirt:
smashwilson Jan 16, 2019
4686cfc
get things to render properly first
vanessayuenn Jan 16, 2019
0c3a2a6
Accept renderStatusOverrides in ye MultiFilePatch builder
smashwilson Jan 16, 2019
7db6fb0
Pass builder options to getFilePatchForPath and getStagedChangesPatch
smashwilson Jan 16, 2019
9de0eae
some clean up
vanessayuenn Jan 16, 2019
e8f372a
click to show diff???
vanessayuenn Jan 16, 2019
dc04f49
Add a renderStatus to Patch
smashwilson Jan 16, 2019
f0b8371
Emit events from a FilePatch when its render status changes
smashwilson Jan 16, 2019
9dad4f7
Unit tests for FilePatch render status events
smashwilson Jan 16, 2019
cd5cc28
Remember changed renderStatus
smashwilson Jan 16, 2019
7eab119
add collapse button to file patch header
Dec 21, 2018
b251264
Use a Marker instead of a Point to track delayed patch location
smashwilson Jan 16, 2019
0bfacb6
Track changed renderStatus in CommitPreviewContainer
smashwilson Jan 16, 2019
40cde30
Ditto for CommitDetailContainer
smashwilson Jan 16, 2019
be2ab8f
fix bad parens in mfp builder
Jan 16, 2019
e28522e
don't render pull request comments if patch exceeds large diff threshold
Jan 16, 2019
b66c88c
use a Map to avoid iterating through patches
Jan 16, 2019
98fbfc9
deal with null patches
Jan 16, 2019
ccf2a99
:shirt:
Jan 16, 2019
26ee209
danananana PROP TYPES
Jan 16, 2019
010cd56
also check for COLLAPSED patch state
Jan 17, 2019
cd2b7f9
honk if you like test helpers
Jan 17, 2019
8324cb3
clean up pr comments builder
Jan 17, 2019
ee6c9c2
[wip] add tests for `isPatchTooLargeOrCollapsed`
Jan 17, 2019
0733676
Test case for Patch Marker movement
smashwilson Jan 17, 2019
1237458
Extract LayeredBuffer class and use it consistently in Patch logic
smashwilson Jan 17, 2019
f963e75
Rename LayeredBuffer to PatchBuffer
smashwilson Jan 17, 2019
6df1380
Begin an "atomic" (with respect to markers) Modification API
smashwilson Jan 17, 2019
3b34099
import LARGE_DIFF_THRESHOLD
Jan 17, 2019
49b406d
Preserve Markers that begin or end at a Modification's insertion point
smashwilson Jan 17, 2019
a2d453c
PatchBuffer::extract() to slice a Range out and preserve its markers
smashwilson Jan 17, 2019
34e104a
Unit test for inserting one PatchBuffer into another
smashwilson Jan 17, 2019
dfc2fee
actually trigger expanding and collapsing from `FilePatchHeaderView`
Jan 18, 2019
ebdec24
change the chevron icon direction depending on collapsed prop
Jan 18, 2019
01b82f0
Implement appendPatchBuffer()
smashwilson Jan 18, 2019
2d7c2f4
Translate Markers when extracting and appending PatchBuffers midline
smashwilson Jan 18, 2019
03e03f3
Renamings
smashwilson Jan 18, 2019
400d1b8
Rename Inserter methods as "insert..." instead of "append..."
smashwilson Jan 18, 2019
37f9ae6
Produce Maps of equivalent Markers after extract/insert PatchBuffers
smashwilson Jan 18, 2019
498c720
Inserter::markWhile() to mark all changes made in a block
smashwilson Jan 18, 2019
5c8181e
Rewrite buildHunks() to use an Inserter
smashwilson Jan 18, 2019
1a74e83
[wip] make patch model use `nextLayeredBuffer`
Jan 22, 2019
510c887
PatchBuffer::inspect() to debug marker placement
smashwilson Jan 22, 2019
18ff065
PatchBuffer::findAllMarkers() to query markers across all layers
smashwilson Jan 22, 2019
5283be0
Clip insertion point to valid buffer positions
smashwilson Jan 22, 2019
c56becb
Fluent APIs
smashwilson Jan 22, 2019
d6e5947
No need to manually touch up patch/hunk markers
smashwilson Jan 22, 2019
4c39a4b
Insert newlines *between* consecutive patches, hunks, regions
smashwilson Jan 22, 2019
62951be
Need IIFEs for callbacks created within loops
smashwilson Jan 22, 2019
0187f4c
buildHunks() always inserts at the end
smashwilson Jan 22, 2019
07f3c88
:fire: trailing newline
smashwilson Jan 22, 2019
f4ea1a2
Remove console.logs :eyes:
smashwilson Jan 22, 2019
57c03e1
Mark zero-length patches
smashwilson Jan 22, 2019
869ec0e
[wip] make Patch model tests use a PatchBuffer
Jan 23, 2019
d1fcf70
:fire: .only
Jan 23, 2019
d13d184
DelayedPatch :point_right: HiddenPatch
smashwilson Jan 23, 2019
d25db25
More trailing newlines
smashwilson Jan 23, 2019
92a1130
updateMarkers methods to consume marker Maps
smashwilson Jan 23, 2019
70ea302
Implement HiddenPatch
smashwilson Jan 23, 2019
24515a1
Get starting and ending Marker sets
smashwilson Jan 23, 2019
f27f5ab
Create a HiddenFilePatch for diff sets that are too large
smashwilson Jan 23, 2019
36ac87c
Move collapsing and expanding to MFP
smashwilson Jan 23, 2019
4bba2f4
Use getRenderStatus() methods
smashwilson Jan 23, 2019
5ca5f12
Use MFP-level expand and collapse methods
smashwilson Jan 23, 2019
fae0a50
Show specific marker layers in PatchBuffer::inspect()
smashwilson Jan 23, 2019
219a409
Implement inspect() methods on patch model classes
smashwilson Jan 23, 2019
9767a87
destroyMarkers() calls to... destroy... the markers
smashwilson Jan 23, 2019
b1d7ff5
Build hunk data for expanding too-large patches on the correct buffer
smashwilson Jan 23, 2019
fc3d89c
Fix up Marker-keyed maps in MFP after expand or collapse
smashwilson Jan 23, 2019
e1a1a5c
NullPatch implementations of adjacent-marker methods
smashwilson Jan 23, 2019
37c53ca
Defer insertPatchBuffer()'s callback until the marker map is populated
smashwilson Jan 23, 2019
9d174a3
More collapse and expand work
smashwilson Jan 23, 2019
a0ae01c
Find adjacent FilePatches by array index instead of markers
smashwilson Jan 23, 2019
cba6f05
Remove unused argument
smashwilson Jan 23, 2019
715f10a
Touch up expected marker range
smashwilson Jan 23, 2019
cff0d29
Correct expected Hunk header
smashwilson Jan 23, 2019
2d7c81a
Build what-the-diff output instead of just model objects
smashwilson Jan 23, 2019
537fd0e
Fix building symlink related FilePatches
smashwilson Jan 23, 2019
6685330
::reMarkOn() accepts a PatchBuffer
smashwilson Jan 23, 2019
2cd40d3
Adapt MultiFilePatch tests to model changes
smashwilson Jan 23, 2019
5af6a87
Distinguish between unset and null files
smashwilson Jan 24, 2019
8bab5ed
Set file patch status on symlink pairs
smashwilson Jan 24, 2019
97154cb
fp3 isn't supposed to be a symlink change?
smashwilson Jan 24, 2019
5b35a4f
Use MFP-level collapse and expand functions
smashwilson Jan 24, 2019
ecb49ea
Retain the TextBuffer within a PatchBuffer
smashwilson Jan 24, 2019
e6a74b0
NullPatch::reMarkOn() accepts a PatchBuffer
smashwilson Jan 24, 2019
aa41930
nits nits nits
Jan 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion lib/containers/changed-file-container.js
Original file line number Diff line number Diff line change
@@ -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


import {autobind} from '../helpers';
import ObserveModel from '../views/observe-model';
Expand All @@ -12,6 +13,7 @@ export default class ChangedFileContainer extends React.Component {
repository: PropTypes.object.isRequired,
stagingStatus: PropTypes.oneOf(['staged', 'unstaged']),
relPath: PropTypes.string.isRequired,
largeDiffThreshold: PropTypes.number,

workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
Expand All @@ -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.


this.state = {renderStatusOverride: null};
}

fetchData(repository) {
const staged = this.props.stagingStatus === 'staged';

const builder = {};
if (this.state.renderStatusOverride !== null) {
builder.renderStatusOverrides = {[this.props.relPath]: this.state.renderStatusOverride};
}
if (this.props.largeDiffThreshold !== undefined) {
builder.largeDiffThreshold = this.props.largeDiffThreshold;
}

return yubikiri({
multiFilePatch: repository.getFilePatchForPath(this.props.relPath, {staged}),
multiFilePatch: repository.getFilePatchForPath(this.props.relPath, {staged, builder}),
isPartiallyStaged: repository.isPartiallyStaged(this.props.relPath),
hasUndoHistory: repository.hasDiscardHistory(this.props.relPath),
});
Expand All @@ -48,6 +63,20 @@ export default class ChangedFileContainer extends React.Component {
}

renderWithData(data) {
const currentMultiFilePatch = data && data.multiFilePatch;
if (currentMultiFilePatch !== this.lastMultiFilePatch) {
this.sub.dispose();
if (currentMultiFilePatch) {
// Keep this component's renderStatusOverride synchronized with the FilePatch we're rendering
this.sub = new CompositeDisposable(
...currentMultiFilePatch.getFilePatches().map(fp => fp.onDidChangeRenderStatus(() => {
this.setState({renderStatusOverride: fp.getRenderStatus()});
})),
);
}
this.lastMultiFilePatch = currentMultiFilePatch;
}

if (this.props.repository.isLoading() || data === null) {
return <LoadingView />;
}
Expand All @@ -59,4 +88,8 @@ export default class ChangedFileContainer extends React.Component {
/>
);
}

componentWillUnmount() {
this.sub.dispose();
}
}
21 changes: 21 additions & 0 deletions lib/containers/commit-detail-container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';
import {CompositeDisposable} from 'event-kit';

import ObserveModel from '../views/observe-model';
import LoadingView from '../views/loading-view';
Expand All @@ -13,6 +14,13 @@ export default class CommitDetailContainer extends React.Component {
itemType: PropTypes.func.isRequired,
}

constructor(props) {
super(props);

this.lastCommit = null;
this.sub = new CompositeDisposable();
}

fetchData = repository => {
return yubikiri({
commit: repository.getCommit(this.props.sha),
Expand All @@ -31,6 +39,19 @@ export default class CommitDetailContainer extends React.Component {
}

renderResult = data => {
const currentCommit = data && data.commit;
if (currentCommit !== this.lastCommit) {
this.sub.dispose();
if (currentCommit && currentCommit.isPresent()) {
this.sub = new CompositeDisposable(
...currentCommit.getMultiFileDiff().getFilePatches().map(fp => fp.onDidChangeRenderStatus(() => {
this.forceUpdate();
})),
);
}
this.lastCommit = currentCommit;
}

if (this.props.repository.isLoading() || data === null || !data.commit.isPresent()) {
return <LoadingView />;
}
Expand Down
39 changes: 38 additions & 1 deletion lib/containers/commit-preview-container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';
import {CompositeDisposable} from 'event-kit';

import ObserveModel from '../views/observe-model';
import LoadingView from '../views/loading-view';
Expand All @@ -9,11 +10,27 @@ import CommitPreviewController from '../controllers/commit-preview-controller';
export default class CommitPreviewContainer extends React.Component {
static propTypes = {
repository: PropTypes.object.isRequired,
largeDiffThreshold: PropTypes.number,
}

constructor(props) {
super(props);

this.lastMultiFilePatch = null;
this.sub = new CompositeDisposable();

this.state = {renderStatusOverrides: {}};
}

fetchData = repository => {
const builder = {renderStatusOverrides: this.state.renderStatusOverrides};

if (this.props.largeDiffThreshold !== undefined) {
builder.largeDiffThreshold = this.props.largeDiffThreshold;
}

return yubikiri({
multiFilePatch: repository.getStagedChangesPatch(),
multiFilePatch: repository.getStagedChangesPatch({builder}),
});
}

Expand All @@ -26,6 +43,26 @@ export default class CommitPreviewContainer extends React.Component {
}

renderResult = data => {
const currentMultiFilePatch = data && data.multiFilePatch;
if (currentMultiFilePatch !== this.lastMultiFilePatch) {
this.sub.dispose();
if (currentMultiFilePatch) {
this.sub = new CompositeDisposable(
...currentMultiFilePatch.getFilePatches().map(fp => fp.onDidChangeRenderStatus(() => {
this.setState(prevState => {
return {
renderStatusOverrides: {
...prevState.renderStatusOverrides,
[fp.getPath()]: fp.getRenderStatus(),
},
};
});
})),
);
}
this.lastMultiFilePatch = currentMultiFilePatch;
}

if (this.props.repository.isLoading() || data === null) {
return <LoadingView />;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/commit-detail-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?

}

render() {
Expand Down
1 change: 1 addition & 0 deletions lib/controllers/pr-reviews-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?

}

constructor(props) {
Expand Down
Loading