open-nomad/ui/app/components/fs-breadcrumbs.js
2019-08-07 15:29:14 -07:00

43 lines
966 B
JavaScript

import Component from '@ember/component';
import { computed } from '@ember/object';
import { isEmpty } from '@ember/utils';
export default Component.extend({
tagName: 'nav',
classNames: ['breadcrumb'],
'data-test-fs-breadcrumbs': true,
task: null,
path: null,
breadcrumbs: computed('path', function() {
const breadcrumbs = this.path
.split('/')
.reject(isEmpty)
.reduce((breadcrumbs, pathSegment, index) => {
let breadcrumbPath;
if (index > 0) {
const lastBreadcrumb = breadcrumbs[index - 1];
breadcrumbPath = `${lastBreadcrumb.path}/${pathSegment}`;
} else {
breadcrumbPath = pathSegment;
}
breadcrumbs.push({
name: pathSegment,
path: breadcrumbPath,
});
return breadcrumbs;
}, []);
if (breadcrumbs.length) {
breadcrumbs[breadcrumbs.length - 1].isLast = true;
}
return breadcrumbs;
}),
});