From 26e74fe2e211a490210cf80b26a3bd197e5bcf0c Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Wed, 7 Aug 2019 15:29:14 -0700 Subject: [PATCH] Make a dedicated fs-breadcrumbs component --- ui/app/components/fs-breadcrumbs.js | 42 +++++++++++++++++++ .../allocations/allocation/task/fs.js | 30 ------------- .../allocations/allocation/task/fs.hbs | 34 +-------------- .../templates/components/fs-breadcrumbs.hbs | 14 +++++++ 4 files changed, 58 insertions(+), 62 deletions(-) create mode 100644 ui/app/components/fs-breadcrumbs.js create mode 100644 ui/app/templates/components/fs-breadcrumbs.hbs diff --git a/ui/app/components/fs-breadcrumbs.js b/ui/app/components/fs-breadcrumbs.js new file mode 100644 index 000000000..f613a0c49 --- /dev/null +++ b/ui/app/components/fs-breadcrumbs.js @@ -0,0 +1,42 @@ +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; + }), +}); diff --git a/ui/app/controllers/allocations/allocation/task/fs.js b/ui/app/controllers/allocations/allocation/task/fs.js index 9ad6df2c7..d901c53dd 100644 --- a/ui/app/controllers/allocations/allocation/task/fs.js +++ b/ui/app/controllers/allocations/allocation/task/fs.js @@ -1,7 +1,6 @@ import Controller from '@ember/controller'; import { computed } from '@ember/object'; import { filterBy } from '@ember/object/computed'; -import { isEmpty } from '@ember/utils'; export default Controller.extend({ queryParams: { @@ -42,33 +41,4 @@ export default Controller.extend({ } } ), - - 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; - }), }); diff --git a/ui/app/templates/allocations/allocation/task/fs.hbs b/ui/app/templates/allocations/allocation/task/fs.hbs index ec5507dfa..9d6ece792 100644 --- a/ui/app/templates/allocations/allocation/task/fs.hbs +++ b/ui/app/templates/allocations/allocation/task/fs.hbs @@ -3,42 +3,12 @@ {{#if task.isRunning}} {{#if isFile}} {{#task-file allocation=task.allocation task=task file=path stat=stat class="fs-explorer"}} - + {{fs-breadcrumbs task=task path=path}} {{/task-file}} {{else}}
- + {{fs-breadcrumbs task=task path=path}}
{{#list-table source=sortedDirectoryEntries diff --git a/ui/app/templates/components/fs-breadcrumbs.hbs b/ui/app/templates/components/fs-breadcrumbs.hbs new file mode 100644 index 000000000..97aba6398 --- /dev/null +++ b/ui/app/templates/components/fs-breadcrumbs.hbs @@ -0,0 +1,14 @@ + \ No newline at end of file