Skip to content

Commit c82ee2a

Browse files
[Security Solution] Fix 'disable usage data here.' link (#86452) (#86495)
* fix 'disable usage data here.' link * update snapshot * update link * update mocks Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 46dceb9 commit c82ee2a

File tree

9 files changed

+32
-9
lines changed

9 files changed

+32
-9
lines changed

src/plugins/telemetry/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const LOCALSTORAGE_KEY = 'telemetry.data';
4949
/**
5050
* Link to Advanced Settings.
5151
*/
52-
export const PATH_TO_ADVANCED_SETTINGS = 'management/kibana/settings';
52+
export const PATH_TO_ADVANCED_SETTINGS = '/app/management/kibana/settings';
5353

5454
/**
5555
* Link to the Elastic Telemetry privacy statement.

src/plugins/telemetry/public/components/__snapshots__/opted_in_notice_banner.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/telemetry/public/components/opted_in_notice_banner.test.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,23 @@ import React from 'react';
2020
import { EuiButton } from '@elastic/eui';
2121
import { shallowWithIntl } from '@kbn/test/jest';
2222
import { OptedInNoticeBanner } from './opted_in_notice_banner';
23+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
24+
import { httpServiceMock } from '../../../../core/public/http/http_service.mock';
25+
26+
const mockHttp = httpServiceMock.createStartContract();
2327

2428
describe('OptInDetailsComponent', () => {
2529
it('renders as expected', () => {
26-
expect(shallowWithIntl(<OptedInNoticeBanner onSeenBanner={() => {}} />)).toMatchSnapshot();
30+
expect(
31+
shallowWithIntl(<OptedInNoticeBanner onSeenBanner={() => {}} http={mockHttp} />)
32+
).toMatchSnapshot();
2733
});
2834

2935
it('fires the "onSeenBanner" prop when a link is clicked', () => {
3036
const onLinkClick = jest.fn();
31-
const component = shallowWithIntl(<OptedInNoticeBanner onSeenBanner={onLinkClick} />);
37+
const component = shallowWithIntl(
38+
<OptedInNoticeBanner onSeenBanner={onLinkClick} http={mockHttp} />
39+
);
3240

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

src/plugins/telemetry/public/components/opted_in_notice_banner.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ import { EuiButton, EuiLink, EuiCallOut, EuiSpacer } from '@elastic/eui';
2424
import { FormattedMessage } from '@kbn/i18n/react';
2525
import { i18n } from '@kbn/i18n';
2626
import { PATH_TO_ADVANCED_SETTINGS, PRIVACY_STATEMENT_URL } from '../../common/constants';
27+
import { HttpSetup } from '../../../../core/public';
2728

2829
interface Props {
30+
http: HttpSetup;
2931
onSeenBanner: () => any;
3032
}
3133

3234
export class OptedInNoticeBanner extends React.PureComponent<Props> {
3335
render() {
34-
const { onSeenBanner } = this.props;
36+
const { onSeenBanner, http } = this.props;
37+
const basePath = http.basePath.get();
38+
3539
const bannerTitle = i18n.translate('telemetry.telemetryOptedInNoticeTitle', {
3640
defaultMessage: 'Help us improve the Elastic Stack',
3741
});
@@ -56,7 +60,7 @@ export class OptedInNoticeBanner extends React.PureComponent<Props> {
5660
</EuiLink>
5761
),
5862
disableLink: (
59-
<EuiLink href={PATH_TO_ADVANCED_SETTINGS} onClick={onSeenBanner}>
63+
<EuiLink href={`${basePath}${PATH_TO_ADVANCED_SETTINGS}`} onClick={onSeenBanner}>
6064
<FormattedMessage
6165
id="telemetry.telemetryOptedInDisableUsage"
6266
defaultMessage="disable usage data here"

src/plugins/telemetry/public/mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function mockTelemetryNotifications({
7676
telemetryService: TelemetryService;
7777
}) {
7878
return new TelemetryNotifications({
79+
http: httpServiceMock.createSetupContract(),
7980
overlays: overlayServiceMock.createStartContract(),
8081
telemetryService,
8182
});

src/plugins/telemetry/public/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
104104
this.telemetryService.userCanChangeSettings = this.canUserChangeSettings;
105105

106106
this.telemetryNotifications = new TelemetryNotifications({
107+
http,
107108
overlays,
108109
telemetryService: this.telemetryService,
109110
});

src/plugins/telemetry/public/services/telemetry_notifications/render_opted_in_notice_banner.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@
2020
import { renderOptedInNoticeBanner } from './render_opted_in_notice_banner';
2121
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2222
import { overlayServiceMock } from '../../../../../core/public/overlays/overlay_service.mock';
23+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
24+
import { httpServiceMock } from '../../../../../core/public/http/http_service.mock';
2325

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

3033
const returnedBannerId = renderOptedInNoticeBanner({
34+
http: mockHttp,
3135
onSeen: jest.fn(),
3236
overlays,
3337
});

src/plugins/telemetry/public/services/telemetry_notifications/render_opted_in_notice_banner.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import { OptedInNoticeBanner } from '../../components/opted_in_notice_banner';
2323
import { toMountPoint } from '../../../../kibana_react/public';
2424

2525
interface RenderBannerConfig {
26+
http: CoreStart['http'];
2627
overlays: CoreStart['overlays'];
2728
onSeen: () => void;
2829
}
29-
export function renderOptedInNoticeBanner({ onSeen, overlays }: RenderBannerConfig) {
30-
const mount = toMountPoint(<OptedInNoticeBanner onSeenBanner={onSeen} />);
30+
export function renderOptedInNoticeBanner({ onSeen, overlays, http }: RenderBannerConfig) {
31+
const mount = toMountPoint(<OptedInNoticeBanner onSeenBanner={onSeen} http={http} />);
3132
const bannerId = overlays.banners.add(mount, 10000);
3233

3334
return bannerId;

src/plugins/telemetry/public/services/telemetry_notifications/telemetry_notifications.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ import { renderOptInBanner } from './render_opt_in_banner';
2323
import { TelemetryService } from '../telemetry_service';
2424

2525
interface TelemetryNotificationsConstructor {
26+
http: CoreStart['http'];
2627
overlays: CoreStart['overlays'];
2728
telemetryService: TelemetryService;
2829
}
2930

3031
export class TelemetryNotifications {
32+
private readonly http: CoreStart['http'];
3133
private readonly overlays: CoreStart['overlays'];
3234
private readonly telemetryService: TelemetryService;
3335
private optedInNoticeBannerId?: string;
3436
private optInBannerId?: string;
3537

36-
constructor({ overlays, telemetryService }: TelemetryNotificationsConstructor) {
38+
constructor({ http, overlays, telemetryService }: TelemetryNotificationsConstructor) {
3739
this.telemetryService = telemetryService;
40+
this.http = http;
3841
this.overlays = overlays;
3942
}
4043

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

4750
public renderOptedInNoticeBanner = (): void => {
4851
const bannerId = renderOptedInNoticeBanner({
52+
http: this.http,
4953
onSeen: this.setOptedInNoticeSeen,
5054
overlays: this.overlays,
5155
});

0 commit comments

Comments
 (0)