Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cc 7146/convert consul hcp to a simpler component for some upcoming changes #20344

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"doc:toc": "doctoc README.md",
"compliance": "npm-run-all compliance:*",
"compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages '[email protected];[email protected];[email protected];[email protected];[email protected];consul-[email protected];consul-[email protected]'"
"compliance:licenses": "license-checker --summary --onlyAllow 'Python-2.0;Apache*;Apache License, Version 2.0;Apache-2.0;Apache 2.0;Artistic-2.0;BSD;BSD-3-Clause;CC-BY-3.0;CC-BY-4.0;CC0-1.0;ISC;MIT;MPL-2.0;Public Domain;Unicode-TOU;Unlicense;WTFPL' --excludePackages '[email protected];[email protected];[email protected];[email protected];[email protected];[email protected]'"

},
"devDependencies": {
Expand Down
15 changes: 0 additions & 15 deletions ui/packages/consul-hcp/app/components/consul/hcp/home/index.hbs

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions ui/packages/consul-hcp/package.json

This file was deleted.

14 changes: 0 additions & 14 deletions ui/packages/consul-hcp/vendor/consul-hcp/routes.js

This file was deleted.

14 changes: 0 additions & 14 deletions ui/packages/consul-hcp/vendor/consul-hcp/services.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
class='hds-side-nav-hide-when-minimized consul-side-nav__selector-group'
as |SNL|
>
<Consul::Hcp::Home @list={{SNL}} />
<HcpNavItem @list={{SNL}}/>
<Consul::Datacenter::Selector
@list={{SNL}}
@dc={{@dc}}
Expand Down
15 changes: 15 additions & 0 deletions ui/packages/consul-ui/app/components/hcp-nav-item/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
}}

{{#let @list (env "CONSUL_HCP_URL") as |SNL hcpUrl|}}
{{#if this.shouldShowBackToHcpItem}}
<SNL.BackLink
@text={{t "components.hashicorp-consul.side-nav.hcp"}}
@href={{hcpUrl}}
@isHrefExternal={{true}}
data-test-back-to-hcp
/>
{{/if}}
{{/let}}
21 changes: 21 additions & 0 deletions ui/packages/consul-ui/app/components/hcp-nav-item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import Component from '@glimmer/component';
chris-hut marked this conversation as resolved.
Show resolved Hide resolved
import { inject as service } from '@ember/service';

/**
* If the user has accessed consul from HCP managed consul, we do NOT want to display the
* "HCP Consul Central↗️" link in the nav bar. As we're already displaying a BackLink to HCP.
*/
export default class HcpLinkItemComponent extends Component {
@service env;

get shouldShowBackToHcpItem() {
const isConsulHcpUrlDefined = !!this.env.var('CONSUL_HCP_URL');
const isConsulHcpEnabled = !!this.env.var('CONSUL_HCP_ENABLED');
return isConsulHcpEnabled && isConsulHcpUrlDefined;
}
}
1 change: 0 additions & 1 deletion ui/packages/consul-ui/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ module.exports = function (defaults, $ = process.env) {
'consul-peerings',
'consul-partitions',
'consul-nspaces',
'consul-hcp',
].map((item) => {
return {
name: item,
Expand Down
8 changes: 0 additions & 8 deletions ui/packages/consul-ui/lib/startup/templates/body.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ ${
{{if .NamespacesEnabled}}
<script src="${rootURL}assets/consul-nspaces/routes.js"></script>
{{end}}
{{if .HCPEnabled}}
<script src="${rootURL}assets/consul-hcp/services.js"></script>
<script src="${rootURL}assets/consul-hcp/routes.js"></script>
{{end}}
`
: `
<script>
Expand Down Expand Up @@ -112,10 +108,6 @@ ${
name: 'consul-nspaces',
default: ${config.operatorConfig.NamespacesEnabled}
},
'CONSUL_HCP_ENABLE': {
name: 'consul-hcp',
default: ${config.operatorConfig.HCPEnabled}
},
}
);
</script>
Expand Down
1 change: 0 additions & 1 deletion ui/packages/consul-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"chalk": "^4.1.0",
"clipboard": "^2.0.11",
"consul-acls": "*",
"consul-hcp": "*",
"consul-lock-sessions": "*",
"consul-nspaces": "*",
"consul-partitions": "*",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { EnvStub } from 'consul-ui/services/env';

module('Integration | Component | hcp nav item', function (hooks) {
setupRenderingTest(hooks);

test('it prints the value of CONSUL_HCP_URL', async function (assert) {
this.owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = {
CONSUL_HCP_URL: 'http://hcp.com',
CONSUL_HCP_ENABLED: true,
};
}
);

await render(hbs`
<Hds::SideNav::List as |SNL|>
<HcpNavItem @list={{SNL}} />
</Hds::SideNav::List>
`);

assert.dom('[data-test-back-to-hcp]').isVisible();
assert.dom('a').hasAttribute('href', 'http://hcp.com');
});

test('it does not output the Back to HCP link if CONSUL_HCP_URL is not present', async function (assert) {
this.owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = {
CONSUL_HCP_ENABLED: true,
CONSUL_HCP_URL: undefined,
};
}
);

await render(hbs`
<Hds::SideNav::List as |SNL|>
<HcpNavItem @list={{SNL}} />
</Hds::SideNav::List>
`);

assert.dom('[data-test-back-to-hcp]').doesNotExist();
assert.dom('a').doesNotExist();
});
test('it does not output the Back to HCP link if CONSUL_HCP_ENABLED is not present', async function (assert) {
this.owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = {
CONSUL_HCP_URL: 'http://hcp.com',
CONSUL_HCP_ENABLED: undefined,
};
}
);

await render(hbs`
<Hds::SideNav::List as |SNL|>
<HcpNavItem @list={{SNL}} />
</Hds::SideNav::List>
`);

assert.dom('[data-test-back-to-hcp]').doesNotExist();
assert.dom('a').doesNotExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 dismissHcpLinkBannerStub = sinon.stub();
Expand All @@ -24,16 +25,16 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) {
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);
this.owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = {
isEnterprise: false,
};
}
);
});

test('it renders banner when hcp-link-status says it should', async function (assert) {
Expand Down Expand Up @@ -96,14 +97,16 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) {
});

test('it displays different banner text when consul is enterprise', async function (assert) {
class EnvStub extends Service {
isEnterprise = true;
var(key) {
return key;
this.owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = {
isEnterprise: true,
};
}
}
this.owner.register('service:env', EnvStub);
);
this.linkData = { isLinked: false };

await render(hbs`<LinkToHcpBanner @linkData={{this.linkData}} />`);
assert
.dom('[data-test-link-to-hcp-banner-description]')
Expand Down
Loading