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

Commit 32b0ada

Browse files
kuychacoTilde Ann Thurium
andcommitted
Add eventSource metadata to undo-last-discard event reporting
Co-Authored-By: Tilde Ann Thurium <annthurium@github.com>
1 parent 7f03c66 commit 32b0ada

File tree

5 files changed

+50
-15
lines changed

5 files changed

+50
-15
lines changed

lib/controllers/file-patch-controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,11 @@ export default class FilePatchController extends React.Component {
539539
return this.props.discardLines(this.state.filePatch, lines, this.repositoryObserver.getActiveModel());
540540
}
541541

542-
undoLastDiscard() {
542+
undoLastDiscard({eventSource} = {}) {
543543
addEvent('undo-last-discard', {
544544
package: 'github',
545545
component: 'FilePatchController',
546+
eventSource,
546547
});
547548
return this.props.undoLastDiscard(this.props.filePath, this.repositoryObserver.getActiveModel());
548549
}

lib/views/file-patch-view.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export default class FilePatchView extends React.Component {
265265
<Command command="github:discard-selected-lines" callback={this.discardSelection} />
266266
<Command
267267
command="core:undo"
268-
callback={() => this.props.hasUndoHistory && this.props.undoLastDiscard()}
268+
callback={this.undoLastDiscardFromCoreUndo}
269269
/>
270270
{this.props.executableModeChange &&
271271
<Command
@@ -282,14 +282,30 @@ export default class FilePatchView extends React.Component {
282282
<Commands registry={this.props.commandRegistry} target="atom-workspace">
283283
<Command
284284
command="github:undo-last-discard-in-diff-view"
285-
callback={() => this.props.hasUndoHistory && this.props.undoLastDiscard()}
285+
callback={this.undoLastDiscardFromCommand}
286286
/>
287287
<Command command="github:focus-diff-view" callback={this.focus} />
288288
</Commands>
289289
</div>
290290
);
291291
}
292292

293+
undoLastDiscardFromCommand = () => {
294+
if (this.props.hasUndoHistory) {
295+
this.props.undoLastDiscard({eventSource: {command: 'github:undo-last-discard-in-diff-view'}});
296+
}
297+
}
298+
299+
undoLastDiscardFromCoreUndo = () => {
300+
if (this.props.hasUndoHistory) {
301+
this.props.undoLastDiscard({eventSource: {command: 'core:undo'}});
302+
}
303+
}
304+
305+
undoLastDiscardFromButton = () => {
306+
this.props.undoLastDiscard({eventSource: 'button'});
307+
}
308+
293309
renderButtonGroup() {
294310
const unstaged = this.props.stagingStatus === 'unstaged';
295311

@@ -298,7 +314,7 @@ export default class FilePatchView extends React.Component {
298314
{this.props.hasUndoHistory && unstaged ? (
299315
<button
300316
className="btn icon icon-history"
301-
onClick={this.props.undoLastDiscard}>
317+
onClick={this.undoLastDiscardFromButton}>
302318
Undo Discard
303319
</button>
304320
) : null}

lib/views/staging-view.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export default class StagingView extends React.Component {
8585
'stageAll', 'unstageAll', 'stageAllMergeConflicts', 'discardAll', 'confirmSelectedItems', 'selectAll',
8686
'selectFirst', 'selectLast', 'diveIntoSelection', 'showDiffView', 'showBulkResolveMenu', 'showActionsMenu',
8787
'resolveCurrentAsOurs', 'resolveCurrentAsTheirs', 'quietlySelectItem', 'didChangeSelectedItems',
88-
'undoLastDiscard',
8988
);
9089

9190
this.subs = new CompositeDisposable(
@@ -274,18 +273,36 @@ export default class StagingView extends React.Component {
274273
<Command command="github:resolve-file-as-ours" callback={this.resolveCurrentAsOurs} />
275274
<Command command="github:resolve-file-as-theirs" callback={this.resolveCurrentAsTheirs} />
276275
<Command command="github:discard-changes-in-selected-files" callback={this.discardChanges} />
277-
<Command command="core:undo" callback={this.undoLastDiscard} />
276+
<Command command="core:undo" callback={this.undoLastDiscardFromCoreUndo} />
278277
</Commands>
279278
<Commands registry={this.props.commandRegistry} target="atom-workspace">
280279
<Command command="github:stage-all-changes" callback={this.stageAll} />
281280
<Command command="github:unstage-all-changes" callback={this.unstageAll} />
282281
<Command command="github:discard-all-changes" callback={this.discardAll} />
283-
<Command command="github:undo-last-discard-in-git-tab" callback={this.undoLastDiscard} />
282+
<Command command="github:undo-last-discard-in-git-tab"
283+
callback={this.undoLastDiscardFromGitHubCommand}
284+
/>
284285
</Commands>
285286
</Fragment>
286287
);
287288
}
288289

290+
undoLastDiscardFromCoreUndo = () => {
291+
this.undoLastDiscard({eventSource: {command: 'core:undo'}});
292+
}
293+
294+
undoLastDiscardFromGitHubCommand = () => {
295+
this.undoLastDiscard({eventSource: {command: 'github:undo-last-discard-in-git-tab'}});
296+
}
297+
298+
undoLastDiscardFromButton = () => {
299+
this.undoLastDiscard({eventSource: 'button'});
300+
}
301+
302+
undoLastDiscardFromHeaderMenu = () => {
303+
this.undoLastDiscard({eventSource: 'header-menu'});
304+
}
305+
289306
renderActionsMenu() {
290307
if (this.props.unstagedChanges.length || this.props.hasUndoHistory) {
291308
return (
@@ -302,7 +319,7 @@ export default class StagingView extends React.Component {
302319
renderUndoButton() {
303320
return (
304321
<button className="github-StagingView-headerButton github-StagingView-headerButton--fullWidth icon icon-history"
305-
onClick={this.undoLastDiscard}>Undo Discard</button>
322+
onClick={this.undoLastDiscardFromButton}>Undo Discard</button>
306323
);
307324
}
308325

@@ -628,7 +645,7 @@ export default class StagingView extends React.Component {
628645

629646
menu.append(new MenuItem({
630647
label: 'Undo Last Discard',
631-
click: () => this.undoLastDiscard(),
648+
click: this.undoLastDiscardFromHeaderMenu,
632649
enabled: this.props.hasUndoHistory,
633650
}));
634651

@@ -841,14 +858,15 @@ export default class StagingView extends React.Component {
841858
}
842859
}
843860

844-
undoLastDiscard() {
861+
undoLastDiscard({eventSource} = {}) {
845862
if (!this.props.hasUndoHistory) {
846863
return;
847864
}
848865

849866
addEvent('undo-last-discard', {
850867
package: 'github',
851868
component: 'StagingView',
869+
eventSource,
852870
});
853871

854872
this.props.undoLastDiscard();

test/controllers/file-patch-controller.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ describe('FilePatchController', function() {
321321
assert.isTrue(reporterProxy.addEvent.calledWith('undo-last-discard', {
322322
package: 'github',
323323
component: 'FilePatchController',
324+
eventSource: undefined,
324325
}));
325326
});
326327
});

test/views/staging-view.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,15 +822,14 @@ describe('StagingView', function() {
822822

823823
describe('undoLastDiscard()', function() {
824824
it('records an event', function() {
825-
const wrapper = mount(app);
825+
const wrapper = mount(React.cloneElement(app, {hasUndoHistory: true}));
826826
sinon.stub(reporterProxy, 'addEvent');
827827
sinon.stub(wrapper.instance(), 'getSelectedItemFilePaths').returns(['a.txt', 'b.txt']);
828-
wrapper.instance().discardChanges();
829-
assert.isTrue(reporterProxy.addEvent.calledWith('discard-unstaged-changes', {
828+
wrapper.instance().undoLastDiscard();
829+
assert.isTrue(reporterProxy.addEvent.calledWith('undo-last-discard', {
830830
package: 'github',
831831
component: 'StagingView',
832-
fileCount: 2,
833-
type: 'selected',
832+
eventSource: undefined,
834833
}));
835834
});
836835
});

0 commit comments

Comments
 (0)