diff --git a/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.hbs b/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.hbs index 39dd933c9187..950c30c945f9 100644 --- a/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.hbs +++ b/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.hbs @@ -2,7 +2,7 @@ Copyright (c) HashiCorp, Inc. SPDX-License-Identifier: BUSL-1.1 }} -{{#if (and this.hcpLinkStatus.shouldDisplayBanner this.notLinked)}} +{{#if this.hcpLinkStatus.shouldDisplayBanner}} {{t "components.link-to-hcp-banner.title"}} diff --git a/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.js b/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.js index 9416cfbafbbe..3d0c96f2fa37 100644 --- a/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.js +++ b/ui/packages/consul-ui/app/components/link-to-hcp-banner/index.js @@ -11,10 +11,6 @@ export default class LinkToHcpBannerComponent extends Component { @service('hcp-link-status') hcpLinkStatus; @service('env') env; - get notLinked() { - return this.args.linkData?.isLinked === false; - } - @action onDismiss() { this.hcpLinkStatus.dismissHcpLinkBanner(); diff --git a/ui/packages/consul-ui/app/services/hcp-link-status.js b/ui/packages/consul-ui/app/services/hcp-link-status.js index cdde716ee4ea..4fec7f5babfc 100644 --- a/ui/packages/consul-ui/app/services/hcp-link-status.js +++ b/ui/packages/consul-ui/app/services/hcp-link-status.js @@ -3,19 +3,19 @@ * SPDX-License-Identifier: BUSL-1.1 */ -import Service, { inject as service } from '@ember/service'; +import Service from '@ember/service'; import { tracked } from '@glimmer/tracking'; const LOCAL_STORAGE_KEY = 'consul:hideHcpLinkBanner'; export default class HcpLinkStatus extends Service { - @service('env') env; + @tracked + alreadyLinked = false; @tracked userDismissedBanner = false; get shouldDisplayBanner() { - const hcpLinkEnabled = this.env.var('CONSUL_HCP_LINK_ENABLED'); - return !this.userDismissedBanner && hcpLinkEnabled; + return !this.alreadyLinked && !this.userDismissedBanner; } constructor() { diff --git a/ui/packages/consul-ui/app/services/repository/hcp-link.js b/ui/packages/consul-ui/app/services/repository/hcp-link.js deleted file mode 100644 index f82296cd0985..000000000000 --- a/ui/packages/consul-ui/app/services/repository/hcp-link.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -import RepositoryService from 'consul-ui/services/repository'; -import dataSource from 'consul-ui/decorators/data-source'; - -export default class HcpLinkService extends RepositoryService { - @dataSource('/:partition/:ns/:dc/hcp-link') - async fetch({ partition, ns, dc }, { uri }, request) { - let result; - try { - result = ( - await request` - GET /api/hcp/v2/link/global - ` - )((headers, body) => { - return { - meta: { - version: 2, - uri: uri, - }, - body: { - isLinked: (body.status['consul.io/hcp/link']['conditions'] || []).some( - (condition) => condition.type === 'linked' && condition.state === 'STATE_TRUE' - ), - }, - headers, - }; - }); - } catch (e) { - // set linked to false if the global link is not found - if (e.statusCode === 404) { - result = Promise.resolve({ isLinked: false }); - } else { - result = Promise.resolve(null); - } - } - return result; - } -} diff --git a/ui/packages/consul-ui/app/templates/application.hbs b/ui/packages/consul-ui/app/templates/application.hbs index b0c9054ce631..a999d9b562aa 100644 --- a/ui/packages/consul-ui/app/templates/application.hbs +++ b/ui/packages/consul-ui/app/templates/application.hbs @@ -48,18 +48,18 @@ (and (not (env 'CONSUL_V2_CATALOG_ENABLED')) (not-eq route.currentName 'oauth-provider-debug')) }} - {{! redirect if we aren't on a URL with dc information }} + {{! redirect if we aren't on a URL with dc information }} {{#if (eq route.currentName 'index')}} - {{! until we get to the dc route we don't know any permissions }} - {{! as we don't know the dc, any inital permission based }} - {{! redirects are in the dc.show route}} + {{! until we get to the dc route we don't know any permissions }} + {{! as we don't know the dc, any inital permission based }} + {{! redirects are in the dc.show route}} - {{! 2022-04-15: Temporarily reverting the services page to the default }} + {{! 2022-04-15: Temporarily reverting the services page to the default }} {{did-insert (route-action 'replaceWith' 'dc.services.index' (hash dc=(env 'CONSUL_DATACENTER_LOCAL'))) }} {{else}} - {{! If we are notfound, guess the params we need }} + {{! If we are notfound, guess the params we need }} {{#if (eq route.currentName 'notfound')}} {{! Once we have a list of DCs make sure the DC we are asking for exists }} {{! If not use the DC that the UI is running in }} @@ -90,20 +90,20 @@ (hash Name=(env 'CONSUL_DATACENTER_LOCAL')) ) dcs.data - as |dc dcs| + as |dc dcs| }} {{#if (and (gt dc.Name.length 0) dcs)}} - {{! figure out our current DC and convert it to a model }} + {{! figure out our current DC and convert it to a model }} {{#if dc.data}} - {{#if error}} - {{! If we got an error from anything, show an error page }} + {{! If we got an error from anything, show an error page }} {{else}} - {{! Otherwise show the rest of the app}} + {{! Otherwise show the rest of the app}} {{outlet}} diff --git a/ui/packages/consul-ui/app/templates/dc/services/index.hbs b/ui/packages/consul-ui/app/templates/dc/services/index.hbs index 0a7e2b97b1d4..7f33e16c6a57 100644 --- a/ui/packages/consul-ui/app/templates/dc/services/index.hbs +++ b/ui/packages/consul-ui/app/templates/dc/services/index.hbs @@ -62,11 +62,7 @@ as |route|> (or route.params.nspace route.model.user.token.Namespace 'default') as |sort filters items partition nspace|}} -{{#let route.params.dc as |dc|}} - - - -{{/let}} +

diff --git a/ui/packages/consul-ui/mock-api/api/hcp/v2/link/global b/ui/packages/consul-ui/mock-api/api/hcp/v2/link/global deleted file mode 100644 index 873f854c202d..000000000000 --- a/ui/packages/consul-ui/mock-api/api/hcp/v2/link/global +++ /dev/null @@ -1,16 +0,0 @@ -{ - "status": { - "consul.io/hcp/link": { - "conditions": [ - { - "message": "Successfully linked to cluster 'organization/f53e5646-6529-4698-ae29-d74f8bd22a01/project/6994bb7a-5561-4d5c-8bb0-cf40177e5b77/hashicorp.consul.global-network-manager.cluster/mkam-vm'", - "reason": "SUCCESS", - "state": "STATE_FALSE", - "type": "linked" - } - ], - "observedGeneration":"01HMA2VPHVKNF6QR8TD07KDN5K", - "updatedAt":"2024-01-16T21:29:25.923140Z" - } - } -} \ No newline at end of file diff --git a/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js b/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js index ac375fb451cf..d20646bf34ba 100644 --- a/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js +++ b/ui/packages/consul-ui/tests/integration/components/link-to-hcp-banner-test.js @@ -9,9 +9,9 @@ import { click, render } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; import Service from '@ember/service'; import sinon from 'sinon'; -import { EnvStub } from 'consul-ui/services/env'; const userDismissedBannerStub = sinon.stub(); +const userHasLinkedStub = sinon.stub(); const dismissHcpLinkBannerStub = sinon.stub(); const bannerSelector = '[data-test-link-to-hcp-banner]'; module('Integration | Component | link-to-hcp-banner', function (hooks) { @@ -22,16 +22,24 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) { return true; } userDismissedBanner = userDismissedBannerStub; + userHasLinked = userHasLinkedStub; dismissHcpLinkBanner = dismissHcpLinkBannerStub; } + class EnvStub extends Service { + isEnterprise = false; + var(key) { + return key; + } + } + hooks.beforeEach(function () { this.owner.register('service:hcp-link-status', HcpLinkStatusStub); + this.owner.register('service:env', EnvStub); }); test('it renders banner when hcp-link-status says it should', async function (assert) { - this.linkData = { isLinked: false }; - await render(hbs``); + await render(hbs``); assert.dom(bannerSelector).exists({ count: 1 }); await click(`${bannerSelector} button[aria-label="Dismiss"]`); @@ -54,51 +62,24 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) { get shouldDisplayBanner() { return false; } + userDismissedBanner = sinon.stub(); + userHasLinked = sinon.stub(); dismissHcpLinkBanner = sinon.stub(); } this.owner.register('service:hcp-link-status', HcpLinkStatusStub); - this.linkData = { isLinked: false }; - await render(hbs``); - assert.dom(bannerSelector).doesNotExist(); - }); - - test('banner does not render when cluster is already linked', async function (assert) { - class HcpLinkStatusStub extends Service { - get shouldDisplayBanner() { - return true; - } - dismissHcpLinkBanner = sinon.stub(); - } - this.owner.register('service:hcp-link-status', HcpLinkStatusStub); - this.linkData = { isLinked: true }; - await render(hbs``); - assert.dom(bannerSelector).doesNotExist(); - }); - - test('banner does not render when we have no cluster link status info', async function (assert) { - class HcpLinkStatusStub extends Service { - get shouldDisplayBanner() { - return true; - } - dismissHcpLinkBanner = sinon.stub(); - } - this.owner.register('service:hcp-link-status', HcpLinkStatusStub); - this.linkData = undefined; - await render(hbs``); + await render(hbs``); assert.dom(bannerSelector).doesNotExist(); }); test('it displays different banner text when consul is enterprise', async function (assert) { - this.owner.register( - 'service:env', - class Stub extends EnvStub { - stubEnv = {}; - isEnterprise = true; + class EnvStub extends Service { + isEnterprise = true; + var(key) { + return key; } - ); - this.linkData = { isLinked: false }; - - await render(hbs``); + } + this.owner.register('service:env', EnvStub); + await render(hbs``); assert .dom('[data-test-link-to-hcp-banner-description]') .hasText(