[License Management] Do not break when telemetry.enabled:false (#69711)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Alejandro Fernández Haro 2020-06-26 13:57:17 +01:00 committed by GitHub
parent 09e3f75bc3
commit ae7e9d9ad5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 28 deletions

View file

@ -9,7 +9,7 @@ import { ScopedHistory } from 'kibana/public';
import { CoreStart } from '../../../../../src/core/public';
import { LicensingPluginSetup, ILicense } from '../../../licensing/public';
import { TelemetryPluginSetup } from '../../../../../src/plugins/telemetry/public';
import { TelemetryPluginStart } from '../../../../../src/plugins/telemetry/public';
import { ClientConfigType } from '../types';
import { BreadcrumbService } from './breadcrumbs';
@ -23,7 +23,7 @@ export interface AppDependencies {
};
plugins: {
licensing: LicensingPluginSetup;
telemetry?: TelemetryPluginSetup;
telemetry?: TelemetryPluginStart;
};
docLinks: {
security: string;

View file

@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { OptInExampleFlyout } from '../../../../../../../src/plugins/telemetry_management_section/public';
// required for lazy loading
// eslint-disable-next-line import/no-default-export
export default OptInExampleFlyout;

View file

@ -5,13 +5,19 @@
*/
import React, { Fragment } from 'react';
import { EuiLink, EuiCheckbox, EuiSpacer, EuiText, EuiTitle, EuiPopover } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import {
OptInExampleFlyout,
PRIVACY_STATEMENT_URL,
TelemetryPluginSetup,
} from '../../lib/telemetry';
EuiLink,
EuiCheckbox,
EuiSpacer,
EuiText,
EuiTitle,
EuiPopover,
EuiLoadingSpinner,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { TelemetryPluginStart } from '../../lib/telemetry';
const OptInExampleFlyout = React.lazy(() => import('./opt_in_example_flyout'));
interface State {
showMoreTelemetryInfo: boolean;
@ -22,7 +28,7 @@ interface Props {
onOptInChange: (isOptingInToTelemetry: boolean) => void;
isOptingInToTelemetry: boolean;
isStartTrial: boolean;
telemetry: TelemetryPluginSetup;
telemetry: TelemetryPluginStart;
}
export class TelemetryOptIn extends React.Component<Props, State> {
@ -54,11 +60,15 @@ export class TelemetryOptIn extends React.Component<Props, State> {
let example = null;
if (showExample) {
// Using React.Suspense and lazy loading here to avoid crashing the plugin when importing
// OptInExampleFlyout but telemetryManagementSection is disabled
example = (
<OptInExampleFlyout
onClose={() => this.setState({ showExample: false })}
fetchExample={telemetry.telemetryService.fetchExample}
/>
<React.Suspense fallback={<EuiLoadingSpinner />}>
<OptInExampleFlyout
onClose={() => this.setState({ showExample: false })}
fetchExample={telemetry.telemetryService.fetchExample}
/>
</React.Suspense>
);
}
@ -116,7 +126,10 @@ export class TelemetryOptIn extends React.Component<Props, State> {
</EuiLink>
),
telemetryPrivacyStatementLink: (
<EuiLink href={PRIVACY_STATEMENT_URL} target="_blank">
<EuiLink
href={telemetry.telemetryConstants.getPrivacyStatementUrl()}
target="_blank"
>
<FormattedMessage
id="xpack.licenseMgmt.telemetryOptIn.telemetryPrivacyStatementLinkText"
defaultMessage="telemetry privacy statement"

View file

@ -4,15 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { TelemetryPluginSetup } from '../../../../../../src/plugins/telemetry/public';
import type { TelemetryPluginStart } from '../../../../../../src/plugins/telemetry/public';
export { OptInExampleFlyout } from '../../../../../../src/plugins/telemetry_management_section/public/';
export { PRIVACY_STATEMENT_URL } from '../../../../../../src/plugins/telemetry/common/constants';
export { TelemetryPluginSetup, shouldShowTelemetryOptIn };
export type { TelemetryPluginStart } from '../../../../../../src/plugins/telemetry/public';
export { shouldShowTelemetryOptIn };
function shouldShowTelemetryOptIn(
telemetry?: TelemetryPluginSetup
): telemetry is TelemetryPluginSetup {
telemetry?: TelemetryPluginStart
): telemetry is TelemetryPluginStart {
if (telemetry) {
const { telemetryService } = telemetry;
const isOptedIn = telemetryService.getIsOptedIn();

View file

@ -26,12 +26,12 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { TelemetryOptIn } from '../../../components/telemetry_opt_in';
import { EXTERNAL_LINKS } from '../../../../../common/constants';
import { AppContextConsumer, AppDependencies } from '../../../app_context';
import { TelemetryPluginSetup, shouldShowTelemetryOptIn } from '../../../lib/telemetry';
import { TelemetryPluginStart, shouldShowTelemetryOptIn } from '../../../lib/telemetry';
interface Props {
loadTrialStatus: () => void;
startLicenseTrial: () => void;
telemetry?: TelemetryPluginSetup;
telemetry?: TelemetryPluginStart;
shouldShowStartTrial: boolean;
}

View file

@ -6,7 +6,7 @@
import { first } from 'rxjs/operators';
import { CoreSetup, Plugin, PluginInitializerContext } from 'src/core/public';
import { TelemetryPluginSetup } from '../../../../src/plugins/telemetry/public';
import { TelemetryPluginStart } from '../../../../src/plugins/telemetry/public';
import { ManagementSetup, ManagementSectionId } from '../../../../src/plugins/management/public';
import { LicensingPluginSetup } from '../../../plugins/licensing/public';
import { PLUGIN } from '../common/constants';
@ -14,10 +14,13 @@ import { ClientConfigType } from './types';
import { AppDependencies } from './application';
import { BreadcrumbService } from './application/breadcrumbs';
interface PluginsDependencies {
interface PluginsDependenciesSetup {
management: ManagementSetup;
licensing: LicensingPluginSetup;
telemetry?: TelemetryPluginSetup;
}
interface PluginsDependenciesStart {
telemetry?: TelemetryPluginStart;
}
export interface LicenseManagementUIPluginSetup {
@ -31,7 +34,10 @@ export class LicenseManagementUIPlugin
constructor(private readonly initializerContext: PluginInitializerContext) {}
setup(coreSetup: CoreSetup, plugins: PluginsDependencies): LicenseManagementUIPluginSetup {
setup(
coreSetup: CoreSetup<PluginsDependenciesStart>,
plugins: PluginsDependenciesSetup
): LicenseManagementUIPluginSetup {
const config = this.initializerContext.config.get<ClientConfigType>();
if (!config.ui.enabled) {
@ -42,14 +48,14 @@ export class LicenseManagementUIPlugin
}
const { getStartServices } = coreSetup;
const { management, telemetry, licensing } = plugins;
const { management, licensing } = plugins;
management.sections.getSection(ManagementSectionId.Stack).registerApp({
id: PLUGIN.id,
title: PLUGIN.title,
order: 0,
mount: async ({ element, setBreadcrumbs, history }) => {
const [core] = await getStartServices();
const [core, { telemetry }] = await getStartServices();
const initialLicense = await plugins.licensing.license$.pipe(first()).toPromise();
// Setup documentation links