From 1c1df4530cdfaa72971d88eed1de946e1d5ceb35 Mon Sep 17 00:00:00 2001 From: David Yu Date: Fri, 26 Jan 2024 16:11:27 -0800 Subject: [PATCH 1/2] GHA: Update broken-link-check.yml to check once a month (#20368) Update broken-link-check.yml --- .github/workflows/broken-link-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/broken-link-check.yml b/.github/workflows/broken-link-check.yml index 2a8d77c588..d3dddccae7 100644 --- a/.github/workflows/broken-link-check.yml +++ b/.github/workflows/broken-link-check.yml @@ -6,7 +6,7 @@ name: Broken Link Check on: workflow_dispatch: schedule: - - cron: "0 0 * * 1" + - cron: "0 0 1 * *" jobs: linkChecker: @@ -30,4 +30,4 @@ jobs: with: title: Link Checker Report content-filepath: ./lychee/out.md - labels: report, automated issue \ No newline at end of file + labels: report, automated issue From 75af5b15d9e7b7b7754c7a96d4cf53dd9cf46a9b Mon Sep 17 00:00:00 2001 From: Chris Hut Date: Fri, 26 Jan 2024 16:39:50 -0800 Subject: [PATCH 2/2] Cc 7146/convert consul hcp to a simpler component for some upcoming changes (#20344) * Convert consul-hcp to a simpler component * update existing test to use envStub helper * Add missing copyright - weird no one yelled about this * remove consul-hcp from load * remove this test that doesn't run anymore --- 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 | 21 +++++ ui/packages/consul-ui/ember-cli-build.js | 1 - .../lib/startup/templates/body.html.js | 8 -- ui/packages/consul-ui/package.json | 1 - .../components/consul/hcp/home-test.js | 7 -- .../components/hcp-nav-item-test.js | 76 ++++++++++++++++++ .../components/link-to-hcp-banner-test.js | 31 +++---- 15 files changed, 131 insertions(+), 161 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 delete mode 100644 ui/packages/consul-ui/tests/integration/components/consul/hcp/home-test.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 7ed39b1595..ea0babf050 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 2e3b0f375c..0000000000 --- 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 0ffb7c4858..0000000000 --- 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 bb35cc6f6e..0000000000 --- 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 ab573dea56..0000000000 --- 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 d1c7820f7d..0000000000 --- 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 58fc719201..fc508b17c6 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 0000000000..487984511e --- /dev/null +++ b/ui/packages/consul-ui/app/components/hcp-nav-item/index.js @@ -0,0 +1,21 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +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 c483cbf678..653c18df5f 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 56b9b6d577..bf201960d2 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}} ` : ` diff --git a/ui/packages/consul-ui/package.json b/ui/packages/consul-ui/package.json index 3d5bb8441e..2218dc819f 100644 --- a/ui/packages/consul-ui/package.json +++ b/ui/packages/consul-ui/package.json @@ -91,7 +91,6 @@ "chalk": "^4.1.0", "clipboard": "^2.0.11", "consul-acls": "*", - "consul-hcp": "*", "consul-lock-sessions": "*", "consul-nspaces": "*", "consul-partitions": "*", 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 99ac5e6e4a..0000000000 --- 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'; diff --git a/ui/packages/consul-ui/tests/integration/components/hcp-nav-item-test.js b/ui/packages/consul-ui/tests/integration/components/hcp-nav-item-test.js new file mode 100644 index 0000000000..8fc7bfa975 --- /dev/null +++ b/ui/packages/consul-ui/tests/integration/components/hcp-nav-item-test.js @@ -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` + + + + `); + + 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` + + + + `); + + 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` + + + + `); + + assert.dom('[data-test-back-to-hcp]').doesNotExist(); + assert.dom('a').doesNotExist(); + }); +}); 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 54c7dd064e..8803cf6168 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,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(); @@ -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) { @@ -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``); assert .dom('[data-test-link-to-hcp-banner-description]')