[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:
parent
09e3f75bc3
commit
ae7e9d9ad5
|
@ -9,7 +9,7 @@ import { ScopedHistory } from 'kibana/public';
|
||||||
|
|
||||||
import { CoreStart } from '../../../../../src/core/public';
|
import { CoreStart } from '../../../../../src/core/public';
|
||||||
import { LicensingPluginSetup, ILicense } from '../../../licensing/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 { ClientConfigType } from '../types';
|
||||||
import { BreadcrumbService } from './breadcrumbs';
|
import { BreadcrumbService } from './breadcrumbs';
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ export interface AppDependencies {
|
||||||
};
|
};
|
||||||
plugins: {
|
plugins: {
|
||||||
licensing: LicensingPluginSetup;
|
licensing: LicensingPluginSetup;
|
||||||
telemetry?: TelemetryPluginSetup;
|
telemetry?: TelemetryPluginStart;
|
||||||
};
|
};
|
||||||
docLinks: {
|
docLinks: {
|
||||||
security: string;
|
security: string;
|
||||||
|
|
|
@ -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;
|
|
@ -5,13 +5,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import { EuiLink, EuiCheckbox, EuiSpacer, EuiText, EuiTitle, EuiPopover } from '@elastic/eui';
|
|
||||||
import { FormattedMessage } from '@kbn/i18n/react';
|
|
||||||
import {
|
import {
|
||||||
OptInExampleFlyout,
|
EuiLink,
|
||||||
PRIVACY_STATEMENT_URL,
|
EuiCheckbox,
|
||||||
TelemetryPluginSetup,
|
EuiSpacer,
|
||||||
} from '../../lib/telemetry';
|
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 {
|
interface State {
|
||||||
showMoreTelemetryInfo: boolean;
|
showMoreTelemetryInfo: boolean;
|
||||||
|
@ -22,7 +28,7 @@ interface Props {
|
||||||
onOptInChange: (isOptingInToTelemetry: boolean) => void;
|
onOptInChange: (isOptingInToTelemetry: boolean) => void;
|
||||||
isOptingInToTelemetry: boolean;
|
isOptingInToTelemetry: boolean;
|
||||||
isStartTrial: boolean;
|
isStartTrial: boolean;
|
||||||
telemetry: TelemetryPluginSetup;
|
telemetry: TelemetryPluginStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TelemetryOptIn extends React.Component<Props, State> {
|
export class TelemetryOptIn extends React.Component<Props, State> {
|
||||||
|
@ -54,11 +60,15 @@ export class TelemetryOptIn extends React.Component<Props, State> {
|
||||||
|
|
||||||
let example = null;
|
let example = null;
|
||||||
if (showExample) {
|
if (showExample) {
|
||||||
|
// Using React.Suspense and lazy loading here to avoid crashing the plugin when importing
|
||||||
|
// OptInExampleFlyout but telemetryManagementSection is disabled
|
||||||
example = (
|
example = (
|
||||||
<OptInExampleFlyout
|
<React.Suspense fallback={<EuiLoadingSpinner />}>
|
||||||
onClose={() => this.setState({ showExample: false })}
|
<OptInExampleFlyout
|
||||||
fetchExample={telemetry.telemetryService.fetchExample}
|
onClose={() => this.setState({ showExample: false })}
|
||||||
/>
|
fetchExample={telemetry.telemetryService.fetchExample}
|
||||||
|
/>
|
||||||
|
</React.Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +126,10 @@ export class TelemetryOptIn extends React.Component<Props, State> {
|
||||||
</EuiLink>
|
</EuiLink>
|
||||||
),
|
),
|
||||||
telemetryPrivacyStatementLink: (
|
telemetryPrivacyStatementLink: (
|
||||||
<EuiLink href={PRIVACY_STATEMENT_URL} target="_blank">
|
<EuiLink
|
||||||
|
href={telemetry.telemetryConstants.getPrivacyStatementUrl()}
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id="xpack.licenseMgmt.telemetryOptIn.telemetryPrivacyStatementLinkText"
|
id="xpack.licenseMgmt.telemetryOptIn.telemetryPrivacyStatementLinkText"
|
||||||
defaultMessage="telemetry privacy statement"
|
defaultMessage="telemetry privacy statement"
|
||||||
|
|
|
@ -4,15 +4,14 @@
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
* 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 type { TelemetryPluginStart } from '../../../../../../src/plugins/telemetry/public';
|
||||||
export { PRIVACY_STATEMENT_URL } from '../../../../../../src/plugins/telemetry/common/constants';
|
export { shouldShowTelemetryOptIn };
|
||||||
export { TelemetryPluginSetup, shouldShowTelemetryOptIn };
|
|
||||||
|
|
||||||
function shouldShowTelemetryOptIn(
|
function shouldShowTelemetryOptIn(
|
||||||
telemetry?: TelemetryPluginSetup
|
telemetry?: TelemetryPluginStart
|
||||||
): telemetry is TelemetryPluginSetup {
|
): telemetry is TelemetryPluginStart {
|
||||||
if (telemetry) {
|
if (telemetry) {
|
||||||
const { telemetryService } = telemetry;
|
const { telemetryService } = telemetry;
|
||||||
const isOptedIn = telemetryService.getIsOptedIn();
|
const isOptedIn = telemetryService.getIsOptedIn();
|
||||||
|
|
|
@ -26,12 +26,12 @@ import { FormattedMessage } from '@kbn/i18n/react';
|
||||||
import { TelemetryOptIn } from '../../../components/telemetry_opt_in';
|
import { TelemetryOptIn } from '../../../components/telemetry_opt_in';
|
||||||
import { EXTERNAL_LINKS } from '../../../../../common/constants';
|
import { EXTERNAL_LINKS } from '../../../../../common/constants';
|
||||||
import { AppContextConsumer, AppDependencies } from '../../../app_context';
|
import { AppContextConsumer, AppDependencies } from '../../../app_context';
|
||||||
import { TelemetryPluginSetup, shouldShowTelemetryOptIn } from '../../../lib/telemetry';
|
import { TelemetryPluginStart, shouldShowTelemetryOptIn } from '../../../lib/telemetry';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
loadTrialStatus: () => void;
|
loadTrialStatus: () => void;
|
||||||
startLicenseTrial: () => void;
|
startLicenseTrial: () => void;
|
||||||
telemetry?: TelemetryPluginSetup;
|
telemetry?: TelemetryPluginStart;
|
||||||
shouldShowStartTrial: boolean;
|
shouldShowStartTrial: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import { first } from 'rxjs/operators';
|
import { first } from 'rxjs/operators';
|
||||||
import { CoreSetup, Plugin, PluginInitializerContext } from 'src/core/public';
|
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 { ManagementSetup, ManagementSectionId } from '../../../../src/plugins/management/public';
|
||||||
import { LicensingPluginSetup } from '../../../plugins/licensing/public';
|
import { LicensingPluginSetup } from '../../../plugins/licensing/public';
|
||||||
import { PLUGIN } from '../common/constants';
|
import { PLUGIN } from '../common/constants';
|
||||||
|
@ -14,10 +14,13 @@ import { ClientConfigType } from './types';
|
||||||
import { AppDependencies } from './application';
|
import { AppDependencies } from './application';
|
||||||
import { BreadcrumbService } from './application/breadcrumbs';
|
import { BreadcrumbService } from './application/breadcrumbs';
|
||||||
|
|
||||||
interface PluginsDependencies {
|
interface PluginsDependenciesSetup {
|
||||||
management: ManagementSetup;
|
management: ManagementSetup;
|
||||||
licensing: LicensingPluginSetup;
|
licensing: LicensingPluginSetup;
|
||||||
telemetry?: TelemetryPluginSetup;
|
}
|
||||||
|
|
||||||
|
interface PluginsDependenciesStart {
|
||||||
|
telemetry?: TelemetryPluginStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LicenseManagementUIPluginSetup {
|
export interface LicenseManagementUIPluginSetup {
|
||||||
|
@ -31,7 +34,10 @@ export class LicenseManagementUIPlugin
|
||||||
|
|
||||||
constructor(private readonly initializerContext: PluginInitializerContext) {}
|
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>();
|
const config = this.initializerContext.config.get<ClientConfigType>();
|
||||||
|
|
||||||
if (!config.ui.enabled) {
|
if (!config.ui.enabled) {
|
||||||
|
@ -42,14 +48,14 @@ export class LicenseManagementUIPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
const { getStartServices } = coreSetup;
|
const { getStartServices } = coreSetup;
|
||||||
const { management, telemetry, licensing } = plugins;
|
const { management, licensing } = plugins;
|
||||||
|
|
||||||
management.sections.getSection(ManagementSectionId.Stack).registerApp({
|
management.sections.getSection(ManagementSectionId.Stack).registerApp({
|
||||||
id: PLUGIN.id,
|
id: PLUGIN.id,
|
||||||
title: PLUGIN.title,
|
title: PLUGIN.title,
|
||||||
order: 0,
|
order: 0,
|
||||||
mount: async ({ element, setBreadcrumbs, history }) => {
|
mount: async ({ element, setBreadcrumbs, history }) => {
|
||||||
const [core] = await getStartServices();
|
const [core, { telemetry }] = await getStartServices();
|
||||||
const initialLicense = await plugins.licensing.license$.pipe(first()).toPromise();
|
const initialLicense = await plugins.licensing.license$.pipe(first()).toPromise();
|
||||||
|
|
||||||
// Setup documentation links
|
// Setup documentation links
|
||||||
|
|
Loading…
Reference in a new issue