From 2dd5ecf9888678c6f6ec8aa590eda512a2fd3fd5 Mon Sep 17 00:00:00 2001 From: Chris Hut Date: Wed, 24 Jan 2024 12:40:09 -0800 Subject: [PATCH 1/5] Convert consul-hcp to a simpler component --- ui/package.json | 2 +- .../app/components/consul/hcp/home/index.hbs | 15 ---- .../components/consul/hcp/home/index.test.js | 80 ------------------- ui/packages/consul-hcp/package.json | 5 -- .../consul-hcp/vendor/consul-hcp/routes.js | 14 ---- .../consul-hcp/vendor/consul-hcp/services.js | 14 ---- .../app/components/hashicorp-consul/index.hbs | 2 +- .../app/components/hcp-nav-item/index.hbs | 15 ++++ .../app/components/hcp-nav-item/index.js | 16 ++++ ui/packages/consul-ui/ember-cli-build.js | 1 - .../lib/startup/templates/body.html.js | 4 - ui/packages/consul-ui/package.json | 1 - .../components/hcp-nav-item-test.js | 76 ++++++++++++++++++ 13 files changed, 109 insertions(+), 136 deletions(-) delete mode 100644 ui/packages/consul-hcp/app/components/consul/hcp/home/index.hbs delete mode 100644 ui/packages/consul-hcp/app/components/consul/hcp/home/index.test.js delete mode 100644 ui/packages/consul-hcp/package.json delete mode 100644 ui/packages/consul-hcp/vendor/consul-hcp/routes.js delete mode 100644 ui/packages/consul-hcp/vendor/consul-hcp/services.js create mode 100644 ui/packages/consul-ui/app/components/hcp-nav-item/index.hbs create mode 100644 ui/packages/consul-ui/app/components/hcp-nav-item/index.js create mode 100644 ui/packages/consul-ui/tests/integration/components/hcp-nav-item-test.js diff --git a/ui/package.json b/ui/package.json index 7ed39b1595ac..ea0babf05008 100644 --- a/ui/package.json +++ b/ui/package.json @@ -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 'consul-ui@2.2.0;consul-acls@0.1.0;consul-lock-sessions@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0;consul-hcp@0.1.0;consul-peerings@0.1.0'" + "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 'consul-ui@2.2.0;consul-acls@0.1.0;consul-lock-sessions@0.1.0;consul-partitions@0.1.0;consul-nspaces@0.1.0;consul-peerings@0.1.0'" }, "devDependencies": { diff --git a/ui/packages/consul-hcp/app/components/consul/hcp/home/index.hbs b/ui/packages/consul-hcp/app/components/consul/hcp/home/index.hbs deleted file mode 100644 index 2e3b0f375c27..000000000000 --- a/ui/packages/consul-hcp/app/components/consul/hcp/home/index.hbs +++ /dev/null @@ -1,15 +0,0 @@ -{{! - Copyright (c) HashiCorp, Inc. - SPDX-License-Identifier: BUSL-1.1 -}} - -{{#let @list (env "CONSUL_HCP_URL") as |SNL hcpUrl|}} - {{#if (and SNL hcpUrl)}} - - {{/if}} -{{/let}} \ No newline at end of file diff --git a/ui/packages/consul-hcp/app/components/consul/hcp/home/index.test.js b/ui/packages/consul-hcp/app/components/consul/hcp/home/index.test.js deleted file mode 100644 index 0ffb7c48583f..000000000000 --- a/ui/packages/consul-hcp/app/components/consul/hcp/home/index.test.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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 ConsulHcpHome from 'consul-ui/components/consul/hcp/home'; - -module('Integration | Component | consul hcp home', function(hooks) { - setupRenderingTest(hooks); - - test('it prints the value of CONSUL_HCP_URL', async function(assert) { - // temporary registration until we are running as separate applications - this.owner.register( - 'component:consul/hcp/home', - ConsulHcpHome - ); - // - - const Helper = this.owner.resolveRegistration('helper:env'); - this.owner.register( - 'helper:env', - class extends Helper { - compute([name, def]) { - switch(name) { - case 'CONSUL_HCP_URL': - return 'http://hcp'; - } - return super.compute(...arguments); - } - } - ); - - await render(hbs` - - - - `); - - assert.dom('[data-test-back-to-hcp]').isVisible(); - assert.dom('a').hasAttribute('href', 'http://hcp'); - - }); - - test('it does not output the Back to HCP link if CONSUL_HCP_URL is not present', async function(assert) { - // temporary registration until we are running as separate applications - this.owner.register( - 'component:consul/hcp/home', - ConsulHcpHome - ); - // - - const Helper = this.owner.resolveRegistration('helper:env'); - this.owner.register( - 'helper:env', - class extends Helper { - compute([name, def]) { - switch(name) { - case 'CONSUL_HCP_URL': - return undefined; - } - return super.compute(...arguments); - } - } - ); - - await render(hbs` - - - - `); - - assert.dom('[data-test-back-to-hcp]').doesNotExist(); - assert.dom('a').doesNotExist(); - }); -}); diff --git a/ui/packages/consul-hcp/package.json b/ui/packages/consul-hcp/package.json deleted file mode 100644 index bb35cc6f6e11..000000000000 --- a/ui/packages/consul-hcp/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "consul-hcp", - "version": "0.1.0", - "private": true -} diff --git a/ui/packages/consul-hcp/vendor/consul-hcp/routes.js b/ui/packages/consul-hcp/vendor/consul-hcp/routes.js deleted file mode 100644 index ab573dea56ad..000000000000 --- a/ui/packages/consul-hcp/vendor/consul-hcp/routes.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -(routes => routes({ - dc: { - show: null - }, -}))( - (json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => { - data[`routes`] = JSON.stringify(json); - } -); diff --git a/ui/packages/consul-hcp/vendor/consul-hcp/services.js b/ui/packages/consul-hcp/vendor/consul-hcp/services.js deleted file mode 100644 index d1c7820f7da5..000000000000 --- a/ui/packages/consul-hcp/vendor/consul-hcp/services.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -(services => services({ - 'component:consul/hcp/home': { - class: 'consul-ui/components/consul/hcp/home', - }, -}))( - (json, data = (typeof document !== 'undefined' ? document.currentScript.dataset : module.exports)) => { - data[`services`] = JSON.stringify(json); - } -); diff --git a/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs b/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs index 58fc71920139..fc508b17c6b5 100644 --- a/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs +++ b/ui/packages/consul-ui/app/components/hashicorp-consul/index.hbs @@ -122,7 +122,7 @@ class='hds-side-nav-hide-when-minimized consul-side-nav__selector-group' as |SNL| > - + + {{/if}} +{{/let}} \ No newline at end of file diff --git a/ui/packages/consul-ui/app/components/hcp-nav-item/index.js b/ui/packages/consul-ui/app/components/hcp-nav-item/index.js new file mode 100644 index 000000000000..e53daede930e --- /dev/null +++ b/ui/packages/consul-ui/app/components/hcp-nav-item/index.js @@ -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; + } +} diff --git a/ui/packages/consul-ui/ember-cli-build.js b/ui/packages/consul-ui/ember-cli-build.js index c483cbf678aa..653c18df5f75 100644 --- a/ui/packages/consul-ui/ember-cli-build.js +++ b/ui/packages/consul-ui/ember-cli-build.js @@ -39,7 +39,6 @@ module.exports = function (defaults, $ = process.env) { 'consul-peerings', 'consul-partitions', 'consul-nspaces', - 'consul-hcp', ].map((item) => { return { name: item, diff --git a/ui/packages/consul-ui/lib/startup/templates/body.html.js b/ui/packages/consul-ui/lib/startup/templates/body.html.js index 93d25f96018b..0139ffbb8cc0 100644 --- a/ui/packages/consul-ui/lib/startup/templates/body.html.js +++ b/ui/packages/consul-ui/lib/startup/templates/body.html.js @@ -75,10 +75,6 @@ ${ {{if .NamespacesEnabled}} {{end}} -{{if .HCPEnabled}} - - -{{end}} ` : ` From 179349470da2a3848d35b5bac8ef280f022bf877 Mon Sep 17 00:00:00 2001 From: Chris Hut Date: Fri, 26 Jan 2024 16:29:50 -0800 Subject: [PATCH 5/5] remove this test that doesn't run anymore --- .../tests/integration/components/consul/hcp/home-test.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 ui/packages/consul-ui/tests/integration/components/consul/hcp/home-test.js diff --git a/ui/packages/consul-ui/tests/integration/components/consul/hcp/home-test.js b/ui/packages/consul-ui/tests/integration/components/consul/hcp/home-test.js deleted file mode 100644 index 99ac5e6e4a8d..000000000000 --- a/ui/packages/consul-ui/tests/integration/components/consul/hcp/home-test.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -// temporary import until we are running as separate applications -import 'consul-ui/components/consul/hcp/home/index.test';