Skip to content

Commit 7474923

Browse files
authored
Merge pull request #6574 from Turbo87/token-scopes-cleanup
Clean up API token creation code
2 parents c9ce04c + 761c11f commit 7474923

File tree

3 files changed

+7
-61
lines changed

3 files changed

+7
-61
lines changed

app/components/settings/api-tokens.hbs

+6-40
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<div local-class="me-subheading">
22
<h2>API Tokens</h2>
33
<div local-class="right">
4-
<button
5-
type="button"
4+
<LinkTo
5+
@route="settings.tokens.new"
66
local-class="new-token-button"
7-
disabled={{this.newToken}}
87
data-test-new-token-button
9-
{{on "click" this.startNewToken}}
108
>
119
New Token
12-
</button>
10+
</LinkTo>
1311
</div>
1412
</div>
1513

@@ -33,36 +31,6 @@
3331
environment variable, but make sure that the token stays secret!
3432
</p>
3533

36-
{{#if this.newToken}}
37-
<form local-class="new-token-form" {{on "submit" (prevent-default (perform this.saveTokenTask))}}>
38-
<Input
39-
@type="text"
40-
placeholder="New token name"
41-
aria-label="New token name"
42-
disabled={{this.newToken.isSaving}}
43-
@value={{this.newToken.name}}
44-
local-class="input"
45-
data-test-focused-input
46-
{{auto-focus}}
47-
/>
48-
49-
<div local-class="actions">
50-
<button
51-
type="submit"
52-
local-class="save-button"
53-
disabled={{or this.newToken.isSaving (not this.newToken.name)}}
54-
title={{unless this.newToken.name "You must specify a name"}}
55-
data-test-save-token-button
56-
>
57-
Create
58-
</button>
59-
{{#if this.newToken.isSaving}}
60-
<LoadingSpinner local-class="spinner" data-test-saving-spinner />
61-
{{/if}}
62-
</div>
63-
</form>
64-
{{/if}}
65-
6634
{{#if this.sortedTokens}}
6735
<ul role="list" local-class="token-list">
6836
{{#each this.sortedTokens as |token|}}
@@ -165,14 +133,12 @@
165133
You have not generated any API tokens yet.
166134
</div>
167135

168-
<button
169-
type="button"
136+
<LinkTo
137+
@route="settings.tokens.new"
170138
local-class="empty-state-button"
171-
disabled={{this.newToken}}
172139
data-test-empty-state-button
173-
{{on "click" this.startNewToken}}
174140
>
175141
New Token
176-
</button>
142+
</LinkTo>
177143
</div>
178144
{{/if}}

app/components/settings/api-tokens.js

-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { action } from '@ember/object';
22
import { inject as service } from '@ember/service';
33
import Component from '@glimmer/component';
4-
import { tracked } from '@glimmer/tracking';
54

65
import { task } from 'ember-concurrency';
76

@@ -12,8 +11,6 @@ export default class ApiTokens extends Component {
1211
@service notifications;
1312
@service router;
1413

15-
@tracked newToken;
16-
1714
scopeDescription = scopeDescription;
1815
patternDescription = patternDescription;
1916

@@ -30,23 +27,6 @@ export default class ApiTokens extends Component {
3027
this.router.transitionTo('settings.tokens.new');
3128
}
3229

33-
saveTokenTask = task(async () => {
34-
let token = this.newToken;
35-
36-
try {
37-
await token.save();
38-
this.args.tokens.unshift(token);
39-
this.newToken = undefined;
40-
} catch (error) {
41-
let msg =
42-
error.errors && error.errors[0] && error.errors[0].detail
43-
? `An error occurred while saving this token, ${error.errors[0].detail}`
44-
: 'An unknown error occurred while saving this token';
45-
46-
this.notifications.error(msg);
47-
}
48-
});
49-
5030
revokeTokenTask = task(async token => {
5131
try {
5232
await token.destroyRecord();

tests/routes/settings/tokens/new-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module('/settings/tokens/new', function (hooks) {
3636
await click('[data-test-settings-menu] [data-test-tokens] a');
3737
assert.strictEqual(currentURL(), '/settings/tokens');
3838

39-
await click('[data-test-new-token-button]', { altKey: true });
39+
await click('[data-test-new-token-button]');
4040
assert.strictEqual(currentURL(), '/settings/tokens/new');
4141
});
4242

0 commit comments

Comments
 (0)