Skip to content

Commit

Permalink
Merge pull request #8095 from michaelchadwick/frontend-5660-unslice-f…
Browse files Browse the repository at this point in the history
…rontend-subdir-comps

removed unneeded slice() calls from frontend components in subdirectories
  • Loading branch information
dartajax authored Aug 26, 2024
2 parents 8aba8a2 + cff70e8 commit 9e01f2f
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions packages/frontend/app/components/courses/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class CoursesRootComponent extends Component {

get selectedSchool() {
if (this.args.schoolId) {
const school = findById(this.args.schools.slice(), this.args.schoolId);
const school = findById(this.args.schools, this.args.schoolId);
if (school) {
return school;
}
Expand Down Expand Up @@ -161,7 +161,7 @@ export default class CoursesRootComponent extends Component {
}

removeCourse = dropTask(async (course) => {
const courses = (await this.selectedSchool.courses).slice();
const courses = await this.selectedSchool.courses;
courses.splice(courses.indexOf(course), 1);
this.selectedSchool.set('courses', courses);
await course.destroyRecord();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default class CurriculumInventoryNewSequenceBlock extends Component {
this.orderInSequence = 0;
if (this.isInOrderedSequence) {
const siblings = await this.args.parent.children;
for (let i = 0, n = siblings.slice().length + 1; i < n; i++) {
for (let i = 0, n = siblings.length + 1; i < n; i++) {
this.orderInSequenceOptions.push(i + 1);
}
this.orderInSequence = 1;
Expand All @@ -242,8 +242,8 @@ export default class CurriculumInventoryNewSequenceBlock extends Component {
this.startingAcademicLevel = await this.args.parent.startingAcademicLevel;
this.endingAcademicLevel = await this.args.parent.endingAcademicLevel;
} else {
this.startingAcademicLevel = this.academicLevels.slice()[0];
this.endingAcademicLevel = this.academicLevels.slice()[0];
this.startingAcademicLevel = this.academicLevels[0];
this.endingAcademicLevel = this.academicLevels[0];
}
this.linkableCourses = await this.getLinkableCourses(this.args.report);
}
Expand All @@ -256,8 +256,8 @@ export default class CurriculumInventoryNewSequenceBlock extends Component {
this.startingAcademicLevel = await this.args.parent.startingAcademicLevel;
this.endingAcademicLevel = await this.args.parent.endingAcademicLevel;
} else {
this.startingAcademicLevel = this.academicLevels.slice()[0];
this.endingAcademicLevel = this.academicLevels.slice()[0];
this.startingAcademicLevel = this.academicLevels[0];
this.endingAcademicLevel = this.academicLevels[0];
}
this.linkableCourses = await this.getLinkableCourses(this.args.report);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class CurriculumInventoryReportRolloverComponent extends Componen
const programs = await school.programs;

this.selectedProgram = program;
this.programs = programs.slice();
this.programs = programs;
this.years = years;
this.selectedYear = selectedYear.year;
this.name = this.args.report.name;
Expand Down
10 changes: 5 additions & 5 deletions packages/frontend/app/components/curriculum-inventory/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class CurriculumInventoryReportsComponent extends Component {
}

get curriculumInventoryReports() {
return this.reports ? this.reports.slice() : [];
return this.reports ?? [];
}

@action
Expand Down Expand Up @@ -68,22 +68,22 @@ export default class CurriculumInventoryReportsComponent extends Component {
if (!this.args.schools) {
return;
}
this.sortedSchools = sortBy(this.args.schools.slice(), 'title');
this.sortedSchools = sortBy(this.args.schools, 'title');
this.hasMoreThanOneSchool = this.sortedSchools.length > 1;

if (!this.args.schoolId) {
const user = await this.currentUser.getModel();
this.selectedSchool = await user.school;
} else {
this.selectedSchool = findById(this.args.schools.slice(), this.args.schoolId);
this.selectedSchool = findById(this.args.schools, this.args.schoolId);
}

if (this.selectedSchool) {
this.canCreate = await this.permissionChecker.canCreateCurriculumInventoryReport(
this.selectedSchool,
);
const programs = await this.selectedSchool.programs;
this.programs = sortBy(programs.slice(), 'title');
this.programs = sortBy(programs, 'title');
}

if (this.args.programId) {
Expand All @@ -94,7 +94,7 @@ export default class CurriculumInventoryReportsComponent extends Component {
});

removeCurriculumInventoryReport = dropTask(async (report) => {
const reports = (await this.selectedProgram.curriculumInventoryReports).slice();
const reports = await this.selectedProgram.curriculumInventoryReports;
reports.splice(reports.indexOf(report), 1);
this.selectedProgram.set('curriculumInventoryReports', reports);
await report.destroyRecord();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ export default class CurriculumInventorySequenceBlockOverviewComponent extends C
load = restartableTask(async (element, [sequenceBlock]) => {
this.report = await sequenceBlock.report;
this.parent = await sequenceBlock.parent;
this.academicLevels = (await this.report.academicLevels).slice();
this.academicLevels = await this.report.academicLevels;
this.isInOrderedSequence = false;
this.orderInSequenceOptions = [];
if (isPresent(this.parent) && this.parent.isOrdered) {
this.isInOrderedSequence = true;
const siblings = await this.parent.children;
for (let i = 0, n = siblings.slice().length; i < n; i++) {
for (let i = 0, n = siblings.length; i < n; i++) {
const num = i + 1;
this.orderInSequenceOptions.push(num);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ export default class CurriculumInventorySequenceBlockOverviewComponent extends C
published: true,
},
});
return sessions.slice();
return sessions;
}

changeRequired = dropTask(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class SequenceBlockSessionManagerComponent extends Component {
if (this.allSelected) {
this.linkedSessions = [];
} else {
this.linkedSessions = this.sessions.slice();
this.linkedSessions = this.sessions;
}
}

Expand All @@ -118,7 +118,7 @@ export default class SequenceBlockSessionManagerComponent extends Component {
if (this.allExcluded) {
this.excludedSessions = [];
} else {
this.excludedSessions = this.sessions.slice();
this.excludedSessions = this.sessions;
}
}

Expand All @@ -136,9 +136,9 @@ export default class SequenceBlockSessionManagerComponent extends Component {
}

load = restartableTask(async () => {
this.linkedSessions = (await this.args.sequenceBlock.sessions).slice();
this.excludedSessions = (await this.args.sequenceBlock.excludedSessions).slice();
this.sessions = (await this.args.sessions).slice();
this.linkedSessions = await this.args.sequenceBlock.sessions;
this.excludedSessions = await this.args.sequenceBlock.excludedSessions;
this.sessions = await this.args.sessions;
});

saveChanges = dropTask(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/app/components/instructor-group/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class InstructorGroupUsersComponent extends Component {
}

manage = dropTask(async () => {
this.usersBuffer = (await this.args.instructorGroup.users).slice();
this.usersBuffer = await this.args.instructorGroup.users;
this.isManaging = true;
});

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/app/components/instructor-groups/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export default class InstructorGroupsRootComponent extends Component {

get bestSelectedSchool() {
if (this.args.schoolId) {
return findById(this.args.schools.slice(), this.args.schoolId);
return findById(this.args.schools, this.args.schoolId);
}

const schoolId = this.user?.belongsTo('school').id();
return schoolId ? findById(this.args.schools.slice(), schoolId) : this.args.schools.slice()[0];
return schoolId ? findById(this.args.schools, schoolId) : this.args.schools[0];
}

get filteredInstructorGroups() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class LearnerGroupBulkAssignmentComponent extends Component {
@action
async addMatch(name, groupId) {
const group = await this.store.findRecord('learner-group', groupId);
const matchedGroups = this.matchedGroups.slice();
const matchedGroups = this.matchedGroups;
const match = findBy(matchedGroups, 'name', name);
if (match) {
this.removeMatch(name);
Expand All @@ -49,7 +49,7 @@ export default class LearnerGroupBulkAssignmentComponent extends Component {
parent: learnerGroup,
});
const savedGroup = await group.save();
const children = (await learnerGroup.children).slice();
const children = await learnerGroup.children;
learnerGroup.set('children', [...children, savedGroup]);
this.matchedGroups = [...this.matchedGroups, { name: title, group: savedGroup }];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/app/components/learner-group/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class LearnerGroupCalendarComponent extends Component {
}
const offerings = await all(mapBy(learnerGroups, 'offerings'));
const flat = offerings.reduce((flattened, obj) => {
return [...flattened, ...obj.slice()];
return [...flattened, ...obj];
}, []);
return await map(flat, async (offering) => {
const session = await offering.session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export default class LearnerGroupInstructorManagerComponent extends Component {
const school = await program.get('school');
const availableInstructorGroups = await school.get('instructorGroups');

this.instructors = instructors.slice();
this.instructorGroups = instructorGroups.slice();
this.availableInstructorGroups = availableInstructorGroups.slice();
this.instructors = instructors;
this.instructorGroups = instructorGroups;
this.availableInstructorGroups = availableInstructorGroups;
}
});

Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/app/components/learner-group/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export default class LearnerGroupListItemComponent extends Component {
}

async isLinkedToOfferingsOrIlms(learnerGroup) {
const offerings = (await learnerGroup.offerings).slice();
const offerings = await learnerGroup.offerings;
if (offerings.length) {
return true;
}
const ilms = (await learnerGroup.ilmSessions).slice();
const ilms = await learnerGroup.ilmSessions;
if (ilms.length) {
return true;
}
const children = (await learnerGroup.children).slice();
const children = await learnerGroup.children;
const linkedChildren = await filter(children, async (child) => {
return this.isLinkedToOfferingsOrIlms(child);
});
Expand Down
14 changes: 7 additions & 7 deletions packages/frontend/app/components/learner-group/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class LearnerGroupRootComponent extends Component {
if (!this.subGroups) {
return [];
}
return this.subGroups.slice();
return this.subGroups;
}

get bestUrl() {
Expand Down Expand Up @@ -185,8 +185,8 @@ export default class LearnerGroupRootComponent extends Component {

@action
saveInstructors(newInstructors, newInstructorGroups) {
this.args.learnerGroup.set('instructors', newInstructors.slice());
this.args.learnerGroup.set('instructorGroups', newInstructorGroups.slice());
this.args.learnerGroup.set('instructors', newInstructors);
this.args.learnerGroup.set('instructorGroups', newInstructorGroups);
return this.args.learnerGroup.save();
}

Expand Down Expand Up @@ -251,7 +251,7 @@ export default class LearnerGroupRootComponent extends Component {
} else {
users = await this.args.learnerGroup.getUsersOnlyAtThisLevel();
}
return await map(users.slice(), async (user) => {
return await map(users, async (user) => {
const lowestGroupInTree = await user.getLowestMemberGroupInALearnerGroupTree(this.treeGroups);
return ObjectProxy.create({
content: user,
Expand Down Expand Up @@ -298,8 +298,8 @@ export default class LearnerGroupRootComponent extends Component {
});

async getCoursesForGroupWithSubgroupName(prefix, learnerGroup) {
const offerings = (await learnerGroup.offerings).slice();
const ilms = (await learnerGroup.ilmSessions).slice();
const offerings = await learnerGroup.offerings;
const ilms = await learnerGroup.ilmSessions;
const arr = [].concat(offerings, ilms);
const sessions = await Promise.all(mapBy(arr, 'session'));
const filteredSessions = uniqueValues(sessions.filter(Boolean));
Expand All @@ -316,7 +316,7 @@ export default class LearnerGroupRootComponent extends Component {
}
return obj;
});
const children = (await learnerGroup.children).slice();
const children = await learnerGroup.children;
const childCourses = await map(children, async (child) => {
return await this.getCoursesForGroupWithSubgroupName(learnerGroup.title, child);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/app/components/learner-group/upload-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export default class LearnerGroupUploadDataComponent extends Component {
} else if (users.length > 1) {
errors.push(this.intl.t('general.multipleUsersFoundWithCampusId', { campusId }));
} else {
const user = users.slice()[0];
const user = users[0];
const cohorts = await user.cohorts;
const cohortIds = mapBy(cohorts.slice(), 'id');
const cohortIds = mapBy(cohorts, 'id');
if (!cohortIds.includes(cohort.id)) {
errors.push(
this.intl.t('general.userNotInGroupCohort', { cohortTitle: cohort.get('title') }),
Expand Down
20 changes: 10 additions & 10 deletions packages/frontend/app/components/learner-groups/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class LearnerGroupsRootComponent extends Component {
get selectedSchool() {
const schoolId = this.args.schoolId ?? this.user?.belongsTo('school').id();

const school = findById(this.args.schools.slice(), schoolId) ?? this.args.schools.slice()[0];
const school = findById(this.args.schools, schoolId) ?? this.args.schools[0];
//trigger a pre-load of the data we need to load an individual group in this school
this.dataLoader.loadInstructorGroupsForSchool(school.id);
return school;
Expand All @@ -121,7 +121,7 @@ export default class LearnerGroupsRootComponent extends Component {
return null;
}
if (this.args.programId) {
return findById(this.programs.slice(), this.args.programId);
return findById(this.programs, this.args.programId);
}

return this.defaultSelectedProgram;
Expand All @@ -132,10 +132,10 @@ export default class LearnerGroupsRootComponent extends Component {
return null;
}
if (this.args.programYearId) {
return findById(this.programYears.slice(), this.args.programYearId);
return findById(this.programYears, this.args.programYearId);
}

return sortBy(this.programYears.slice(), 'startYear').reverse()[0];
return sortBy(this.programYears, 'startYear').reverse()[0];
}

get rootLevelLearnerGroups() {
Expand All @@ -147,7 +147,7 @@ export default class LearnerGroupsRootComponent extends Component {

get filteredLearnerGroups() {
if (!this.args.titleFilter) {
return this.rootLevelLearnerGroups.slice();
return this.rootLevelLearnerGroups;
}
const filter = this.args.titleFilter.trim().toLowerCase();
return this.rootLevelLearnerGroups.filter((learnerGroup) => {
Expand All @@ -161,7 +161,7 @@ export default class LearnerGroupsRootComponent extends Component {
cohort: this.selectedCohort,
});
if (fillWithCohort) {
const users = (await this.selectedCohort.users).slice();
const users = await this.selectedCohort.users;
group.set('users', users);
}
this.savedLearnerGroup = await group.save();
Expand All @@ -188,9 +188,9 @@ export default class LearnerGroupsRootComponent extends Component {
if (!programs) {
return null;
}
const sortingPrograms = await map(programs.slice(), async (program) => {
const sortingPrograms = await map(programs, async (program) => {
const thisYear = new Date().getFullYear();
const programYears = (await program.programYears).slice();
const programYears = await program.programYears;
const sorters = await map(programYears, async (programYear) => {
const groupCount = (await programYear.cohort).hasMany('learnerGroups').ids().length;
return {
Expand Down Expand Up @@ -236,15 +236,15 @@ export default class LearnerGroupsRootComponent extends Component {
}

setProgramId = dropTask(async (programId) => {
const program = findById(this.programs.slice(), programId);
const program = findById(this.programs, programId);
const school = await program.school;
this.args.setSchoolId(school.id);
this.args.setProgramId(program.id);
this.args.setProgramYearId(null);
});

setProgramYearId = dropTask(async (programYearId) => {
const programYear = findById(this.programYears.slice(), programYearId);
const programYear = findById(this.programYears, programYearId);
const program = await programYear.program;
const school = await program.school;
this.args.setSchoolId(school.id);
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/app/components/program-year/competencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export default class ProgramYearCompetenciesComponent extends Component {
const program = await programYear.program;
const school = await program.school;
const competencies = await school.competencies;
const domains = await map(competencies.slice(), async (c) => c.getDomain());
const domains = await map(competencies, async (c) => c.getDomain());
const programYearCompetencies = await programYear.competencies;

return { program, school, competencies, domains, programYearCompetencies };
}

async getCompetenciesWithSelectedChildren(selectedCompetencies, competencies) {
return await filter(competencies.slice(), async (competency) => {
return await filter(competencies, async (competency) => {
const children = await competency.children;
const selectedChildren = children.filter((c) => selectedCompetencies.includes(c));
return selectedChildren.length > 0;
Expand Down
Loading

0 comments on commit 9e01f2f

Please sign in to comment.