From bd99907ec0d7120e9e163be55112869ea00a8b92 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 20 Dec 2024 10:38:47 -0800 Subject: [PATCH] replaces tracked prop usersToPassToCohortManager with getter, then rm obsolete load() task. --- packages/frontend/.lint-todo | 2 - .../app/components/learner-group/root.hbs | 504 +++++++++--------- .../app/components/learner-group/root.js | 32 +- 3 files changed, 268 insertions(+), 270 deletions(-) diff --git a/packages/frontend/.lint-todo b/packages/frontend/.lint-todo index d67a2cbdb8..3c0a994fab 100644 --- a/packages/frontend/.lint-todo +++ b/packages/frontend/.lint-todo @@ -7,8 +7,6 @@ add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|1fb0566922ce4f06691 add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|38e65b45b56fdfd4160d3b0884114b6643e3a036|1731542400000|1762646400000|1793750400000|app/components/visualizer-program-year-objectives.hbs add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|cb6d7acb9879902b89ad1575846d290a564ffbae|1731542400000|1762646400000|1793750400000|app/components/learner-group/instructor-manager.hbs add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|2bdc98d02ac5ea2a4bd5bac6a0f9e880abafdcbe|1731542400000|1762646400000|1793750400000|app/components/learner-group/instructor-manager.hbs -add|ember-template-lint|no-at-ember-render-modifiers|4|4|4|4|170987df2d1e4c134a0ac459fc0bdd8dd91b9929|1731542400000|1762646400000|1793750400000|app/components/learner-group/root.hbs -add|ember-template-lint|no-at-ember-render-modifiers|5|4|5|4|7c59a55b95fd159dd99afa6b20e5f05b5b68def0|1731542400000|1762646400000|1793750400000|app/components/learner-group/root.hbs add|ember-template-lint|no-at-ember-render-modifiers|10|6|10|6|d919d2af254f782c01fe2ba15416673e52e91124|1731542400000|1762646400000|1793750400000|app/components/reports/subject/new/academic-year.hbs add|ember-template-lint|no-at-ember-render-modifiers|11|6|11|6|940005188b476a060b0e5d3f05baea24ba178878|1731542400000|1762646400000|1793750400000|app/components/reports/subject/new/academic-year.hbs add|ember-template-lint|no-at-ember-render-modifiers|10|6|10|6|d919d2af254f782c01fe2ba15416673e52e91124|1731542400000|1762646400000|1793750400000|app/components/reports/subject/new/competency.hbs diff --git a/packages/frontend/app/components/learner-group/root.hbs b/packages/frontend/app/components/learner-group/root.hbs index 3cef23359b..2ad3357d40 100644 --- a/packages/frontend/app/components/learner-group/root.hbs +++ b/packages/frontend/app/components/learner-group/root.hbs @@ -1,279 +1,271 @@ {{#let (unique-id) as |templateId|}} -
- {{#unless this.load.isRunning}} - {{#if this.isSavingGroups}} - - {{/if}} - + {{#if this.isSavingGroups}} + -
-
- - - {{#if @canUpdate}} - - {{else}} - {{#if @learnerGroup.needsAccommodation}} - {{t "general.yes"}} - {{else}} - {{t "general.no"}} - {{/if}} - {{/if}} - -
-
- - - {{#if @canUpdate}} - - - - - {{else if this.location}} - {{this.location}} + {{/if}} + +
+
+ + + {{#if @canUpdate}} + + {{else}} + {{#if @learnerGroup.needsAccommodation}} + {{t "general.yes"}} {{else}} - {{t "general.none"}} + {{t "general.no"}} {{/if}} - + {{/if}} + +
+
+ + + {{#if @canUpdate}} + + + + + {{else if this.location}} + {{this.location}} + {{else}} + {{t "general.none"}} + {{/if}} + +
+
+ + + {{#if @canUpdate}} + + {{! template-lint-disable no-bare-strings}} + + + + {{else if this.url}} + {{this.url}} + {{else}} + {{t "general.none"}} + {{/if}} + +
+
+ +
    + {{#each (sort-by "courseTitle" this.courses) as |obj|}} +
  • + + {{obj.courseTitle}} + {{#if this.academicYearCrossesCalendarYearBoundaries}} + ({{obj.course.year}} + - + {{add obj.course.year 1}}) + {{else}} + ({{obj.course.year}}) + {{/if}} + +
  • + {{/each}} +
+
+ +
+
+ {{#if @isEditing}} + {{t "general.manageGroupMembership"}} + {{else if @isBulkAssigning}} + {{t "general.uploadGroupAssignments"}} + {{else}} + {{t "general.members"}} + ({{this.usersForUserManager.length}}) + {{/if}}
-
- - + + {{#if (or @isEditing @isBulkAssigning)}} + + {{else}} + {{#if @canUpdate}} - - {{! template-lint-disable no-bare-strings}} - - - - {{else if this.url}} - {{this.url}} - {{else}} - {{t "general.none"}} - {{/if}} - -
-
- -
    - {{#each (sort-by "courseTitle" this.courses) as |obj|}} -
  • - - {{obj.courseTitle}} - {{#if this.academicYearCrossesCalendarYearBoundaries}} - ({{obj.course.year}} - - - {{add obj.course.year 1}}) - {{else}} - ({{obj.course.year}}) - {{/if}} - -
  • - {{/each}} -
-
- -
-
- {{#if @isEditing}} - {{t "general.manageGroupMembership"}} - {{else if @isBulkAssigning}} - {{t "general.uploadGroupAssignments"}} - {{else}} - {{t "general.members"}} - ({{this.usersForUserManager.length}}) - {{/if}} -
- - {{#if (or @isEditing @isBulkAssigning)}} + {{t "general.uploadGroupAssignments"}} + - {{else}} - - {{#if @canUpdate}} - - - {{/if}} {{/if}} - -
- {{#if @isBulkAssigning}} - - {{else if @isEditing}} -
- -
- {{else}} - {{#if this.showLearnerGroupCalendar}} - {{/if}} -
- -
- {{/if}} -
-
-

- {{t "general.subgroups"}} - ({{this.learnerGroups.length}}) -

-
- {{#if @canCreate}} - - {{/if}} -
-
-
- {{#if this.showNewLearnerGroupForm}} - - {{/if}} - {{#if this.newLearnerGroup}} -
- - - {{this.newLearnerGroup.title}} - - {{t "general.savedSuccessfully"}} -
- {{/if}} -
-
- {{#if @learnerGroup.childrenCount}} - - {{/if}} -
-
-
- +
+ {{#if @isBulkAssigning}} + + {{else if @isEditing}} +
+ +
+ {{else}} + {{#if this.showLearnerGroupCalendar}} + + {{/if}} +
+ -
+
+ {{/if}} +
+
+

+ {{t "general.subgroups"}} + ({{this.learnerGroups.length}}) +

+
+ {{#if @canCreate}} + + {{/if}} +
+
+
+ {{#if this.showNewLearnerGroupForm}} + + {{/if}} + {{#if this.newLearnerGroup}} +
+ + + {{this.newLearnerGroup.title}} + + {{t "general.savedSuccessfully"}} +
+ {{/if}} +
+
+ {{#if @learnerGroup.childrenCount}} + + {{/if}} +
+
+
+
- {{/unless}} +
{{/let}} \ No newline at end of file diff --git a/packages/frontend/app/components/learner-group/root.js b/packages/frontend/app/components/learner-group/root.js index 9aa805ee39..30fe0b8c61 100644 --- a/packages/frontend/app/components/learner-group/root.js +++ b/packages/frontend/app/components/learner-group/root.js @@ -3,7 +3,6 @@ import { cached, tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; import ObjectProxy from '@ember/object/proxy'; import { service } from '@ember/service'; -import { isPresent } from '@ember/utils'; import { all, map } from 'rsvp'; import { dropTask, enqueueTask, restartableTask, task } from 'ember-concurrency'; import pad from 'pad'; @@ -23,7 +22,6 @@ export default class LearnerGroupRootComponent extends Component { @tracked location = null; @IsURL() @Length(2, 2000) @tracked url = null; @tracked showLearnerGroupCalendar = false; - @tracked usersToPassToCohortManager = []; @tracked sortGroupsBy = 'title'; @tracked isSavingGroups = false; @tracked savedGroup; @@ -38,12 +36,6 @@ export default class LearnerGroupRootComponent extends Component { this.url = this.args.learnerGroup.url; } - load = restartableTask(async (element, [learnerGroup]) => { - if (isPresent(learnerGroup)) { - this.usersToPassToCohortManager = await this.createUsersToPassToCohortManager.perform(); - } - }); - @cached get learnerGroupId() { return this.args.learnerGroup.id; @@ -285,6 +277,26 @@ export default class LearnerGroupRootComponent extends Component { }); } + @cached + get usersForCohortManagerData() { + // Learnergroup members are only referenced here to trigger a re-computation on membership changes. + return new TrackedAsyncData( + this.getUsersToPassToCohortManager(this.args.learnerGroup, this.args.learnerGroup.users), + ); + } + + get usersForCohortManager() { + return this.usersForCohortManagerData.isResolved ? this.usersForCohortManagerData.value : []; + } + + async getUsersToPassToCohortManager(learnerGroup) { + const cohort = await learnerGroup.cohort; + const topLevelGroup = await learnerGroup.getTopLevelGroup(); + const currentUsers = await topLevelGroup.getAllDescendantUsers(); + const users = await cohort.users; + return users.filter((user) => !currentUsers.includes(user)); + } + addUserToGroup = enqueueTask(async (user) => { const learnerGroup = this.args.learnerGroup; const topLevelGroup = await learnerGroup.topLevelGroup; @@ -292,14 +304,12 @@ export default class LearnerGroupRootComponent extends Component { const addGroups = await learnerGroup.addUserToGroupAndAllParents(user); await Promise.all(removeGroups.map((g) => g.save())); await Promise.all(addGroups.map((g) => g.save())); - this.usersToPassToCohortManager = await this.createUsersToPassToCohortManager.perform(); }); removeUserToCohort = enqueueTask(async (user) => { const topLevelGroup = await this.args.learnerGroup.topLevelGroup; const groups = await topLevelGroup.removeUserFromGroupAndAllDescendants(user); await all(groups.map((group) => group.save())); - this.usersToPassToCohortManager = await this.createUsersToPassToCohortManager.perform(); }); addUsersToGroup = enqueueTask(async (users) => { @@ -318,7 +328,6 @@ export default class LearnerGroupRootComponent extends Component { await Promise.all(uniqueValues(removeGroups).map((g) => g.save())); await Promise.all(uniqueValues(addGroups).map((g) => g.save())); - this.usersToPassToCohortManager = await this.createUsersToPassToCohortManager.perform(); }); removeUsersToCohort = enqueueTask(async (users) => { @@ -330,7 +339,6 @@ export default class LearnerGroupRootComponent extends Component { groupsToSave = [...groupsToSave, ...removeGroups]; } await all(uniqueValues(groupsToSave).map((group) => group.save())); - this.usersToPassToCohortManager = await this.createUsersToPassToCohortManager.perform(); }); createUsersToPassToCohortManager = task(async () => {