Use theme for the telemetry opt-in banner (#139911)

This commit is contained in:
Pierre Gayvallet 2022-09-05 10:45:55 +02:00 committed by GitHub
parent cd3931e0be
commit 7d767ede9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 4 deletions

View file

@ -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';
@ -75,6 +76,7 @@ export function mockTelemetryNotifications({
return new TelemetryNotifications({
http: httpServiceMock.createSetupContract(),
overlays: overlayServiceMock.createStartContract(),
theme: themeServiceMock.createStartContract(),
telemetryService,
telemetryConstants: mockTelemetryConstants(),
});

View file

@ -198,6 +198,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
analytics,
http,
overlays,
theme,
application,
savedObjects,
docLinks,
@ -213,6 +214,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
const telemetryNotifications = new TelemetryNotifications({
http,
overlays,
theme,
telemetryService: this.telemetryService,
telemetryConstants,
});

View file

@ -7,7 +7,7 @@
*/
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', () => {
@ -15,6 +15,7 @@ describe('renderOptedInNoticeBanner', () => {
const bannerID = 'brucer-wayne';
const overlays = overlayServiceMock.createStartContract();
const mockHttp = httpServiceMock.createStartContract();
const theme = themeServiceMock.createStartContract();
const telemetryConstants = mockTelemetryConstants();
overlays.banners.add.mockReturnValue(bannerID);
@ -22,6 +23,7 @@ describe('renderOptedInNoticeBanner', () => {
http: mockHttp,
onSeen: jest.fn(),
overlays,
theme,
telemetryConstants,
});

View file

@ -7,7 +7,7 @@
*/
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 '../..';
@ -15,13 +15,16 @@ 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(
@ -36,7 +39,8 @@ export function renderOptedInNoticeBanner({
onSeenBanner={onSeen}
http={http}
telemetryConstants={telemetryConstants}
/>
/>,
{ theme$: theme.theme$ }
);
const bannerId = overlays.banners.add(mount, 10000);

View file

@ -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';
@ -15,6 +15,7 @@ import { TelemetryConstants } from '../..';
interface TelemetryNotificationsConstructor {
http: HttpStart;
overlays: OverlayStart;
theme: ThemeServiceStart;
telemetryService: TelemetryService;
telemetryConstants: TelemetryConstants;
}
@ -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;
@ -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;
}
@ -59,6 +63,7 @@ export class TelemetryNotifications {
http: this.http,
onSeen: this.setOptedInNoticeSeen,
overlays: this.overlays,
theme: this.theme,
telemetryConstants: this.telemetryConstants,
});