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

Commit 7efaa8c

Browse files
committed
Restructure identity view to require explicit button press to accept
1 parent a747a1b commit 7efaa8c

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

lib/views/git-identity-view.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ export default class GitIdentityView extends React.Component {
77
// Model
88
usernameBuffer: PropTypes.object.isRequired,
99
emailBuffer: PropTypes.object.isRequired,
10+
canWriteLocal: PropTypes.bool.isRequired,
1011

1112
// Action methods
13+
setLocal: PropTypes.func.isRequired,
14+
setGlobal: PropTypes.func.isRequired,
1215
close: PropTypes.func.isRequired,
1316
};
1417

@@ -19,19 +22,29 @@ export default class GitIdentityView extends React.Component {
1922
Git Identity
2023
</h1>
2124
<p className="github-GitIdentity-explanation">
22-
Please set the username and email address that you wish to use to
23-
author git commits.
25+
Please set the username and email address that you wish to use to author git commits. This will write to the
26+
<code>user.name</code> and <code>user.email</code> values in your git configuration at the chosen scope.
2427
</p>
2528
<div className="github-GitIdentity-text">
2629
<AtomTextEditor mini placeholderText="name" buffer={this.props.usernameBuffer} />
2730
<AtomTextEditor mini placeholderText="email address" buffer={this.props.emailBuffer} />
2831
</div>
2932
<div className="github-GitIdentity-buttons">
33+
<button className="btn" onClick={this.props.close}>
34+
Cancel
35+
</button>
36+
<button
37+
className="btn btn-primary"
38+
title="Configure git for this repository"
39+
onClick={this.props.setLocal}
40+
disabled={!this.props.canWriteLocal}>
41+
Use for this repository
42+
</button>
3043
<button
3144
className="btn btn-primary"
32-
onClick={this.props.close}
33-
disabled={this.props.usernameBuffer.isEmpty() || this.props.emailBuffer.isEmpty()}>
34-
Continue
45+
title="Configure git globally for your operating system user account"
46+
onClick={this.props.setGlobal}>
47+
Use for all repositories
3548
</button>
3649
</div>
3750
</div>

styles/git-identity.less

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
}
2727

2828
&-buttons {
29-
//
29+
.btn {
30+
margin: @component-padding/2;
31+
}
3032
}
3133
}

test/views/git-identity-view.test.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ describe('GitIdentityView', function() {
1010
<GitIdentityView
1111
usernameBuffer={new TextBuffer()}
1212
emailBuffer={new TextBuffer()}
13+
canWriteLocal={true}
14+
setLocal={() => {}}
15+
setGlobal={() => {}}
1316
close={() => {}}
1417
{...override}
1518
/>
@@ -30,27 +33,37 @@ describe('GitIdentityView', function() {
3033
assert.strictEqual(getEditor('email address').prop('buffer'), emailBuffer);
3134
});
3235

33-
it('disables the "Continue" button if the name is blank', function() {
34-
const usernameBuffer = new TextBuffer();
35-
const wrapper = mount(buildApp({usernameBuffer}));
36+
it('disables the local repo button when canWriteLocal is false', function() {
37+
const wrapper = mount(buildApp({canWriteLocal: false}));
3638

37-
assert.isTrue(wrapper.find('.btn').prop('disabled'));
39+
assert.isTrue(wrapper.find('.btn').filterWhere(each => /this repository/.test(each.text())).prop('disabled'));
3840
});
3941

40-
it('disables the "Continue" button if the email is blank', function() {
41-
const emailBuffer = new TextBuffer();
42-
const wrapper = mount(buildApp({emailBuffer}));
42+
it('triggers a callback when "Use for this repository" is clicked', function() {
43+
const setLocal = sinon.spy();
44+
const wrapper = mount(buildApp({setLocal}));
45+
46+
wrapper.find('.btn').filterWhere(each => /this repository/.test(each.text())).simulate('click');
47+
48+
assert.isTrue(setLocal.called);
49+
});
50+
51+
it('triggers a callback when "Use for all repositories" is clicked', function() {
52+
const setGlobal = sinon.spy();
53+
const wrapper = mount(buildApp({setGlobal}));
54+
55+
wrapper.find('.btn').filterWhere(each => /all repositories/.test(each.text())).simulate('click');
4356

44-
assert.isTrue(wrapper.find('.btn').prop('disabled'));
57+
assert.isTrue(setGlobal.called);
4558
});
4659

47-
it('triggers a callback when "Continue" is clicked', function() {
60+
it('triggers a callback when "Cancel" is clicked', function() {
4861
const usernameBuffer = new TextBuffer({text: 'Me'});
4962
const emailBuffer = new TextBuffer({text: '[email protected]'});
5063
const close = sinon.spy();
5164
const wrapper = mount(buildApp({usernameBuffer, emailBuffer, close}));
5265

53-
wrapper.find('.btn').simulate('click');
66+
wrapper.find('.btn').filterWhere(each => /Cancel/.test(each.text())).simulate('click');
5467

5568
assert.isTrue(close.called);
5669
});

0 commit comments

Comments
 (0)