Skip to content

Commit

Permalink
Merge pull request #8089 from stopfstedt/program_year_objectives_sorting
Browse files Browse the repository at this point in the history
fixes broken getter and moves it from model into component where it belongs
  • Loading branch information
dartajax committed Aug 22, 2024
2 parents 9f45a1e + 36ad82d commit ef86c64
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<span class="grid-item" data-test-header>{{t "general.meshTerms"}}</span>
<span class="actions grid-item" data-test-header>{{t "general.actions"}}</span>
</div>
{{#if (and (is-array @programYear.sortedProgramYearObjectives) (is-array this.domainTrees))}}
{{#each @programYear.sortedProgramYearObjectives as |programYearObjective|}}
{{#if (is-array this.domainTrees)}}
{{#each this.sortedProgramYearObjectives as |programYearObjective|}}
<ProgramYear::ObjectiveListItem
@programYearObjective={{programYearObjective}}
@editable={{@editable}}
Expand Down
13 changes: 13 additions & 0 deletions packages/frontend/app/components/program-year/objective-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { map } from 'rsvp';
import { service } from '@ember/service';
import { TrackedAsyncData } from 'ember-async-data';
import { mapBy, uniqueValues } from 'ilios-common/utils/array-helpers';
import sortableByPosition from 'ilios-common/utils/sortable-by-position';

export default class ProgramYearObjectiveListComponent extends Component {
@service iliosConfig;
@service session;
Expand Down Expand Up @@ -32,6 +34,17 @@ export default class ProgramYearObjectiveListComponent extends Component {
return this.domainTreesData.isResolved ? this.domainTreesData.value : [];
}

@cached
get programYearObjectivesData() {
return new TrackedAsyncData(this.args.programYear.programYearObjectives);
}

get sortedProgramYearObjectives() {
return this.programYearObjectivesData.isResolved
? this.programYearObjectivesData.value.slice().sort(sortableByPosition)
: [];
}

get programYearObjectiveCount() {
return this.args.programYear.programYearObjectives.length;
}
Expand Down
16 changes: 0 additions & 16 deletions packages/ilios-common/addon/models/program-year.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Model, { hasMany, belongsTo, attr } from '@ember-data/model';
import sortableByPosition from 'ilios-common/utils/sortable-by-position';
import { TrackedAsyncData } from 'ember-async-data';
import { cached } from '@glimmer/tracking';
import { sortBy, uniqueValues } from 'ilios-common/utils/array-helpers';
Expand Down Expand Up @@ -34,11 +33,6 @@ export default class ProgramYear extends Model {
@hasMany('program-year-objective', { async: true, inverse: 'programYear' })
programYearObjectives;

@cached
get _programYearObjectivesData() {
return new TrackedAsyncData(this.programYearObjectives);
}

@hasMany('term', { async: true, inverse: 'programYears' })
terms;

Expand Down Expand Up @@ -91,16 +85,6 @@ export default class ProgramYear extends Model {
return Number(this.startYear) + Number(program.duration);
}

/**
* A list of program-year objectives, sorted by position.
*/
get sortedProgramYearObjectives() {
if (!this._programYearObjectivesData.isResolved) {
return null;
}
return this._programYearObjectivesData.value.slice().sort(sortableByPosition);
}

@cached
get _termVocabularies() {
if (!this._termsData.isResolved) {
Expand Down
28 changes: 0 additions & 28 deletions packages/test-app/tests/unit/models/program-year-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,6 @@ module('Unit | Model | ProgramYear', function (hooks) {
assert.strictEqual(await waitForResource(model, 'classOfYear'), '2006');
});

test('sortedProgramYearObjectives', async function (assert) {
const store = this.owner.lookup('service:store');
const programYear = store.createRecord('program-year');
const programYearObjective1 = store.createRecord('program-year-objective', {
id: 1,
programYear,
title: 'Aardvark',
position: 3,
});
const programYearObjective2 = store.createRecord('program-year-objective', {
id: 2,
programYear,
title: 'Bar',
position: 2,
});
const programYearObjective3 = store.createRecord('program-year-objective', {
id: 3,
programYear,
title: 'Foo',
position: 2,
});
const objectives = await waitForResource(programYear, 'sortedProgramYearObjectives');
assert.strictEqual(objectives.length, 3);
assert.strictEqual(objectives[0], programYearObjective3);
assert.strictEqual(objectives[1], programYearObjective2);
assert.strictEqual(objectives[2], programYearObjective1);
});

test('assignableVocabularies', async function (assert) {
const store = this.owner.lookup('service:store');
const programYear = store.createRecord('program-year');
Expand Down

0 comments on commit ef86c64

Please sign in to comment.