Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!this.node || this.node.isRoot) {
return [];
}
const parentId = this.node.belongsTo('parent').id();
const rootId = this.node.belongsTo('root').id();
// One ancestor
if (parentId === rootId) {
const parentNode = yield this.node.parent;
const { id, title }: {id: string, title: string } = parentNode;
return [{ id, title }];
}
// At least two ancestors
const results = yield allSettled([
this.node.root,
this.node.parent,
]);
const ancestors = results
.mapBy('value')
.compact()
.map(({ id, title }: { id: string, title: string }) => ({ id, title }));
// Results might have undefined `value` if ancestors are private
if (ancestors.length > 1) {
const parent = results[1].value;
if (parent && parent.belongsTo('parent').id() !== rootId) {
ancestors.insertAt(1, { id: '', title: this.i18n.t('general.ellipsis') });
}
}