Skip to content

Commit 4d4b1ad

Browse files
committed
refactor: deprecate-array-prototype-extensions - sortBy()
1 parent bcc3386 commit 4d4b1ad

File tree

15 files changed

+50
-44
lines changed

15 files changed

+50
-44
lines changed

admin/app/components/badges/capped-tubes-criterion.gjs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import Component from '@glimmer/component';
2+
import sortBy from 'lodash/sortBy';
23

34
import Area from '../common/tubes-details/area';
45

56
export default class CappedTubesCriterion extends Component {
67
get areasForView() {
7-
return this.args.targetProfile
8-
.hasMany('areas')
9-
.value()
10-
.sortBy('code')
8+
const areas = sortBy([...this.args.targetProfile.hasMany('areas').value()], 'code');
9+
return areas
1110
.map((area) => ({
1211
area,
1312
competences: this._buildCompetencesViewModel(area.hasMany('competences').value()),
@@ -21,8 +20,7 @@ export default class CappedTubesCriterion extends Component {
2120
}
2221

2322
_buildCompetencesViewModel(competences) {
24-
return competences
25-
.sortBy('index')
23+
return sortBy([...competences], 'index')
2624
.map((competence) => ({
2725
competence,
2826
thematics: this._buildThematicsViewModel(competence.hasMany('thematics').value()),
@@ -35,8 +33,7 @@ export default class CappedTubesCriterion extends Component {
3533
}
3634

3735
_buildThematicsViewModel(thematics) {
38-
return thematics
39-
.sortBy('index')
36+
return sortBy([...thematics], 'index')
4037
.map((thematic) => ({
4138
thematic,
4239
tubes: this._buildTubesViewModel(thematic.hasMany('tubes').value()),
@@ -50,8 +47,7 @@ export default class CappedTubesCriterion extends Component {
5047
}
5148

5249
_buildTubesViewModel(tubes) {
53-
return tubes
54-
.sortBy('practicalName')
50+
return sortBy([...tubes], 'practicalName')
5551
.map((tube) => ({
5652
tube,
5753
cappedTube: this.args.criterion.cappedTubes.find(({ tubeId }) => tubeId === tube.id),

admin/app/components/certification-centers/information-edit.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { tracked } from '@glimmer/tracking';
1111
import pick from 'ember-composable-helpers/helpers/pick';
1212
import { t } from 'ember-intl';
1313
import set from 'ember-set-helper/helpers/set';
14+
import sortBy from 'lodash/sortBy';
1415

1516
import contains from '../../helpers/contains.js';
1617
import { types } from '../../models/certification-center';
@@ -31,7 +32,7 @@ export default class InformationEdit extends Component {
3132
}
3233

3334
get availableHabilitations() {
34-
return this.args.availableHabilitations?.sortBy('id');
35+
return sortBy([...this.args.availableHabilitations], 'id');
3536
}
3637

3738
@action

admin/app/components/certification-centers/information-view.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { service } from '@ember/service';
44
import Component from '@glimmer/component';
55
import { tracked } from '@glimmer/tracking';
66
import { t } from 'ember-intl';
7+
import sortBy from 'lodash/sortBy';
78
import ENV from 'pix-admin/config/environment';
89

910
import HabilitationTag from './habilitation-tag';
@@ -20,7 +21,7 @@ export default class InformationView extends Component {
2021
}
2122

2223
get availableHabilitations() {
23-
const habilitations = this.args.availableHabilitations?.sortBy('id') || [];
24+
const habilitations = sortBy([...this.args.availableHabilitations], 'id') || [];
2425
return habilitations.map((habilitation) => {
2526
const isHabilitated = this.habilitations.includes(habilitation);
2627
const label = habilitation.label;

admin/app/components/certification-centers/invitations.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { service } from '@ember/service';
66
import Component from '@glimmer/component';
77
import dayjsFormat from 'ember-dayjs/helpers/dayjs-format';
88
import { t } from 'ember-intl';
9+
import sortBy from 'lodash/sortBy';
910

1011
export default class CertificationCenterInvitations extends Component {
1112
@service intl;
1213

1314
get sortedCertificationCenterInvitations() {
14-
return this.args.certificationCenterInvitations.sortBy('updatedAt').reverse();
15+
return sortBy([...this.args.certificationCenterInvitations], 'updatedAt').reverse();
1516
}
1617

1718
<template>

admin/app/components/complementary-certifications/list.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import PixTableColumn from '@1024pix/pix-ui/components/pix-table-column';
33
import { LinkTo } from '@ember/routing';
44
import Component from '@glimmer/component';
55
import { t } from 'ember-intl';
6+
import sortBy from 'lodash/sortBy';
67

78
export default class List extends Component {
89
get sortedComplementaryCertifications() {
9-
return this.args.complementaryCertifications.sortBy('label');
10+
return sortBy([...this.args.complementaryCertifications], 'label');
1011
}
1112

1213
<template>

admin/app/components/organizations/invitations.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import { service } from '@ember/service';
66
import Component from '@glimmer/component';
77
import dayjsFormat from 'ember-dayjs/helpers/dayjs-format';
88
import { t } from 'ember-intl';
9+
import sortBy from 'lodash/sortBy';
910

1011
export default class OrganizationInvitations extends Component {
1112
@service accessControl;
1213
@service intl;
1314

1415
get sortedInvitations() {
15-
return this.args.invitations.sortBy('updatedAt').reverse();
16+
return sortBy([...this.args.invitations], 'updatedAt').reverse();
1617
}
1718

1819
<template>

admin/app/components/sessions/certifications/list.gjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import PixTableColumn from '@1024pix/pix-ui/components/pix-table-column';
44
import { LinkTo } from '@ember/routing';
55
import Component from '@glimmer/component';
66
import { t } from 'ember-intl';
7+
import sortBy from 'lodash/sortBy';
78

89
import CertificationStatus from './status';
10+
911
export default class CertificationsHeader extends Component {
1012
get sortedCertificationJurySummaries() {
11-
return this.args.juryCertificationSummaries.sortBy('numberOfCertificationIssueReportsWithRequiredAction').reverse();
13+
return sortBy(
14+
[...this.args.juryCertificationSummaries],
15+
'numberOfCertificationIssueReportsWithRequiredAction',
16+
).reverse();
1217
}
1318

1419
<template>

admin/app/components/target-profiles/badge-form/capped-tubes-criterion.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { action } from '@ember/object';
66
import Component from '@glimmer/component';
77
import { tracked } from '@glimmer/tracking';
88
import { t } from 'ember-intl';
9+
import sortBy from 'lodash/sortBy';
910

1011
import Areas from '../../common/tubes-selection/areas';
1112

@@ -22,7 +23,7 @@ export default class CappedTubesCriterion extends Component {
2223
}
2324

2425
get areas() {
25-
return this.areasList.sortBy('code');
26+
return sortBy([...this.areasList], 'code');
2627
}
2728

2829
@action

admin/app/components/trainings/trigger/details.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { service } from '@ember/service';
22
import Component from '@glimmer/component';
33
import { tracked } from '@glimmer/tracking';
4+
import sortBy from 'lodash/sortBy';
45

56
import Area from '../../common/tubes-details/area';
67

@@ -17,7 +18,7 @@ export default class Details extends Component {
1718
}
1819

1920
get areasList() {
20-
return this.areas.sortBy('code').map((area) => this.buildAreaViewModel(area));
21+
return sortBy([...this.areas], 'code').map((area) => this.buildAreaViewModel(area));
2122
}
2223

2324
buildAreaViewModel(area) {

admin/app/components/users/certification-centers/memberships.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Component from '@glimmer/component';
22
import { t } from 'ember-intl';
3+
import sortBy from 'lodash/sortBy';
34

45
import MembershipItem from './membership-item';
56

67
export default class Memberships extends Component {
78
get orderedCertificationCenterMemberships() {
8-
return this.args.certificationCenterMemberships.sortBy('certificationCenter.name');
9+
return sortBy([...this.args.certificationCenterMemberships], 'certificationCenter.name');
910
}
1011

1112
<template>

admin/app/components/users/user-organization-memberships.gjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { LinkTo } from '@ember/routing';
22
import { service } from '@ember/service';
33
import Component from '@glimmer/component';
4+
import sortBy from 'lodash/sortBy';
45

56
import ActionsOnUsersRoleInOrganization from '../actions-on-users-role-in-organization';
67

78
export default class UserOrganizationMemberships extends Component {
89
@service accessControl;
910

1011
get orderedOrganizationMemberships() {
11-
return this.args.organizationMemberships.sortBy('organizationName');
12+
return sortBy([...this.args.organizationMemberships], 'organizationName');
1213
}
1314

1415
<template>

admin/app/controllers/authenticated/target-profiles/target-profile/details.js

+14-21
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,51 @@
11
import Controller from '@ember/controller';
2+
import sortBy from 'lodash/sortBy';
23

34
export default class TargetProfileDetailsController extends Controller {
45
get areas() {
5-
return this.model.areas.sortBy('frameworkId', 'code').map((area) => this.buildAreaViewModel(area));
6+
return sortBy([...this.model.areas], ['frameworkId', 'code']).map((area) => this.buildAreaViewModel(area));
67
}
78

89
buildAreaViewModel(area) {
10+
const competences = sortBy([...area.hasMany('competences').value()], 'index');
11+
912
return {
1013
title: `${area.code} · ${area.title}`,
1114
color: area.color,
12-
competences: area
13-
.hasMany('competences')
14-
.value()
15-
.sortBy('index')
16-
.map((competence) => this.buildCompetenceViewModel(competence)),
15+
competences: competences.map((competence) => this.buildCompetenceViewModel(competence)),
1716
};
1817
}
1918

2019
buildCompetenceViewModel(competence) {
20+
const thematics = sortBy([...competence.hasMany('thematics').value()], 'index');
21+
2122
return {
2223
id: competence.id,
2324
title: `${competence.index} ${competence.name}`,
24-
thematics: competence
25-
.hasMany('thematics')
26-
.value()
27-
.sortBy('index')
28-
.map((thematic) => this.buildThematicViewModel(thematic)),
25+
thematics: thematics.map((thematic) => this.buildThematicViewModel(thematic)),
2926
};
3027
}
3128

3229
buildThematicViewModel(thematic) {
30+
const tubes = sortBy([...thematic.hasMany('tubes').value()], 'practicalTitle');
31+
3332
return {
3433
name: thematic.name,
3534
nbTubes: thematic.hasMany('tubes').value().length,
36-
tubes: thematic
37-
.hasMany('tubes')
38-
.value()
39-
.sortBy('practicalTitle')
40-
.map((tube) => this.buildTubeViewModel(tube)),
35+
tubes: tubes.map((tube) => this.buildTubeViewModel(tube)),
4136
};
4237
}
4338

4439
buildTubeViewModel(tube) {
40+
const skills = sortBy([...tube.hasMany('skills').value()], 'difficulty');
41+
4542
return {
4643
id: tube.id,
4744
title: `${tube.name} : ${tube.practicalTitle}`,
4845
level: tube.level,
4946
mobile: tube.mobile,
5047
tablet: tube.tablet,
51-
skills: tube
52-
.hasMany('skills')
53-
.value()
54-
.sortBy('difficulty')
55-
.map((skill) => this.buildSkillViewModel(skill)),
48+
skills: skills.map((skill) => this.buildSkillViewModel(skill)),
5649
};
5750
}
5851

admin/app/models/area.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Model, { attr, hasMany } from '@ember-data/model';
2+
import sortBy from 'lodash/sortBy';
23

34
export default class Area extends Model {
45
@attr() title;
@@ -9,6 +10,6 @@ export default class Area extends Model {
910
@hasMany('competence', { async: true, inverse: null }) competences;
1011

1112
get sortedCompetences() {
12-
return this.hasMany('competences').value().sortBy('index');
13+
return sortBy([...this.hasMany('competences').value()], 'index');
1314
}
1415
}

admin/app/models/competence.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Model, { attr, hasMany } from '@ember-data/model';
2+
import sortBy from 'lodash/sortBy';
23

34
export default class Competence extends Model {
45
@attr() name;
@@ -7,6 +8,6 @@ export default class Competence extends Model {
78
@hasMany('thematic', { async: true, inverse: null }) thematics;
89

910
get sortedThematics() {
10-
return this.hasMany('thematics').value().sortBy('index');
11+
return sortBy([...this.hasMany('thematics').value()], 'index');
1112
}
1213
}

admin/app/models/training.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Model, { attr, hasMany } from '@ember-data/model';
2+
import sortBy from 'lodash/sortBy';
23

34
import formatList from '../utils/format-select-options';
45

@@ -54,6 +55,6 @@ export default class Training extends Model {
5455
}
5556

5657
get sortedTargetProfileSummaries() {
57-
return this.hasMany('targetProfileSummaries').value().sortBy('id');
58+
return sortBy([...this.hasMany('targetProfileSummaries').value()], 'id');
5859
}
5960
}

0 commit comments

Comments
 (0)