2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2019-08-07 22:29:14 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { isEmpty } from '@ember/utils';
|
2022-03-08 17:28:36 +00:00
|
|
|
import {
|
|
|
|
classNames,
|
|
|
|
tagName,
|
|
|
|
attributeBindings,
|
|
|
|
} from '@ember-decorators/component';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2019-08-07 22:29:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('nav')
|
|
|
|
@classNames('breadcrumb')
|
2022-03-08 17:28:36 +00:00
|
|
|
@attributeBindings('data-test-fs-breadcrumbs')
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class Breadcrumbs extends Component {
|
|
|
|
'data-test-fs-breadcrumbs' = true;
|
2019-08-07 22:29:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
allocation = null;
|
|
|
|
taskState = null;
|
|
|
|
path = null;
|
2019-08-07 22:29:14 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('path')
|
|
|
|
get breadcrumbs() {
|
2019-08-07 22:29:14 +00:00
|
|
|
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;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|