Skip to content

Commit 86b7bfb

Browse files
authored
crate/settings: Hide "Add Owner" form behind "Add Owner" button (#11301)
This form does not need a dedicated header and does not need to be visible all the time. This commit hides it until the user explicitly clicks the "Add Owner" button. This frees up space on the page to add the list of "Trusted Publishing" configurations.
1 parent 89085e8 commit 86b7bfb

File tree

6 files changed

+40
-12
lines changed

6 files changed

+40
-12
lines changed

app/controllers/crate/settings.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Controller from '@ember/controller';
2+
import { action } from '@ember/object';
23
import { service } from '@ember/service';
4+
import { tracked } from '@glimmer/tracking';
35

46
import { task } from 'ember-concurrency';
57

@@ -8,6 +10,12 @@ export default class CrateSettingsController extends Controller {
810

911
crate = null;
1012
username = '';
13+
@tracked addOwnerVisible = false;
14+
15+
@action showAddOwnerForm() {
16+
this.addOwnerVisible = true;
17+
this.username = '';
18+
}
1119

1220
addOwnerTask = task(async () => {
1321
const username = this.username;
@@ -20,6 +28,7 @@ export default class CrateSettingsController extends Controller {
2028
} else {
2129
this.notifications.success(`An invite has been sent to ${username}`);
2230
}
31+
this.addOwnerVisible = false;
2332
} catch (error) {
2433
let detail = error.errors?.[0]?.detail;
2534
if (detail && !detail.startsWith('{')) {

app/styles/crate/settings.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
.owners-header {
2+
display: flex;
3+
justify-content: space-between;
4+
align-items: center;
5+
}
6+
17
.email-form {
28
display: flex;
39
justify-content: space-between;
@@ -8,6 +14,7 @@
814
background-color: light-dark(white, #141413);
915
border-radius: var(--space-3xs);
1016
box-shadow: 0 1px 3px light-dark(hsla(51, 90%, 42%, .35), #232321);
17+
margin-bottom: var(--space-s);
1118
}
1219

1320
.email-input-label {

app/templates/crate/settings.hbs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22

33
<CrateHeader @crate={{this.crate}} />
44

5-
<h2>Add Owner</h2>
6-
7-
<form local-class="email-form" {{on "submit" (prevent-default (perform this.addOwnerTask))}}>
8-
<label local-class="email-input-label" for='new-owner-username'>
9-
Username
10-
</label>
11-
<Input @type="text" id="new-owner-username" @value={{this.username}} placeholder="Username" local-class="email-input" name="username" />
12-
<button type="submit" disabled={{not this.username}} class="button button--small" data-test-save-button>Save</button>
13-
</form>
5+
<div local-class="owners-header">
6+
<h2>Owners</h2>
7+
{{#unless this.addOwnerVisible}}
8+
<button type="button" class="button button--small" data-test-add-owner-button {{on "click" this.showAddOwnerForm}}>Add Owner</button>
9+
{{/unless}}
10+
</div>
1411

15-
<h2>Owners</h2>
12+
{{#if this.addOwnerVisible}}
13+
<form local-class="email-form" {{on "submit" (prevent-default (perform this.addOwnerTask))}}>
14+
<label local-class="email-input-label" for='new-owner-username'>
15+
Username
16+
</label>
17+
<Input @type="text" id="new-owner-username" @value={{this.username}} placeholder="Username" local-class="email-input" name="username" />
18+
<button type="submit" disabled={{not this.username}} class="button button--small" data-test-save-button>Save</button>
19+
</form>
20+
{{/if}}
1621

1722
<div local-class='list' data-test-owners>
1823
{{#each this.crate.owner_team as |team|}}

e2e/acceptance/settings/add-owner.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ test.describe('Acceptance | Settings | Add Owner', { tag: '@acceptance' }, () =>
1919

2020
test('attempting to add owner without username', async ({ page }) => {
2121
await page.goto('/crates/nanomsg/settings');
22+
await page.click('[data-test-add-owner-button]');
2223
await page.fill('input[name="username"]', '');
2324
await expect(page.locator('[data-test-save-button]')).toBeDisabled();
2425
});
2526

2627
test('attempting to add non-existent owner', async ({ page }) => {
2728
await page.goto('/crates/nanomsg/settings');
29+
await page.click('[data-test-add-owner-button]');
2830
await page.fill('input[name="username"]', 'spookyghostboo');
2931
await page.click('[data-test-save-button]');
3032

@@ -39,6 +41,7 @@ test.describe('Acceptance | Settings | Add Owner', { tag: '@acceptance' }, () =>
3941
msw.db.user.create({ name: 'iain8' });
4042

4143
await page.goto('/crates/nanomsg/settings');
44+
await page.click('[data-test-add-owner-button]');
4245
await page.fill('input[name="username"]', 'iain8');
4346
await page.click('[data-test-save-button]');
4447

@@ -54,6 +57,7 @@ test.describe('Acceptance | Settings | Add Owner', { tag: '@acceptance' }, () =>
5457
msw.db.team.create({ org: 'rust-lang', name: 'crates-io' });
5558

5659
await page.goto('/crates/nanomsg/settings');
60+
await page.click('[data-test-add-owner-button]');
5761
await page.fill('input[name="username"]', 'github:rust-lang:crates-io');
5862
await page.click('[data-test-save-button]');
5963

tests/acceptance/settings/add-owner-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module('Acceptance | Settings | Add Owner', function (hooks) {
3030
prepare(this);
3131

3232
await visit('/crates/nanomsg/settings');
33+
await click('[data-test-add-owner-button]');
3334
await fillIn('input[name="username"]', '');
3435
assert.dom('[data-test-save-button]').isDisabled();
3536
});
@@ -38,6 +39,7 @@ module('Acceptance | Settings | Add Owner', function (hooks) {
3839
prepare(this);
3940

4041
await visit('/crates/nanomsg/settings');
42+
await click('[data-test-add-owner-button]');
4143
await fillIn('input[name="username"]', 'spookyghostboo');
4244
await click('[data-test-save-button]');
4345

@@ -54,6 +56,7 @@ module('Acceptance | Settings | Add Owner', function (hooks) {
5456
this.db.user.create({ name: 'iain8' });
5557

5658
await visit('/crates/nanomsg/settings');
59+
await click('[data-test-add-owner-button]');
5760
await fillIn('input[name="username"]', 'iain8');
5861
await click('[data-test-save-button]');
5962

@@ -69,6 +72,7 @@ module('Acceptance | Settings | Add Owner', function (hooks) {
6972
this.db.team.create({ org: 'rust-lang', name: 'crates-io' });
7073

7174
await visit('/crates/nanomsg/settings');
75+
await click('[data-test-add-owner-button]');
7276
await fillIn('input[name="username"]', 'github:rust-lang:crates-io');
7377
await click('[data-test-save-button]');
7478

tests/routes/crate/settings-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ module('Route | crate.settings', hooks => {
4646

4747
await visit(`/crates/${crate.name}/settings`);
4848
assert.strictEqual(currentURL(), `/crates/${crate.name}/settings`);
49-
// This is the Add Owner button.
50-
assert.dom('[data-test-save-button]').exists();
49+
assert.dom('[data-test-add-owner-button]').exists();
5150
assert.dom('[data-test-owners]').exists();
5251
assert.dom(`[data-test-owner-user="${user.login}"]`).exists();
5352
assert.dom('[data-test-remove-owner-button]').exists();

0 commit comments

Comments
 (0)