From 73519f2a1ed461d8e0048e437ae9b3cff1a38d5f Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Fri, 6 Mar 2026 14:58:37 -0800 Subject: [PATCH] only list vocabularies with selected terms in terms manager. --- .../program-year/objectiveterms-test.js | 27 +++++++------------ .../addon/components/taxonomy-manager.gjs | 12 +-------- .../components/taxonomy-manager-test.gjs | 11 ++++++-- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/packages/frontend/tests/acceptance/program-year/objectiveterms-test.js b/packages/frontend/tests/acceptance/program-year/objectiveterms-test.js index 5df5a7e873..6cc41ee27a 100644 --- a/packages/frontend/tests/acceptance/program-year/objectiveterms-test.js +++ b/packages/frontend/tests/acceptance/program-year/objectiveterms-test.js @@ -59,28 +59,19 @@ module('Acceptance | Program Year - Objective Vocabulary Terms', function (hooks assert.ok(page.details.objectives.objectiveList.objectives[0].taxonomyManager.isPresent); assert.strictEqual( page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms.length, - 2, + 1, ); assert.strictEqual( page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].title, - 'Resources (school 0)', - ); - assert.strictEqual( - page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].terms - .length, - 0, - ); - assert.strictEqual( - page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].title, 'Topics (school 0)', ); assert.strictEqual( - page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].terms + page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].terms .length, 1, ); assert.strictEqual( - page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].terms[0] + page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].terms[0] .name, 'term 0', ); @@ -141,7 +132,7 @@ module('Acceptance | Program Year - Objective Vocabulary Terms', function (hooks page.details.objectives.objectiveList.objectives[0].taxonomyManager.availableTerms[3] .isSelected, ); - await page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].terms[0].remove(); + await page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].terms[0].remove(); await page.details.objectives.objectiveList.objectives[0].taxonomyManager.availableTerms[3].toggle(); await page.details.objectives.objectiveList.objectives[0].selectedTerms.save(); assert.strictEqual( @@ -186,19 +177,19 @@ module('Acceptance | Program Year - Objective Vocabulary Terms', function (hooks assert.ok(page.details.objectives.objectiveList.objectives[0].taxonomyManager.isPresent); assert.strictEqual( page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms.length, - 2, + 1, ); assert.strictEqual( - page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].title, + page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].title, 'Topics (school 0)', ); assert.strictEqual( - page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].terms + page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].terms .length, 1, ); assert.strictEqual( - page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].terms[0] + page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].terms[0] .name, 'term 0', ); @@ -245,7 +236,7 @@ module('Acceptance | Program Year - Objective Vocabulary Terms', function (hooks page.details.objectives.objectiveList.objectives[0].taxonomyManager.availableTerms[3] .isSelected, ); - await page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[1].terms[0].remove(); + await page.details.objectives.objectiveList.objectives[0].taxonomyManager.selectedTerms[0].terms[0].remove(); await page.details.objectives.objectiveList.objectives[0].taxonomyManager.availableTerms[3].toggle(); await page.details.objectives.objectiveList.objectives[0].selectedTerms.cancel(); assert.strictEqual( diff --git a/packages/ilios-common/addon/components/taxonomy-manager.gjs b/packages/ilios-common/addon/components/taxonomy-manager.gjs index ac8ff32926..c09af262ac 100644 --- a/packages/ilios-common/addon/components/taxonomy-manager.gjs +++ b/packages/ilios-common/addon/components/taxonomy-manager.gjs @@ -85,18 +85,8 @@ export default class TaxonomyManager extends Component { get listableVocabularies() { return this.nonEmptyVocabularies.filter((vocab) => { - if (vocab.active) { - return true; - } const terms = this.args.selectedTerms; - let hasTerms = false; - terms.forEach((term) => { - if (term.belongsTo('vocabulary').id() === vocab.id) { - hasTerms = true; - } - }); - - return hasTerms; + return terms.some((term) => term.belongsTo('vocabulary').id() === vocab.id); }); } diff --git a/packages/test-app/tests/integration/components/taxonomy-manager-test.gjs b/packages/test-app/tests/integration/components/taxonomy-manager-test.gjs index a335ae97bb..713fd8643f 100644 --- a/packages/test-app/tests/integration/components/taxonomy-manager-test.gjs +++ b/packages/test-app/tests/integration/components/taxonomy-manager-test.gjs @@ -61,6 +61,11 @@ module('Integration | Component | taxonomy manager', function (hooks) { title: 'Gamma', vocabulary: vocab2, }); + this.server.create('term', { + active: true, + title: 'Banana', + vocabulary: vocab3, + }); this.vocabModel1 = await this.owner.lookup('service:store').findRecord('vocabulary', vocab1.id); this.vocabModel2 = await this.owner.lookup('service:store').findRecord('vocabulary', vocab2.id); @@ -92,10 +97,12 @@ module('Integration | Component | taxonomy manager', function (hooks) { assert.strictEqual(component.selectedTerms[1].title, 'Bar (Medicine) (inactive)'); assert.strictEqual(component.selectedTerms[1].terms[0].name, 'Gamma'); - assert.strictEqual(component.vocabulary.options.length, 1); + assert.strictEqual(component.vocabulary.options.length, 2); assert.strictEqual(component.vocabulary.options[0].value, '1'); assert.strictEqual(component.vocabulary.options[0].text, 'Foo (Medicine)'); assert.ok(component.vocabulary.options[0].isSelected); + assert.strictEqual(component.vocabulary.options[1].value, '3'); + assert.strictEqual(component.vocabulary.options[1].text, 'Baz (Medicine)'); assert.strictEqual(component.availableTerms.length, 2); assert.strictEqual(component.availableTerms[0].name, 'Alpha'); @@ -247,7 +254,7 @@ module('Integration | Component | taxonomy manager', function (hooks) { , ); - assert.strictEqual(component.vocabulary.options.length, 2); + assert.strictEqual(component.vocabulary.options.length, 3); assert.notOk(component.vocabulary.options[0].isSelected); assert.ok(component.vocabulary.options[1].isSelected); assert.strictEqual(component.availableTerms.length, 1);