Skip to content

Commit

Permalink
Adjust client license handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Mar 30, 2020
1 parent 37b665a commit ed846a1
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 38 deletions.
91 changes: 91 additions & 0 deletions x-pack/plugins/grokdebugger/public/components/inactive_license.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 React from 'react';
import {
EuiCallOut,
EuiText,
EuiLink,
EuiCode,
EuiPage,
EuiPageBody,
EuiPageContent,
EuiPageContentBody,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

export const InactiveLicenseSlate = () => {
const registerLicenseLinkLabel = i18n.translate('xpack.grokDebugger.registerLicenseLinkLabel', {
defaultMessage: 'register a license',
});

const trialLicense = i18n.translate('xpack.grokdDebugger.trialLicenseTitle', {
defaultMessage: 'Trial',
});

const basicLicense = i18n.translate('xpack.grokDebugger.basicLicenseTitle', {
defaultMessage: 'Basic',
});

const goldLicense = i18n.translate('xpack.grokDebugger.goldLicenseTitle', {
defaultMessage: 'Gold',
});

const platinumLicense = i18n.translate('xpack.grokDebugger.platinumLicenseTitle', {
defaultMessage: 'Platinum',
});

return (
<EuiPage>
<EuiPageBody component="div">
<EuiPageContent verticalPosition="center" horizontalPosition="center">
<EuiPageContentBody>
<EuiCallOut
title={i18n.translate('xpack.grokDebugger.licenseErrorMessageTitle', {
defaultMessage: 'License error',
})}
color="danger"
iconType="alert"
style={{ padding: '16px' }}
>
<EuiText size="s">
<p>
<FormattedMessage
id="xpack.grokDebugger.licenseErrorMessageDescription"
defaultMessage="The Grok Debugger requires an active license ({licenseTypeList} or {platinumLicenseType}), but none were found in your cluster."
values={{
licenseTypeList: (
<>
<EuiCode>{trialLicense}</EuiCode>, <EuiCode>{basicLicense}</EuiCode>,{' '}
<EuiCode>{goldLicense}</EuiCode>
</>
),
platinumLicenseType: <EuiCode>{platinumLicense}</EuiCode>,
}}
/>
</p>
<p>
<FormattedMessage
id="xpack.grokDebugger.registerLicenseDescription"
defaultMessage="Please {registerLicenseLink} to continue using the Grok Debugger"
values={{
registerLicenseLink: (
<EuiLink href="https://www.elastic.co/subscriptions" rel="noopener">
{registerLicenseLinkLabel}
</EuiLink>
),
}}
/>
</p>
</EuiText>
</EuiCallOut>
</EuiPageContentBody>
</EuiPageContent>
</EuiPageBody>
</EuiPage>
);
};
43 changes: 14 additions & 29 deletions x-pack/plugins/grokdebugger/public/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,27 @@ import { first } from 'rxjs/operators';
import { registerFeature } from './register_feature';
import { PLUGIN } from '../common/constants';

const inactiveLicenseMessage = i18n.translate('xpack.grokDebugger.clientInactiveLicenseError', {
defaultMessage: 'The Grok Debugger tool requires an active license.',
});

export class Plugin {
setup(coreSetup, plugins) {
registerFeature(plugins.home);

this.licensing = plugins.licensing;

this.licensing.license$.pipe(first()).subscribe(license => {
plugins.devTools.register({
order: 6,
title: i18n.translate('xpack.grokDebugger.displayName', {
defaultMessage: 'Grok Debugger',
}),
id: PLUGIN.ID,
enableRouting: false,
disabled: !license.isActive,
tooltipContent: !license.isActive ? inactiveLicenseMessage : null,
async mount(context, { element }) {
const [coreStart] = await coreSetup.getStartServices();
const { renderApp } = await import('./render_app');
return renderApp(element, coreStart);
},
});
plugins.devTools.register({
order: 6,
title: i18n.translate('xpack.grokDebugger.displayName', {
defaultMessage: 'Grok Debugger',
}),
id: PLUGIN.ID,
enableRouting: false,
async mount(context, { element }) {
const [coreStart] = await coreSetup.getStartServices();
const license = await plugins.licensing.license$.pipe(first()).toPromise();
const { renderApp } = await import('./render_app');
return renderApp(license, element, coreStart);
},
});
}

start(coreStart) {
this.licensing.license$.subscribe(license => {
coreStart.chrome.navLinks.update(PLUGIN.ID, {
hidden: !license.isActive,
});
});
}
start() {}

stop() {}
}
29 changes: 20 additions & 9 deletions x-pack/plugins/grokdebugger/public/render_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ import { GrokDebugger } from './components/grok_debugger';
import { GrokdebuggerService } from './services/grokdebugger/grokdebugger_service';
import { I18nProvider } from '@kbn/i18n/react';
import { KibanaContextProvider } from '../../../../src/plugins/kibana_react/public';
import { InactiveLicenseSlate } from './components/inactive_license';

export function renderApp(element, coreStart) {
render(
<KibanaContextProvider services={{ ...coreStart }}>
export function renderApp(license, element, coreStart) {
if (!license.isActive) {
render(
<I18nProvider>
<GrokDebugger grokdebuggerService={new GrokdebuggerService(coreStart.http)} />
</I18nProvider>
</KibanaContextProvider>,
element
);
return () => unmountComponentAtNode(element);
<InactiveLicenseSlate license={license} />
</I18nProvider>,
element
);
return () => unmountComponentAtNode(element);
} else {
render(
<KibanaContextProvider services={{ ...coreStart }}>
<I18nProvider>
<GrokDebugger grokdebuggerService={new GrokdebuggerService(coreStart.http)} />
</I18nProvider>
</KibanaContextProvider>,
element
);
return () => unmountComponentAtNode(element);
}
}

0 comments on commit ed846a1

Please sign in to comment.