-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
realigns Curr Inv Expanded Leadership component with equivalents.
replace the modifier-based data loading process with a tracked-resource one already used in leadership mngmt components for programs and program-years. align the related testing components as well while at it.
- Loading branch information
1 parent
e135037
commit 6442f4d
Showing
6 changed files
with
98 additions
and
96 deletions.
There are no files selected for viewing
91 changes: 43 additions & 48 deletions
91
packages/frontend/app/components/curriculum-inventory/leadership-expanded.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
<div | ||
class="curriculum-inventory-leadership-expanded" | ||
data-test-curriculum-inventory-leadership-expanded | ||
{{did-insert (perform this.load) @report}} | ||
> | ||
{{#if this.load.isRunning}} | ||
<LoadingSpinner /> | ||
{{else}} | ||
<div class="curriculum-inventory-leadership-expanded-header" data-test-header> | ||
<button | ||
class="title link-button" | ||
type="button" | ||
aria-expanded="true" | ||
data-test-title | ||
{{on "click" @collapse}} | ||
> | ||
{{t "general.leadership"}} ({{this.count}}) | ||
<FaIcon @icon="caret-down" /> | ||
</button> | ||
<div class="actions"> | ||
{{#if @isManaging}} | ||
<button type="button" class="bigadd" {{on "click" (perform this.save)}} data-test-save> | ||
<FaIcon | ||
@icon={{if this.save.isRunning "spinner" "check"}} | ||
@spin={{this.save.isRunning}} | ||
/> | ||
</button> | ||
<button type="button" class="bigcancel" {{on "click" (perform this.cancel)}} data-test-cancel> | ||
<FaIcon @icon="arrow-rotate-left" /> | ||
</button> | ||
{{else if @canUpdate}} | ||
<button type="button" {{on "click" this.manage}} data-test-manage> | ||
{{t "general.manageLeadership"}} | ||
</button> | ||
{{/if}} | ||
</div> | ||
</div> | ||
<div class="curriculum-inventory-leadership-expanded-content" data-test-content> | ||
<div class="curriculum-inventory-leadership-expanded-header" data-test-header> | ||
<button | ||
class="title link-button" | ||
type="button" | ||
aria-expanded="true" | ||
data-test-title | ||
{{on "click" @collapse}} | ||
> | ||
{{t "general.leadership"}} ({{this.count}}) | ||
<FaIcon @icon="caret-down" /> | ||
</button> | ||
<div class="actions"> | ||
{{#if @isManaging}} | ||
<LeadershipManager | ||
@showAdministrators={{true}} | ||
@showDirectors={{false}} | ||
@administrators={{this.administrators}} | ||
@removeAdministrator={{this.removeAdministrator}} | ||
@addAdministrator={{this.addAdministrator}} | ||
/> | ||
{{else}} | ||
<LeadershipList | ||
@showAdministrators={{true}} | ||
@showDirectors={{false}} | ||
@administrators={{this.administrators}} | ||
/> | ||
<button type="button" class="bigadd" {{on "click" (perform this.save)}} data-test-save> | ||
<FaIcon | ||
@icon={{if this.save.isRunning "spinner" "check"}} | ||
@spin={{this.save.isRunning}} | ||
/> | ||
</button> | ||
<button type="button" class="bigcancel" {{on "click" this.close}} data-test-cancel> | ||
<FaIcon @icon="arrow-rotate-left" /> | ||
</button> | ||
{{else if @editable}} | ||
<button type="button" {{on "click" (fn @setIsManaging true)}} data-test-manage> | ||
{{t "general.manageLeadership"}} | ||
</button> | ||
{{/if}} | ||
</div> | ||
{{/if}} | ||
</div> | ||
<div class="curriculum-inventory-leadership-expanded-content" data-test-content> | ||
{{#if @isManaging}} | ||
<LeadershipManager | ||
@showAdministrators={{true}} | ||
@showDirectors={{false}} | ||
@administrators={{this.administrators}} | ||
@removeAdministrator={{this.removeAdministrator}} | ||
@addAdministrator={{this.addAdministrator}} | ||
/> | ||
{{else}} | ||
<LeadershipList | ||
@showAdministrators={{true}} | ||
@showDirectors={{false}} | ||
@administrators={{this.administrators}} | ||
/> | ||
{{/if}} | ||
</div> | ||
</div> |
57 changes: 36 additions & 21 deletions
57
packages/frontend/app/components/curriculum-inventory/leadership-expanded.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,62 @@ | ||
import Component from '@glimmer/component'; | ||
import { dropTask, timeout } from 'ember-concurrency'; | ||
import { action } from '@ember/object'; | ||
import { dropTask } from 'ember-concurrency'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { TrackedAsyncData } from 'ember-async-data'; | ||
import { cached } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
export default class CurriculumInventoryLeadershipExpandedComponent extends Component { | ||
@tracked administrators = []; | ||
@tracked administratorsToAdd = []; | ||
@tracked administratorsToRemove = []; | ||
|
||
@cached | ||
get count() { | ||
return this.administrators.length; | ||
} | ||
|
||
@cached | ||
get reportAdministrators() { | ||
return new TrackedAsyncData(this.args.report.administrators); | ||
} | ||
|
||
@cached | ||
get administrators() { | ||
const administrators = this.reportAdministrators.isResolved | ||
? this.reportAdministrators.value.slice() | ||
: []; | ||
return [...administrators, ...this.administratorsToAdd].filter( | ||
(user) => !this.administratorsToRemove.includes(user), | ||
); | ||
} | ||
|
||
resetBuffers() { | ||
this.administratorsToAdd = []; | ||
this.administratorsToRemove = []; | ||
} | ||
|
||
@action | ||
addAdministrator(user) { | ||
this.administrators = [...this.administrators, user]; | ||
this.administratorsToAdd = [...this.administratorsToAdd, user]; | ||
this.administratorsToRemove = this.administratorsToRemove.filter((d) => d !== user); | ||
} | ||
|
||
@action | ||
removeAdministrator(user) { | ||
this.administrators = this.administrators.filter(({ id }) => id !== user.id); | ||
} | ||
|
||
async setBuffers() { | ||
this.administrators = (await this.args.report.administrators).slice(); | ||
this.administratorsToRemove = [...this.administratorsToRemove, user]; | ||
this.administratorsToAdd = this.administratorsToAdd.filter((d) => d !== user); | ||
} | ||
|
||
@action | ||
manage() { | ||
this.args.setIsManaging(true); | ||
close() { | ||
this.resetBuffers(); | ||
this.args.setIsManaging(false); | ||
} | ||
|
||
load = dropTask(async () => { | ||
await this.setBuffers(); | ||
}); | ||
|
||
save = dropTask(async () => { | ||
await timeout(10); | ||
this.args.report.set('administrators', this.administrators); | ||
this.args.expand(); | ||
this.resetBuffers(); | ||
await this.args.report.save(); | ||
this.args.setIsManaging(false); | ||
}); | ||
|
||
cancel = dropTask(async () => { | ||
await this.setBuffers(); | ||
this.args.setIsManaging(false); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 6 additions & 13 deletions
19
packages/frontend/tests/pages/components/curriculum-inventory/leadership-expanded.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters