Skip to content

Commit

Permalink
[Security Solution] Fix 'disable usage data here.' link (#86452)
Browse files Browse the repository at this point in the history
* fix 'disable usage data here.' link

* update snapshot

* update link

* update mocks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
angorayc and kibanamachine authored Dec 18, 2020
1 parent 6a51741 commit fc7ae0e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/plugins/telemetry/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const LOCALSTORAGE_KEY = 'telemetry.data';
/**
* Link to Advanced Settings.
*/
export const PATH_TO_ADVANCED_SETTINGS = 'management/kibana/settings';
export const PATH_TO_ADVANCED_SETTINGS = '/app/management/kibana/settings';

/**
* Link to the Elastic Telemetry privacy statement.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ import React from 'react';
import { EuiButton } from '@elastic/eui';
import { shallowWithIntl } from '@kbn/test/jest';
import { OptedInNoticeBanner } from './opted_in_notice_banner';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { httpServiceMock } from '../../../../core/public/http/http_service.mock';

const mockHttp = httpServiceMock.createStartContract();

describe('OptInDetailsComponent', () => {
it('renders as expected', () => {
expect(shallowWithIntl(<OptedInNoticeBanner onSeenBanner={() => {}} />)).toMatchSnapshot();
expect(
shallowWithIntl(<OptedInNoticeBanner onSeenBanner={() => {}} http={mockHttp} />)
).toMatchSnapshot();
});

it('fires the "onSeenBanner" prop when a link is clicked', () => {
const onLinkClick = jest.fn();
const component = shallowWithIntl(<OptedInNoticeBanner onSeenBanner={onLinkClick} />);
const component = shallowWithIntl(
<OptedInNoticeBanner onSeenBanner={onLinkClick} http={mockHttp} />
);

const button = component.findWhere((n) => n.type() === EuiButton);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ import { EuiButton, EuiLink, EuiCallOut, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { PATH_TO_ADVANCED_SETTINGS, PRIVACY_STATEMENT_URL } from '../../common/constants';
import { HttpSetup } from '../../../../core/public';

interface Props {
http: HttpSetup;
onSeenBanner: () => any;
}

export class OptedInNoticeBanner extends React.PureComponent<Props> {
render() {
const { onSeenBanner } = this.props;
const { onSeenBanner, http } = this.props;
const basePath = http.basePath.get();

const bannerTitle = i18n.translate('telemetry.telemetryOptedInNoticeTitle', {
defaultMessage: 'Help us improve the Elastic Stack',
});
Expand All @@ -56,7 +60,7 @@ export class OptedInNoticeBanner extends React.PureComponent<Props> {
</EuiLink>
),
disableLink: (
<EuiLink href={PATH_TO_ADVANCED_SETTINGS} onClick={onSeenBanner}>
<EuiLink href={`${basePath}${PATH_TO_ADVANCED_SETTINGS}`} onClick={onSeenBanner}>
<FormattedMessage
id="telemetry.telemetryOptedInDisableUsage"
defaultMessage="disable usage data here"
Expand Down
1 change: 1 addition & 0 deletions src/plugins/telemetry/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function mockTelemetryNotifications({
telemetryService: TelemetryService;
}) {
return new TelemetryNotifications({
http: httpServiceMock.createSetupContract(),
overlays: overlayServiceMock.createStartContract(),
telemetryService,
});
Expand Down
1 change: 1 addition & 0 deletions src/plugins/telemetry/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
this.telemetryService.userCanChangeSettings = this.canUserChangeSettings;

this.telemetryNotifications = new TelemetryNotifications({
http,
overlays,
telemetryService: this.telemetryService,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
import { renderOptedInNoticeBanner } from './render_opted_in_notice_banner';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { overlayServiceMock } from '../../../../../core/public/overlays/overlay_service.mock';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { httpServiceMock } from '../../../../../core/public/http/http_service.mock';

describe('renderOptedInNoticeBanner', () => {
it('adds a banner to banners with priority of 10000', () => {
const bannerID = 'brucer-wayne';
const overlays = overlayServiceMock.createStartContract();
const mockHttp = httpServiceMock.createStartContract();
overlays.banners.add.mockReturnValue(bannerID);

const returnedBannerId = renderOptedInNoticeBanner({
http: mockHttp,
onSeen: jest.fn(),
overlays,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import { OptedInNoticeBanner } from '../../components/opted_in_notice_banner';
import { toMountPoint } from '../../../../kibana_react/public';

interface RenderBannerConfig {
http: CoreStart['http'];
overlays: CoreStart['overlays'];
onSeen: () => void;
}
export function renderOptedInNoticeBanner({ onSeen, overlays }: RenderBannerConfig) {
const mount = toMountPoint(<OptedInNoticeBanner onSeenBanner={onSeen} />);
export function renderOptedInNoticeBanner({ onSeen, overlays, http }: RenderBannerConfig) {
const mount = toMountPoint(<OptedInNoticeBanner onSeenBanner={onSeen} http={http} />);
const bannerId = overlays.banners.add(mount, 10000);

return bannerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ import { renderOptInBanner } from './render_opt_in_banner';
import { TelemetryService } from '../telemetry_service';

interface TelemetryNotificationsConstructor {
http: CoreStart['http'];
overlays: CoreStart['overlays'];
telemetryService: TelemetryService;
}

export class TelemetryNotifications {
private readonly http: CoreStart['http'];
private readonly overlays: CoreStart['overlays'];
private readonly telemetryService: TelemetryService;
private optedInNoticeBannerId?: string;
private optInBannerId?: string;

constructor({ overlays, telemetryService }: TelemetryNotificationsConstructor) {
constructor({ http, overlays, telemetryService }: TelemetryNotificationsConstructor) {
this.telemetryService = telemetryService;
this.http = http;
this.overlays = overlays;
}

Expand All @@ -46,6 +49,7 @@ export class TelemetryNotifications {

public renderOptedInNoticeBanner = (): void => {
const bannerId = renderOptedInNoticeBanner({
http: this.http,
onSeen: this.setOptedInNoticeSeen,
overlays: this.overlays,
});
Expand Down

0 comments on commit fc7ae0e

Please sign in to comment.