github.com/hernad/nomad@v1.6.112/ui/app/components/fs/breadcrumbs.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Component from '@ember/component';
     7  import { computed } from '@ember/object';
     8  import { isEmpty } from '@ember/utils';
     9  import {
    10    classNames,
    11    tagName,
    12    attributeBindings,
    13  } from '@ember-decorators/component';
    14  import classic from 'ember-classic-decorator';
    15  
    16  @classic
    17  @tagName('nav')
    18  @classNames('breadcrumb')
    19  @attributeBindings('data-test-fs-breadcrumbs')
    20  export default class Breadcrumbs extends Component {
    21    'data-test-fs-breadcrumbs' = true;
    22  
    23    allocation = null;
    24    taskState = null;
    25    path = null;
    26  
    27    @computed('path')
    28    get breadcrumbs() {
    29      const breadcrumbs = this.path
    30        .split('/')
    31        .reject(isEmpty)
    32        .reduce((breadcrumbs, pathSegment, index) => {
    33          let breadcrumbPath;
    34  
    35          if (index > 0) {
    36            const lastBreadcrumb = breadcrumbs[index - 1];
    37            breadcrumbPath = `${lastBreadcrumb.path}/${pathSegment}`;
    38          } else {
    39            breadcrumbPath = pathSegment;
    40          }
    41  
    42          breadcrumbs.push({
    43            name: pathSegment,
    44            path: breadcrumbPath,
    45          });
    46  
    47          return breadcrumbs;
    48        }, []);
    49  
    50      if (breadcrumbs.length) {
    51        breadcrumbs[breadcrumbs.length - 1].isLast = true;
    52      }
    53  
    54      return breadcrumbs;
    55    }
    56  }