Skip to content

Commit c098435

Browse files
committed
Auto merge of #2848 - Turbo87:api-token, r=locks
ApiTokenRow: Simplify template and wrap with `<form>` element Instead of having ``@token.isNew`` checks everywhere we now only have a single top-level check, which then allows us to use a proper `<form>` element for the token name input field. Eventually this should probably be extracted to a dedicated component. r? `@locks`
2 parents 9143a0f + 5caeb5a commit c098435

File tree

2 files changed

+42
-37
lines changed

2 files changed

+42
-37
lines changed

app/components/api-token-row.hbs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
<div local-class="row {{if @token.isNew "create-token"}}" data-test-api-token={{@token.id}}>
2-
<div local-class="name" data-test-name>
3-
{{#if @token.isNew}}
1+
{{#if @token.isNew}}
2+
<form local-class="row create-token" {{on "submit" (perform this.saveTokenTask)}}>
3+
<div local-class="name">
44
<Input
55
@type="text"
66
placeholder="New token name"
77
@disabled={{@token.isSaving}}
88
@value={{@token.name}}
9-
@enter={{perform this.saveTokenTask}}
109
data-test-focused-input
1110
{{auto-focus}}
1211
/>
13-
{{else}}
12+
</div>
13+
14+
<div local-class="actions">
15+
<button
16+
type="submit"
17+
local-class="save-button"
18+
disabled={{this.disableCreate}}
19+
title={{if this.emptyName "You must specify a name" ""}}
20+
data-test-save-token-button
21+
>
22+
Create
23+
</button>
24+
{{#if @token.isSaving}}
25+
<LoadingSpinner local-class="spinner" data-test-saving-spinner />
26+
{{/if}}
27+
</div>
28+
</form>
29+
{{else}}
30+
<div local-class="row" data-test-api-token={{@token.id}}>
31+
<div local-class="name" data-test-name>
1432
{{@token.name}}
15-
{{/if}}
16-
</div>
33+
</div>
1734

18-
{{#unless @token.isNew}}
19-
<div local-class='dates'>
35+
<div local-class="dates">
2036
<span title={{@token.created_at}} local-class="created-at" data-test-created-at>
2137
Created {{moment-from-now @token.created_at}}
2238
</span>
@@ -28,21 +44,8 @@
2844
{{/if}}
2945
</span>
3046
</div>
31-
{{/unless}}
3247

33-
<div local-class='actions'>
34-
{{#if @token.isNew}}
35-
<button
36-
type="button"
37-
local-class="save-button"
38-
disabled={{this.disableCreate}}
39-
title={{if this.emptyName "You must specify a name" ""}}
40-
data-test-save-token-button
41-
{{on "click" (perform this.saveTokenTask)}}
42-
>
43-
Create
44-
</button>
45-
{{else}}
48+
<div local-class="actions">
4649
<button
4750
type="button"
4851
local-class="revoke-button"
@@ -52,21 +55,21 @@
5255
>
5356
Revoke
5457
</button>
55-
{{/if}}
56-
{{#if @token.isSaving}}
57-
<LoadingSpinner local-class="spinner" data-test-saving-spinner />
58-
{{/if}}
58+
{{#if @token.isSaving}}
59+
<LoadingSpinner local-class="spinner" data-test-saving-spinner />
60+
{{/if}}
61+
</div>
5962
</div>
60-
</div>
6163

62-
{{#if @token.token}}
63-
<div local-class="row new-token" data-test-token>
64-
<div>
65-
Please record this token somewhere, you cannot retrieve
66-
its value again. For use on the command line you can save it to <code>~/.cargo/credentials</code>
67-
with:
64+
{{#if @token.token}}
65+
<div local-class="row new-token" data-test-token>
66+
<div>
67+
Please record this token somewhere, you cannot retrieve
68+
its value again. For use on the command line you can save it to <code>~/.cargo/credentials</code>
69+
with:
6870

69-
<pre>cargo login {{@token.token}}</pre>
71+
<pre>cargo login {{@token.token}}</pre>
72+
</div>
7073
</div>
71-
</div>
74+
{{/if}}
7275
{{/if}}

app/components/api-token-row.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export default class ApiTokenRow extends Component {
1010
@empty('args.token.name') emptyName;
1111
@or('args.token.isSaving', 'emptyName') disableCreate;
1212

13-
@task(function* () {
13+
@task(function* (event) {
14+
event.preventDefault();
15+
1416
try {
1517
yield this.args.token.save();
1618
} catch (err) {

0 commit comments

Comments
 (0)