Skip to content

Commit 87e136a

Browse files
committed
Settings::ApiTokens: Filter tokens from the list that haven't been saved to the server
1 parent c8a189a commit 87e136a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

app/components/settings/api-tokens.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<ul role="list" local-class="token-list">
5757
{{#each this.sortedTokens as |token|}}
5858
<li>
59-
<div local-class="row" data-test-api-token={{token.id}}>
59+
<div local-class="row" data-test-api-token={{or token.id true}}>
6060
<div local-class="name" data-test-name>
6161
{{token.name}}
6262
</div>

app/components/settings/api-tokens.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import Component from '@glimmer/component';
44
import { tracked } from '@glimmer/tracking';
55

66
import { task } from 'ember-concurrency';
7-
import { sortBy } from 'macro-decorators';
7+
import { filterBy, sortBy } from 'macro-decorators';
88

99
export default class ApiTokens extends Component {
1010
@service store;
1111
@service notifications;
1212

1313
@tracked newToken;
1414

15-
@sortBy('args.tokens', 'created_at', false) sortedTokens;
15+
@filterBy('args.tokens', 'isNew', false) filteredTokens;
16+
@sortBy('filteredTokens', 'created_at', false) sortedTokens;
1617

1718
@action startNewToken() {
1819
this.newToken = this.store.createRecord('api-token');

tests/acceptance/api-token-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,19 @@ module('Acceptance | api-tokens', function (hooks) {
128128
assert.dom('[data-test-api-token="3"] [data-test-error]').doesNotExist();
129129
assert.dom('[data-test-token]').includesText(`cargo login ${token.token}`);
130130
});
131+
132+
test('navigating away while creating a token does not keep it in the list', async function (assert) {
133+
prepare(this);
134+
135+
await visit('/settings/tokens');
136+
assert.dom('[data-test-api-token]').exists({ count: 2 });
137+
138+
await click('[data-test-new-token-button]');
139+
await fillIn('[data-test-focused-input]', 'the new token');
140+
141+
await visit('/settings/profile');
142+
143+
await visit('/settings/tokens');
144+
assert.dom('[data-test-api-token]').exists({ count: 2 });
145+
});
131146
});

0 commit comments

Comments
 (0)