Skip to content

Commit

Permalink
Replace Data Loading in Material Manager
Browse files Browse the repository at this point in the history
Because this component is only ever rendered with a material and a
different material cannot be passed in we can do all of the data loading
in the constructor and not worry about the behavior in did-update.

I was also able to remove the spinner as the only data included in the
manager that isn't already loaded is some mesh tree meta data when mesh
terms are attached.
  • Loading branch information
jrjohnson committed Dec 6, 2024
1 parent 0558bc4 commit be1a4c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 0 additions & 2 deletions packages/ilios-common/.lint-todo
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ add|ember-template-lint|no-at-ember-render-modifiers|2|2|2|2|ad17d66e0fe1720bc8d
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|d39abab22a3e75d93f69335da422e7ef73b36283|1731542400000|1762646400000|1793750400000|addon/components/html-editor.hbs
add|ember-template-lint|no-at-ember-render-modifiers|9|2|9|2|1a2522cd1202904fb09a6e811dec6b46d8189ab3|1731542400000|1762646400000|1793750400000|addon/components/ilios-calendar-event-month.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|4|4|4|fc97c348371546a640a56d968295aa0dec994ad9|1731542400000|1762646400000|1793750400000|addon/components/ilios-tooltip.hbs
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|4836956b22094e4400c07a696446403e2e70ae25|1731542400000|1762646400000|1793750400000|addon/components/learningmaterial-manager.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|ed145b35cc73f6141f721a99468b9ac5488e1c3c|1731542400000|1762646400000|1793750400000|addon/components/learningmaterial-manager.hbs
add|ember-template-lint|no-at-ember-render-modifiers|62|10|62|10|5ba6894d30ea3a3eae704867d5bc5d61c5ee4e1f|1731542400000|1762646400000|1793750400000|addon/components/mesh-manager.hbs
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|6bbbcafd85d75fd8f3d70c2bd4ba01d753c24f9c|1731542400000|1762646400000|1793750400000|addon/components/offering-calendar.hbs
add|ember-template-lint|no-at-ember-render-modifiers|4|2|4|2|0a8f8f3c4ad64455e02a7594b39cb2785441d6e8|1731542400000|1762646400000|1793750400000|addon/components/offering-calendar.hbs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<div
class="learningmaterial-manager"
{{did-insert (perform this.load) @learningMaterial}}
{{did-update (perform this.load) @learningMaterial}}
>
{{#if this.load.isRunning}}
<LoadingSpinner class="loading" />
{{else}}
<div class="learningmaterial-manager">
{{#if this.isLoaded}}
{{#let (unique-id) as |templateId|}}
<div class="item displayname">
<label for="displayname-{{templateId}}">
Expand Down
22 changes: 15 additions & 7 deletions packages/ilios-common/addon/components/learningmaterial-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export default class LearningMaterialManagerComponent extends Component {
@service flashMessages;
@service intl;

@tracked notes;
@tracked learningMaterial;
constructor() {
super(...arguments);
this.loadExistingData();
}

validations = new YupValidations(this, {
title: string().required().min(4).max(120),
Expand Down Expand Up @@ -47,9 +49,12 @@ export default class LearningMaterialManagerComponent extends Component {
}),
});

@tracked isLoaded = false;

@tracked notes;
@tracked learningMaterial;
@tracked title;
@tracked endDate;

@tracked type;
@tracked owningUser;
@tracked originalAuthor;
Expand Down Expand Up @@ -200,10 +205,11 @@ export default class LearningMaterialManagerComponent extends Component {
return findById(this.args.learningMaterialStatuses, this.statusId);
}

load = restartableTask(async (element, [learningMaterial]) => {
if (!learningMaterial) {
return;
async loadExistingData() {
if (!this.args.learningMaterial) {
throw new Error('LearningMaterialManagerComponent requires a learningMaterial argument');
}
const { learningMaterial } = this.args;
const parentMaterial = await learningMaterial.learningMaterial;
this.notes = learningMaterial.notes;
this.required = learningMaterial.required;
Expand Down Expand Up @@ -231,7 +237,9 @@ export default class LearningMaterialManagerComponent extends Component {
this.owningUser = await parentMaterial.owningUser;
const userRole = await parentMaterial.userRole;
this.userRoleTitle = userRole.title;
});

this.isLoaded = true;
}

save = dropTask(async () => {
this.validations.addErrorDisplayForAllFields();
Expand Down

0 comments on commit be1a4c8

Please sign in to comment.