ui: Prevent redirect to topology url and hide Topology tab if service has no services (#9008)

* Prevent redirect to topology url and hide Topology tab if service has no proxies

* Remove unused computed function from topology model

* Fix up tests

* Remove use of Exists computed function

* Add tests for hiding topology tab
This commit is contained in:
Kenia 2020-10-23 09:45:10 -04:00 committed by GitHub
parent 05411303b4
commit 92abbbacc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 21 deletions

View File

@ -1,6 +1,5 @@
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { computed } from '@ember/object';
export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ServiceName';
@ -13,7 +12,4 @@ export default Model.extend({
Downstreams: attr(),
Protocol: attr(),
meta: attr(),
Exists: computed(function() {
return true;
}),
});

View File

@ -11,25 +11,29 @@ export default Route.extend({
// so check the length here.
let to = 'topology';
const parentModel = this.modelFor(parent);
const hasProxy = get(parentModel, 'proxies');
const kind = get(parentModel, 'items.firstObject.Service.Kind');
switch (kind) {
case 'ingress-gateway':
if (!get(parentModel, 'topology.Exists')) {
to = 'upstreams';
}
break;
case 'terminating-gateway':
to = 'services';
break;
case 'mesh-gateway':
to = 'instances';
break;
default:
if (!get(parentModel, 'topology.Exists')) {
if (hasProxy.length === 0) {
to = 'instances';
} else {
switch (kind) {
case 'ingress-gateway':
if (!get(parentModel, 'topology.Datacenter')) {
to = 'upstreams';
}
break;
case 'terminating-gateway':
to = 'services';
break;
case 'mesh-gateway':
to = 'instances';
}
break;
default:
if (!get(parentModel, 'topology.Datacenter')) {
to = 'instances';
}
}
}
this.replaceWith(`${parent}.${to}`, parentModel);

View File

@ -29,7 +29,7 @@
<TabNav @items={{
compact
(array
(if topology.Datacenter
(if (and topology.Datacenter (gt proxies.length 0))
(hash label="Topology" href=(href-to "dc.services.show.topology") selected=(is-href "dc.services.show.topology"))
'')
(if (eq item.Service.Kind 'terminating-gateway')

View File

@ -0,0 +1,40 @@
@setupApplicationTest
Feature: dc / services / show-topology: Show Topology tab for Service
Scenario: Given a service, the Topology tab should display
Given 1 datacenter model with the value "dc1"
And 1 node models
And 1 service model from yaml
---
- Service:
Name: service-0
ID: service-0-with-id
---
When I visit the service page for yaml
---
dc: dc1
service: service-0
---
And I see topology on the tabs
Then the url should be /dc1/services/service-0/topology
Scenario: Given connect is disabled, the Topology tab should not display or error
Given 1 datacenter model with the value "dc1"
And 1 node models
And 1 service model from yaml
---
- Service:
Name: service-0
ID: service-0-with-id
---
And the url "/v1/discovery-chain/service-0?dc=dc1&ns=@namespace" responds with from yaml
---
status: 500
body: "Connect must be enabled in order to use this endpoint"
---
When I visit the service page for yaml
---
dc: dc1
service: service-0
---
And I don't see topology on the tabs
Then the url should be /dc1/services/service-0/instances

View File

@ -0,0 +1,10 @@
import steps from '../../steps';
// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file
export default function(assert) {
return steps(assert).then('I should find a file', function() {
assert.ok(true, this.step);
});
}

View File

@ -8,6 +8,7 @@ export default function(visitable, attribute, collection, text, intentions, filt
href: attribute('href', '[data-test-dashboard-anchor]'),
},
tabs: tabs('tab', [
'topology',
'instances',
'linked-services',
'upstreams',