Skip to content

Commit 5cc896d

Browse files
committed
app: Simplify isOwner with crate.hasOwnerUser(userId) fn
This fixes the following deprecations: - The findBy method on ember-data's PromiseManyArray is deprecated. - The `findBy` method on the class ManyArray is deprecated.
1 parent b09f410 commit 5cc896d

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

app/components/crate-header.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,21 @@ export default class CrateHeader extends Component {
88
@service session;
99

1010
@alias('loadKeywordsTask.last.value') keywords;
11-
@alias('loadOwnerUserTask.last.value') ownerUser;
1211

1312
constructor() {
1413
super(...arguments);
1514

1615
this.loadKeywordsTask.perform().catch(() => {
1716
// ignore all errors and just don't display keywords if the request fails
1817
});
19-
this.loadOwnerUserTask.perform().catch(() => {
20-
// ignore all errors and just don't display settings if the request fails
21-
});
2218
}
2319

2420
get isOwner() {
25-
let ownerUser = this.ownerUser ?? [];
26-
let currentUserId = this.session.currentUser?.id;
27-
return ownerUser.some(({ id }) => id === currentUserId);
21+
let userId = this.session.currentUser?.id;
22+
return this.args.crate?.hasOwnerUser(userId) ?? false;
2823
}
2924

3025
loadKeywordsTask = task(async () => {
3126
return (await this.args.crate?.keywords) ?? [];
3227
});
33-
34-
loadOwnerUserTask = task(async () => {
35-
return (await this.args.crate?.owner_user) ?? [];
36-
});
3728
}

app/components/version-list/row.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export default class VersionRow extends Component {
4848
}
4949

5050
get isOwner() {
51-
return this.args.version.crate?.owner_user?.findBy('id', this.session.currentUser?.id);
51+
let userId = this.session.currentUser?.id;
52+
return this.args.version.crate.hasOwnerUser(userId);
5253
}
5354

5455
@action setFocused(value) {

app/controllers/crate/version.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export default class CrateVersionController extends Controller {
3030
@alias('model.version') currentVersion;
3131

3232
get isOwner() {
33-
return this.crate.owner_user.findBy('id', this.session.currentUser?.id);
33+
let userId = this.session.currentUser?.id;
34+
return this.crate.hasOwnerUser(userId);
3435
}
3536

3637
@alias('loadReadmeTask.last.value') readme;

app/routes/crate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NotFoundError } from '@ember-data/adapter/error';
22
import Route from '@ember/routing/route';
33
import { inject as service } from '@ember/service';
4+
import { waitForPromise } from '@ember/test-waiters';
45

56
export default class CrateRoute extends Route {
67
@service headData;
@@ -26,6 +27,9 @@ export default class CrateRoute extends Route {
2627
setupController(controller, model) {
2728
super.setupController(...arguments);
2829
this.headData.crate = model;
30+
waitForPromise(model.loadOwnerUserTask.perform()).catch(() => {
31+
// ignore all errors if the request fails
32+
});
2933
}
3034

3135
resetController() {

tests/components/version-list-row-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module('Component | VersionList::Row', function (hooks) {
1919
let store = this.owner.lookup('service:store');
2020
let crateRecord = await store.findRecord('crate', crate.name);
2121
let versions = (await crateRecord.versions).slice();
22+
await crateRecord.loadOwnerUserTask.perform();
2223
this.firstVersion = versions[0];
2324
this.secondVersion = versions[1];
2425

@@ -39,6 +40,7 @@ module('Component | VersionList::Row', function (hooks) {
3940
let store = this.owner.lookup('service:store');
4041
let crateRecord = await store.findRecord('crate', crate.name);
4142
this.version = (await crateRecord.versions).slice()[0];
43+
await crateRecord.loadOwnerUserTask.perform();
4244

4345
await render(hbs`<VersionList::Row @version={{this.version}} />`);
4446
assert.dom('[data-test-release-track]').hasText('?');
@@ -72,6 +74,7 @@ module('Component | VersionList::Row', function (hooks) {
7274
let store = this.owner.lookup('service:store');
7375
let crateRecord = await store.findRecord('crate', crate.name);
7476
let versions = (await crateRecord.versions).slice();
77+
await crateRecord.loadOwnerUserTask.perform();
7578
this.firstVersion = versions[0];
7679
this.secondVersion = versions[1];
7780
this.thirdVersion = versions[2];

0 commit comments

Comments
 (0)