Skip to content

Commit

Permalink
Revert "Cc 7145 hcp link status api (#20330)"
Browse files Browse the repository at this point in the history
This reverts commit 049ca10.
  • Loading branch information
chris-hut committed Mar 11, 2024
1 parent c8996cd commit 731f276
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
<Hds::Alert @type="page" @color="highlight" @onDismiss={{this.onDismiss}} class="link-to-hcp-banner"
data-test-link-to-hcp-banner as |A|>
<A.Title data-test-link-to-hcp-banner-title>{{t "components.link-to-hcp-banner.title"}}</A.Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions ui/packages/consul-ui/app/services/hcp-link-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
42 changes: 0 additions & 42 deletions ui/packages/consul-ui/app/services/repository/hcp-link.js

This file was deleted.

36 changes: 18 additions & 18 deletions ui/packages/consul-ui/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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')}}
<DataSource
@src={{uri '/*/*/*/notfound/${path}' (hash path=route.params.notfound)}}
Expand All @@ -75,11 +75,11 @@
''
)
(if (can 'use nspaces') (or route.params.nspace notfound.nspace token.Namespace '') '')
as |partition nspace|
as |partition nspace|
}}

{{! Make sure we have enough to show the app chrome}}
{{! Don't show anything until we have a list of DCs }}
{{! Make sure we have enough to show the app chrome}}
{{! Don't show anything until we have a list of DCs }}
<DataSource @src={{uri '/*/*/*/datacenters'}} as |dcs|>
{{! 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 }}
Expand All @@ -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 }}
<DataSource
@src={{uri
'/${partition}/*/${dc}/datacenter-cache/${name}'
(hash dc=dc.Name partition=partition name=dc.Name)
}}
'/${partition}/*/${dc}/datacenter-cache/${name}'
(hash dc=dc.Name partition=partition name=dc.Name)
}}
as |dc|
>
{{#if dc.data}}
<HashicorpConsul
<HashicorpConsul
id='wrapper'
@dcs={{dcs}}
@dc={{dc.data}}
Expand All @@ -115,10 +115,10 @@
>

{{#if error}}
{{! If we got an error from anything, show an error page }}
{{! If we got an error from anything, show an error page }}
<AppError @error={{error}} @login={{consul.login.open}} />
{{else}}
{{! Otherwise show the rest of the app}}
{{! Otherwise show the rest of the app}}
<Outlet
@name='application'
@model={{hash app=consul user=(hash token=token) dc=dc.data dcs=dcs}}
Expand All @@ -140,7 +140,7 @@
{{/let}}
{{/if}}
{{else}}
{{! Routes with no main navigation }}
{{! Routes with no main navigation }}
<Outlet @name='application' @model={{hash user=(hash token=token)}} as |o|>
{{outlet}}
</Outlet>
Expand Down
6 changes: 1 addition & 5 deletions ui/packages/consul-ui/app/templates/dc/services/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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|}}
<DataSource @src={{uri '/${partition}/*/${dc}/hcp-link' (hash dc=dc partition=partition name=dc) }} as |hcpLink|>
<LinkToHcpBanner @linkData={{hcpLink.data}}/>
</DataSource>
{{/let}}
<LinkToHcpBanner/>
<AppView>
<BlockSlot @name="header">
<h1>
Expand Down
16 changes: 0 additions & 16 deletions ui/packages/consul-ui/mock-api/api/hcp/v2/link/global

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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`<LinkToHcpBanner @linkData={{this.linkData}} />`);
await render(hbs`<LinkToHcpBanner />`);

assert.dom(bannerSelector).exists({ count: 1 });
await click(`${bannerSelector} button[aria-label="Dismiss"]`);
Expand All @@ -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`<LinkToHcpBanner @linkData={{this.linkData}} />`);
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`<LinkToHcpBanner @linkData={{this.linkData}} />`);
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`<LinkToHcpBanner @linkData={{this.linkData}} />`);
await render(hbs`<LinkToHcpBanner />`);
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`<LinkToHcpBanner @linkData={{this.linkData}} />`);
}
this.owner.register('service:env', EnvStub);
await render(hbs`<LinkToHcpBanner />`);
assert
.dom('[data-test-link-to-hcp-banner-description]')
.hasText(
Expand Down

0 comments on commit 731f276

Please sign in to comment.