Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for vocabulary selection, filter out vocabularies where all top-level terms are inactive. #8430

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
for vocabulary selection, filter out vocabularies where all top-level…
… terms are inactive.
stopfstedt committed Mar 12, 2025
commit d556cf9abc905885b9374cd2eae986d1ef8302f6
17 changes: 16 additions & 1 deletion packages/ilios-common/addon/components/taxonomy-manager.js
Original file line number Diff line number Diff line change
@@ -55,8 +55,23 @@ export default class TaxonomyManager extends Component {
}
}

@cached
get assignableVocabulariesData() {
return new TrackedAsyncData(this.getAssignableVocabularies(this.nonEmptyVocabularies));
}

get assignableVocabularies() {
return this.nonEmptyVocabularies.filter((vocab) => vocab.active);
return this.assignableVocabulariesData.isResolved ? this.assignableVocabulariesData.value : [];
}

async getAssignableVocabularies(vocabularies) {
// Filter out inactive vocabularies.
const activeVocabularies = vocabularies.filter((vocab) => vocab.active);
// Filter out vocabularies where all top-level terms are inactive.
return filter(activeVocabularies, async (vocabulary) => {
const topLevelTerms = await vocabulary.getTopLevelTerms();
return !topLevelTerms.every((term) => !term.active);
});
}

get listableVocabularies() {
Original file line number Diff line number Diff line change
@@ -229,4 +229,19 @@ module('Integration | Component | taxonomy manager', function (hooks) {
assert.strictEqual(component.availableTerms.length, 1);
assert.strictEqual(component.availableTerms[0].name, 'Gamma');
});

test('vocabulary without active top-level terms is not assignable', async function (assert) {
// deactivate all top-level terms in vocabulary 1
this.termModel1.set('active', false);
this.termModel2.set('active', false);

this.set('assignableVocabularies', [this.vocabModel1]);
await render(hbs`<TaxonomyManager
@vocabularies={{this.assignableVocabularies}}
@selectedTerms={{(array)}}
@add={{(noop)}}
@remove={{(noop)}}
/>`);
assert.strictEqual(component.vocabulary.options.length, 0);
});
});