Skip to content

Commit c02bc06

Browse files
authored
Merge pull request #10380 from Turbo87/delete-reason-input
crate/delete: Add required reason input field
2 parents e863029 + 8719a86 commit c02bc06

File tree

9 files changed

+52
-6
lines changed

9 files changed

+52
-6
lines changed

app/adapters/crate.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ export default class CrateAdapter extends ApplicationAdapter {
2525
return `${baseUrl}/${crateName}`;
2626
}
2727

28+
/** Adds a `reason` query parameter to the URL, if set in the `adapterOptions`. */
29+
urlForDeleteRecord(id, modelName, snapshot) {
30+
let url = super.urlForDeleteRecord(...arguments);
31+
32+
let reason = snapshot.adapterOptions.reason;
33+
if (reason) {
34+
url += `?reason=${encodeURIComponent(reason)}`;
35+
}
36+
37+
return url;
38+
}
39+
2840
groupRecordsForFindMany(store, snapshots) {
2941
let result = [];
3042
for (let i = 0; i < snapshots.length; i += BULK_REQUEST_GROUP_SIZE) {

app/controllers/crate/delete.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ export default class CrateSettingsController extends Controller {
99
@service notifications;
1010
@service router;
1111

12+
@tracked reason = '';
1213
@tracked isConfirmed;
1314

1415
@action toggleConfirmation() {
1516
this.isConfirmed = !this.isConfirmed;
1617
}
1718

1819
deleteTask = task(async () => {
20+
let { reason } = this;
21+
1922
try {
20-
await this.model.destroyRecord();
23+
await this.model.destroyRecord({ adapterOptions: { reason } });
2124
this.notifications.success(`Crate ${this.model.name} has been successfully deleted.`);
2225
this.router.transitionTo('index');
2326
} catch (error) {

app/routes/crate/delete.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class SettingsRoute extends AuthenticatedRoute {
2020

2121
setupController(controller) {
2222
super.setupController(...arguments);
23+
controller.set('reason', '');
2324
controller.set('isConfirmed', false);
2425
}
2526
}

app/styles/crate/delete.module.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
}
7676
}
7777

78+
.reason {
79+
margin-bottom: var(--space-m);
80+
}
81+
82+
.reason-input {
83+
composes: base-input from '../../styles/settings/tokens/new.module.css';
84+
width: 100%;
85+
}
86+
7887
.confirmation {
7988
composes: warning-block;
8089
display: block;

app/templates/crate/delete.hbs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div local-class="wrapper">
2-
<div local-class="content">
2+
<form local-class="content" {{on "submit" (prevent-default (perform this.deleteTask))}}>
33
<h1 local-class="title" data-test-title>Delete the {{@model.name}} crate?</h1>
44

55
<p>Are you sure you want to delete the crate "{{@model.name}}"?</p>
@@ -36,6 +36,20 @@
3636
</ol>
3737
</div>
3838

39+
<div local-class="reason">
40+
<h3>Reason:</h3>
41+
<label>
42+
<p>Please tell us why you are deleting this crate:</p>
43+
<Input
44+
@type="text"
45+
@value={{this.reason}}
46+
required={{true}}
47+
local-class="reason-input"
48+
data-test-reason
49+
/>
50+
</label>
51+
</div>
52+
3953
<label local-class="confirmation">
4054
<Input
4155
@type="checkbox"
@@ -53,7 +67,6 @@
5367
disabled={{or (not this.isConfirmed) this.deleteTask.isRunning}}
5468
local-class="delete-button"
5569
data-test-delete-button
56-
{{on "click" (perform this.deleteTask)}}
5770
>
5871
Delete this crate
5972
</button>
@@ -63,5 +76,5 @@
6376
</div>
6477
{{/if}}
6578
</div>
66-
</div>
79+
</form>
6780
</div>

e2e/acceptance/crate-deletion.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test.describe('Acceptance | crate deletion', { tag: '@acceptance' }, () => {
2424
await expect(page.locator('[data-test-title]')).toHaveText('Delete the foo crate?');
2525
await expect(page.locator('[data-test-delete-button]')).toBeDisabled();
2626

27+
await page.fill('[data-test-reason]', "I don't need this crate anymore");
2728
await page.click('[data-test-confirmation-checkbox]');
2829
await expect(page.locator('[data-test-delete-button]')).toBeEnabled();
2930

e2e/routes/crate/delete.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ test.describe('Route: crate.delete', { tag: '@routes' }, () => {
5050
await expect(page.locator('[data-test-title]')).toHaveText('Delete the foo crate?');
5151
await percy.snapshot();
5252

53+
await page.fill('[data-test-reason]', "I don't need this crate anymore");
5354
await expect(page.locator('[data-test-delete-button]')).toBeDisabled();
5455
await page.click('[data-test-confirmation-checkbox]');
5556
await expect(page.locator('[data-test-delete-button]')).toBeEnabled();
@@ -72,6 +73,7 @@ test.describe('Route: crate.delete', { tag: '@routes' }, () => {
7273
});
7374

7475
await page.goto('/crates/foo/delete');
76+
await page.fill('[data-test-reason]', "I don't need this crate anymore");
7577
await page.click('[data-test-confirmation-checkbox]');
7678
await page.click('[data-test-delete-button]');
7779
await expect(page.locator('[data-test-spinner]')).toBeVisible();
@@ -90,6 +92,7 @@ test.describe('Route: crate.delete', { tag: '@routes' }, () => {
9092
});
9193

9294
await page.goto('/crates/foo/delete');
95+
await page.fill('[data-test-reason]', "I don't need this crate anymore");
9396
await page.click('[data-test-confirmation-checkbox]');
9497
await page.click('[data-test-delete-button]');
9598
await expect(page).toHaveURL('/crates/foo/delete');

tests/acceptance/crate-deletion-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, currentURL } from '@ember/test-helpers';
1+
import { click, currentURL, fillIn } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

44
import { setupApplicationTest } from 'crates-io/tests/helpers';
@@ -29,6 +29,7 @@ module('Acceptance | crate deletion', function (hooks) {
2929
assert.dom('[data-test-title]').hasText('Delete the foo crate?');
3030
assert.dom('[data-test-delete-button]').isDisabled();
3131

32+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
3233
await click('[data-test-confirmation-checkbox]');
3334
assert.dom('[data-test-delete-button]').isEnabled();
3435

tests/routes/crate/delete-test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, currentURL, waitFor } from '@ember/test-helpers';
1+
import { click, currentURL, fillIn, waitFor } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

44
import { defer } from 'rsvp';
@@ -58,6 +58,7 @@ module('Route: crate.delete', function (hooks) {
5858
assert.dom('[data-test-title]').hasText('Delete the foo crate?');
5959
await percySnapshot(assert);
6060

61+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
6162
assert.dom('[data-test-delete-button]').isDisabled();
6263
await click('[data-test-confirmation-checkbox]');
6364
assert.dom('[data-test-delete-button]').isEnabled();
@@ -79,6 +80,7 @@ module('Route: crate.delete', function (hooks) {
7980
this.server.delete('/api/v1/crates/foo', deferred.promise);
8081

8182
await visit('/crates/foo/delete');
83+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
8284
await click('[data-test-confirmation-checkbox]');
8385
let clickPromise = click('[data-test-delete-button]');
8486
await waitFor('[data-test-spinner]');
@@ -98,6 +100,7 @@ module('Route: crate.delete', function (hooks) {
98100
this.server.delete('/api/v1/crates/foo', payload, 422);
99101

100102
await visit('/crates/foo/delete');
103+
await fillIn('[data-test-reason]', "I don't need this crate anymore");
101104
await click('[data-test-confirmation-checkbox]');
102105
await click('[data-test-delete-button]');
103106
assert.strictEqual(currentURL(), '/crates/foo/delete');

0 commit comments

Comments
 (0)