mirror of https://github.com/hashicorp/consul
Browse Source
We need a component abstraction that encapsulates creating the dynamic tabs based on peering-type. We create a `PeerTab`-abstraction that behaves like the data-structure the tab-nav expects to achieve this effect.pull/14947/head
Michael Klein
2 years ago
2 changed files with 64 additions and 0 deletions
@ -0,0 +1 @@
|
||||
{{yield (hash data=this.data)}} |
@ -0,0 +1,63 @@
|
||||
import Component from '@glimmer/component'; |
||||
import { tracked } from '@glimmer/tracking'; |
||||
import { hrefTo } from 'consul-ui/helpers/href-to'; |
||||
import { inject as service } from '@ember/service'; |
||||
import { getOwner } from '@ember/application'; |
||||
|
||||
class PeerTab { |
||||
@tracked route; |
||||
@tracked label; |
||||
@tracked currentRouteName; |
||||
|
||||
constructor(opts) { |
||||
const { currentRouteName, route, label, owner } = opts; |
||||
|
||||
this.currentRouteName = currentRouteName; |
||||
this.owner = owner; |
||||
this.route = route; |
||||
this.label = label; |
||||
} |
||||
|
||||
get selected() { |
||||
return this.currentRouteName === this.route; |
||||
} |
||||
|
||||
get href() { |
||||
return hrefTo(this.owner, [this.route]); |
||||
} |
||||
} |
||||
|
||||
export default class PeeringsProvider extends Component { |
||||
@service router; |
||||
|
||||
get data() { |
||||
return { |
||||
tabs: this.tabs, |
||||
}; |
||||
} |
||||
|
||||
get tabs() { |
||||
const { peer } = this.args; |
||||
const { router } = this; |
||||
const owner = getOwner(this); |
||||
|
||||
let tabs; |
||||
if (peer.isDialer) { |
||||
tabs = [ |
||||
{ |
||||
label: 'Exported Services', |
||||
route: 'dc.peers.edit.exported', |
||||
}, |
||||
]; |
||||
} else { |
||||
tabs = [ |
||||
{ label: 'Imported Services', route: 'dc.peers.edit.imported' }, |
||||
{ label: 'Addresses', route: 'dc.peers.edit.addresses' }, |
||||
]; |
||||
} |
||||
|
||||
return tabs.map( |
||||
(tab) => new PeerTab({ ...tab, currentRouteName: router.currentRouteName, owner }) |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue