Skip to content

Commit

Permalink
Convert consul-hcp to a simpler component
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hut committed Jan 25, 2024
1 parent 5119667 commit 2dd5ecf
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 136 deletions.
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}}
16 changes: 16 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,16 @@
import Component from '@glimmer/component';
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
4 changes: 0 additions & 4 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
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
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();
});
});

0 comments on commit 2dd5ecf

Please sign in to comment.