Skip to content

Commit

Permalink
Merge pull request #8363 from michaelchadwick/remove-ay-report-render…
Browse files Browse the repository at this point in the history
…-modifier

Remove Reporting AcademicYear render modifier
  • Loading branch information
dartajax authored Feb 12, 2025
2 parents 4df03e4 + 7e7cfc1 commit fce18e1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 50 deletions.
2 changes: 0 additions & 2 deletions packages/frontend/.lint-todo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ add|ember-template-lint|no-at-ember-render-modifiers|5|2|5|2|23cd787c79c34a628da
add|ember-template-lint|no-at-ember-render-modifiers|6|2|6|2|e5120f87b74c5ae8e4c76b9089e0b4a4504c6e3c|1731542400000|1762646400000|1793750400000|app/components/user-profile-roles.hbs
add|ember-template-lint|no-at-ember-render-modifiers|3|2|3|2|1fb0566922ce4f066916e5e2931f650f69d7cfba|1731542400000|1762646400000|1793750400000|app/components/visualizer-program-year-objectives.hbs
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|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
add|ember-template-lint|no-at-ember-render-modifiers|11|6|11|6|940005188b476a060b0e5d3f05baea24ba178878|1731542400000|1762646400000|1793750400000|app/components/reports/subject/new/competency.hbs
add|ember-template-lint|no-at-ember-render-modifiers|10|6|10|6|d919d2af254f782c01fe2ba15416673e52e91124|1731542400000|1762646400000|1793750400000|app/components/reports/subject/new/instructor-group.hbs
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/app/components/reports/new-subject.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ export default class ReportsNewSubjectComponent extends Component {

get newPrepositionalObjectComponent() {
switch (this.prepositionalObject) {
case 'academic year':
return ensureSafeComponent(NewAcademicYearComponent, this);
case 'competency':
return ensureSafeComponent(NewCompetencyComponent, this);
case 'course':
Expand All @@ -237,8 +239,6 @@ export default class ReportsNewSubjectComponent extends Component {
return ensureSafeComponent(NewSessionTypeComponent, this);
case 'term':
return ensureSafeComponent(NewTermComponent, this);
case 'academic year':
return ensureSafeComponent(NewAcademicYearComponent, this);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
<label for="new-term">
{{t "general.whichIs"}}
</label>
{{#if this.isLoaded}}
{{#if this.academicYearsData.isResolved}}
<select
id="new-academic-year"
data-test-prepositional-objects
{{on "change" (pick "target.value" @changeId)}}
{{did-insert (perform this.setInitialValue)}}
{{did-update (perform this.setInitialValue) @school}}
>
{{#each (sort-by "title" this.academicYears) as |year|}}
<option selected={{eq year.id @currentId}} value={{year.id}}>
<option selected={{eq year.id this.bestSelectedAcademicYear}} value={{year.id}}>
{{#if this.academicYearCrossesCalendarYearBoundaries}}
{{year.id}}
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,41 @@ import Component from '@glimmer/component';
import { TrackedAsyncData } from 'ember-async-data';
import { cached } from '@glimmer/tracking';
import { service } from '@ember/service';
import { task, timeout } from 'ember-concurrency';
import currentAcademicYear from 'ilios-common/utils/current-academic-year';

export default class ReportsSubjectNewAcademicYearComponent extends Component {
@service store;
@service iliosConfig;

@cached
get data() {
get academicYearsData() {
return new TrackedAsyncData(this.store.findAll('academic-year'));
}

crossesBoundaryConfig = new TrackedAsyncData(
this.iliosConfig.itemFromConfig('academicYearCrossesCalendarYearBoundaries'),
);

@cached
get academicYearCrossesCalendarYearBoundaries() {
return this.crossesBoundaryConfig.isResolved ? this.crossesBoundaryConfig.value : false;
}

get academicYears() {
return this.data.value;
return this.academicYearsData.isResolved ? this.academicYearsData.value : [];
}

get isLoaded() {
return this.data.isResolved;
}

@task
*setInitialValue() {
yield timeout(1); //wait a moment so we can render before setting
get bestSelectedAcademicYear() {
const ids = this.academicYears.map(({ id }) => id);

if (ids.includes(this.args.currentId)) {
return;
return this.args.currentId;
}

const currentYear = currentAcademicYear();
const currentYearId = this.academicYears.find(({ id }) => Number(id) === currentYear)?.id;
this.args.changeId(currentYearId ?? ids.at(-1));
const newId = currentYearId ?? ids.at(-1);

return newId;
}

crossesBoundaryConfig = new TrackedAsyncData(
this.iliosConfig.itemFromConfig('academicYearCrossesCalendarYearBoundaries'),
);

@cached
get academicYearCrossesCalendarYearBoundaries() {
return this.crossesBoundaryConfig.isResolved ? this.crossesBoundaryConfig.value : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module('Integration | Component | reports/subject/new/academic-year', function (
});

test('it renders', async function (assert) {
assert.expect(14);
assert.expect(12);
this.set('currentId', null);
this.set('changeId', (id) => {
assert.strictEqual(id, '2060');
Expand All @@ -37,28 +37,27 @@ module('Integration | Component | reports/subject/new/academic-year', function (
@school={{null}}
/>`);

assert.strictEqual(component.options.length, 3);
assert.strictEqual(component.options[0].text, '2015');
assert.strictEqual(component.options[1].text, '2031');
assert.strictEqual(component.options[2].text, '2060');
assert.strictEqual(component.options.length, 3, 'dropdown has 3 options');
assert.strictEqual(component.options[0].text, '2015', 'first option is 2015');
assert.strictEqual(component.options[1].text, '2031', 'second option is 2031');
assert.strictEqual(component.options[2].text, '2060', 'third option is 2060');

assert.strictEqual(component.value, '2060');
assert.strictEqual(component.value, '2060', 'selected option is 2060');

assert.notOk(component.options[0].isSelected);
assert.notOk(component.options[1].isSelected);
assert.ok(component.options[2].isSelected);
assert.notOk(component.options[0].isSelected, 'option 0 is not selected');
assert.notOk(component.options[1].isSelected, 'option 1 is not selected');
assert.ok(component.options[2].isSelected, 'option 2 is selected');

this.set('changeId', (id) => {
assert.strictEqual(id, '2031');
this.set('currentId', id);
});

this.set('currentId', '2031');
assert.notOk(component.options[0].isSelected);
assert.notOk(component.options[0].isSelected);
assert.ok(component.options[1].isSelected);
assert.notOk(component.options[2].isSelected);
assert.strictEqual(component.value, '2031');
assert.notOk(component.options[0].isSelected, 'option 0 is not selected');
assert.ok(component.options[1].isSelected, 'option 1 is selected');
assert.notOk(component.options[2].isSelected, 'option 2 is not selected');
assert.strictEqual(component.value, '2031', 'selected option is 2031');
});

test('it works', async function (assert) {
Expand All @@ -73,14 +72,14 @@ module('Integration | Component | reports/subject/new/academic-year', function (
assert.strictEqual(id, '2031');
this.set('currentId', id);
});
assert.ok(component.options[0].isSelected);
assert.notOk(component.options[1].isSelected);
assert.notOk(component.options[2].isSelected);
assert.ok(component.options[0].isSelected, 'option 0 is selected');
assert.notOk(component.options[1].isSelected, 'option 1 is not selected');
assert.notOk(component.options[2].isSelected, 'option 2 is not selected');

await component.set('2031');
assert.notOk(component.options[0].isSelected);
assert.ok(component.options[1].isSelected);
assert.notOk(component.options[2].isSelected);
assert.strictEqual(component.value, '2031');
assert.notOk(component.options[0].isSelected, 'option 0 is not selected');
assert.ok(component.options[1].isSelected, 'option 1 is selected');
assert.notOk(component.options[2].isSelected, 'option 2 is not selected');
assert.strictEqual(component.value, '2031', 'selected option is 2031');
});
});

0 comments on commit fce18e1

Please sign in to comment.