Skip to content

Commit

Permalink
Fix for topics with no children
Browse files Browse the repository at this point in the history
  • Loading branch information
lindenmckenzie committed Sep 23, 2024
1 parent 760fab2 commit d558702
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ export class CantabularMetadataController extends Component {
try {
const extractTopicItems = ({ items }) => items;
let rootTopicsArr = await topics.getRootTopics().then(extractTopicItems);
const getSubtopics = ({ id }) => topics.getSubtopics(id).then(extractTopicItems);
const getSubtopics = ({ id, next: { subtopics_ids } }) => {
if (subtopics_ids.length > 0) {
return topics.getSubtopics(id).then(extractTopicItems);
}
return [];
};
let allSubtopics = await Promise.all(rootTopicsArr.map(getSubtopics)).then(subtopics => subtopics.flat());
const extractTopicOptions = ({ id, next: { title } }) => ({ value: id, label: title });
const rootTopics = {
Expand Down

0 comments on commit d558702

Please sign in to comment.