Skip to content

Commit

Permalink
Use theme for the telemetry opt-in banner (elastic#139911)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet authored and Mpdreamz committed Sep 6, 2022
1 parent 7dac802 commit 3c162df
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/plugins/telemetry/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
overlayServiceMock,
httpServiceMock,
notificationServiceMock,
themeServiceMock,
} from '@kbn/core/public/mocks';
import { TelemetryService } from './services/telemetry_service';
import { TelemetryNotifications } from './services/telemetry_notifications/telemetry_notifications';
Expand Down Expand Up @@ -75,6 +76,7 @@ export function mockTelemetryNotifications({
return new TelemetryNotifications({
http: httpServiceMock.createSetupContract(),
overlays: overlayServiceMock.createStartContract(),
theme: themeServiceMock.createStartContract(),
telemetryService,
telemetryConstants: mockTelemetryConstants(),
});
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/telemetry/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
analytics,
http,
overlays,
theme,
application,
savedObjects,
docLinks,
Expand All @@ -213,6 +214,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
const telemetryNotifications = new TelemetryNotifications({
http,
overlays,
theme,
telemetryService: this.telemetryService,
telemetryConstants,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
*/

import { renderOptedInNoticeBanner } from './render_opted_in_notice_banner';
import { overlayServiceMock, httpServiceMock } from '@kbn/core/public/mocks';
import { overlayServiceMock, httpServiceMock, themeServiceMock } from '@kbn/core/public/mocks';
import { mockTelemetryConstants } from '../../mocks';

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

const returnedBannerId = renderOptedInNoticeBanner({
http: mockHttp,
onSeen: jest.fn(),
overlays,
theme,
telemetryConstants,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
*/

import React from 'react';
import type { HttpStart, OverlayStart } from '@kbn/core/public';
import type { HttpStart, OverlayStart, ThemeServiceStart } from '@kbn/core/public';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { withSuspense } from '@kbn/shared-ux-utility';
import type { TelemetryConstants } from '../..';

interface RenderBannerConfig {
http: HttpStart;
overlays: OverlayStart;
theme: ThemeServiceStart;
onSeen: () => void;
telemetryConstants: TelemetryConstants;
}

export function renderOptedInNoticeBanner({
onSeen,
overlays,
http,
theme,
telemetryConstants,
}: RenderBannerConfig) {
const OptedInNoticeBannerLazy = withSuspense(
Expand All @@ -36,7 +39,8 @@ export function renderOptedInNoticeBanner({
onSeenBanner={onSeen}
http={http}
telemetryConstants={telemetryConstants}
/>
/>,
{ theme$: theme.theme$ }
);
const bannerId = overlays.banners.add(mount, 10000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { HttpStart, OverlayStart } from '@kbn/core/public';
import { HttpStart, OverlayStart, ThemeServiceStart } from '@kbn/core/public';
import { renderOptedInNoticeBanner } from './render_opted_in_notice_banner';
import { renderOptInBanner } from './render_opt_in_banner';
import { TelemetryService } from '../telemetry_service';
Expand All @@ -15,6 +15,7 @@ import { TelemetryConstants } from '../..';
interface TelemetryNotificationsConstructor {
http: HttpStart;
overlays: OverlayStart;
theme: ThemeServiceStart;
telemetryService: TelemetryService;
telemetryConstants: TelemetryConstants;
}
Expand All @@ -25,6 +26,7 @@ interface TelemetryNotificationsConstructor {
export class TelemetryNotifications {
private readonly http: HttpStart;
private readonly overlays: OverlayStart;
private readonly theme: ThemeServiceStart;
private readonly telemetryConstants: TelemetryConstants;
private readonly telemetryService: TelemetryService;
private optedInNoticeBannerId?: string;
Expand All @@ -33,12 +35,14 @@ export class TelemetryNotifications {
constructor({
http,
overlays,
theme,
telemetryService,
telemetryConstants,
}: TelemetryNotificationsConstructor) {
this.telemetryService = telemetryService;
this.http = http;
this.overlays = overlays;
this.theme = theme;
this.telemetryConstants = telemetryConstants;
}

Expand All @@ -59,6 +63,7 @@ export class TelemetryNotifications {
http: this.http,
onSeen: this.setOptedInNoticeSeen,
overlays: this.overlays,
theme: this.theme,
telemetryConstants: this.telemetryConstants,
});

Expand Down

0 comments on commit 3c162df

Please sign in to comment.