From 92abbbacc1b795a2056951ee837404c6d15a7ccd Mon Sep 17 00:00:00 2001 From: Kenia <19161242+kaxcode@users.noreply.github.com> Date: Fri, 23 Oct 2020 09:45:10 -0400 Subject: [PATCH] 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 --- ui/packages/consul-ui/app/models/topology.js | 4 -- .../app/routes/dc/services/show/index.js | 36 +++++++++-------- .../app/templates/dc/services/show.hbs | 2 +- .../dc/services/show-topology.feature | 40 +++++++++++++++++++ .../steps/dc/services/show-topology-steps.js | 10 +++++ .../consul-ui/tests/pages/dc/services/show.js | 1 + 6 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 ui/packages/consul-ui/tests/acceptance/dc/services/show-topology.feature create mode 100644 ui/packages/consul-ui/tests/acceptance/steps/dc/services/show-topology-steps.js diff --git a/ui/packages/consul-ui/app/models/topology.js b/ui/packages/consul-ui/app/models/topology.js index 63c2d9e08b..5f8d3f3b08 100644 --- a/ui/packages/consul-ui/app/models/topology.js +++ b/ui/packages/consul-ui/app/models/topology.js @@ -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; - }), }); diff --git a/ui/packages/consul-ui/app/routes/dc/services/show/index.js b/ui/packages/consul-ui/app/routes/dc/services/show/index.js index 5b9171d8e7..6d1e6c381f 100644 --- a/ui/packages/consul-ui/app/routes/dc/services/show/index.js +++ b/ui/packages/consul-ui/app/routes/dc/services/show/index.js @@ -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); diff --git a/ui/packages/consul-ui/app/templates/dc/services/show.hbs b/ui/packages/consul-ui/app/templates/dc/services/show.hbs index e3c11aa323..0eb0aacb1f 100644 --- a/ui/packages/consul-ui/app/templates/dc/services/show.hbs +++ b/ui/packages/consul-ui/app/templates/dc/services/show.hbs @@ -29,7 +29,7 @@