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

Hide the hcp link banner behind an env variable #20392

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ui/packages/consul-ui/app/services/hcp-link-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
* SPDX-License-Identifier: BUSL-1.1
*/

import Service from '@ember/service';
import Service, { inject as 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
userDismissedBanner = false;

get shouldDisplayBanner() {
return !this.userDismissedBanner;
const hcpLinkEnabled = this.env.var('CONSUL_HCP_LINK_ENABLED');
return !this.userDismissedBanner && hcpLinkEnabled;
}

constructor() {
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/app/utils/get-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default function (config = {}, win = window, doc = document) {
case 'CONSUL_API_PREFIX':
// we want API prefix to look like an env var for if we ever change
// operator config to be an API request, we need this variable before we
// make and API request so this specific variable should never be be
// make and API request so this specific variable should never be
// retrived via an API request
return operatorConfig.APIPrefix;
case 'CONSUL_HCP_URL':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { module, test } from 'qunit';
import { click, visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { EnvStub } from 'consul-ui/services/env';

const bannerSelector = '[data-test-link-to-hcp-banner]';
module('Acceptance | link to hcp banner', function (hooks) {
Expand All @@ -14,9 +15,14 @@ module('Acceptance | link to hcp banner', function (hooks) {
hooks.beforeEach(function () {
// clear local storage so we don't have any settings
window.localStorage.clear();
// setupTestEnv(this.owner, {
// CONSUL_ACLS_ENABLED: true,
// });
this.owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = {
CONSUL_HCP_LINK_ENABLED: true,
};
}
);
});

test('the banner is initially displayed on services page', async function (assert) {
Expand All @@ -32,4 +38,17 @@ module('Acceptance | link to hcp banner', function (hooks) {
await visit('/');
assert.dom(bannerSelector).doesNotExist('Banner is still gone after refresh');
});

test('the banner is not displayed if the env var is not set', async function (assert) {
this.owner.register(
'service:env',
class Stub extends EnvStub {
stubEnv = {};
}
);
// default route is services page so we're good here
await visit('/');
// Expect the banner to be visible by default
assert.dom(bannerSelector).doesNotExist('Banner is not here');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module('Integration | Component | link-to-hcp-banner', function (hooks) {
'service:env',
class Stub extends EnvStub {
stubEnv = {
isEnterprise: false,
CONSUL_HCP_LINK_ENABLED: true,
};
}
);
Expand Down
Loading