open-nomad/ui/app/components/fs/breadcrumbs.js
Buck Doyle 89136cbf6a Add massaged results of class codemod
Manual interventions:
• decorators on the same line for service and controller
  injections and most computed property macros
• preserving import order when possible, both per-line
  and intra-line
• moving new imports to the bottom
• removal of classic decorator for trivial cases
• conversion of init to constructor when appropriate
2020-06-10 16:18:42 -05:00

47 lines
1.1 KiB
JavaScript

import Component from '@ember/component';
import { computed } from '@ember/object';
import { isEmpty } from '@ember/utils';
import { classNames, tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
@classic
@tagName('nav')
@classNames('breadcrumb')
export default class Breadcrumbs extends Component {
'data-test-fs-breadcrumbs' = true;
allocation = null;
taskState = null;
path = null;
@computed('path')
get breadcrumbs() {
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;
}
}