Skip to content

Commit

Permalink
Adds back in custom images for reporting + tests (elastic#76810) (ela…
Browse files Browse the repository at this point in the history
…stic#76825)

# Conflicts:
#	x-pack/plugins/reporting/server/plugin.ts

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
2 people authored and dgieselaar committed Sep 9, 2020
1 parent 8663e46 commit 42371a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions x-pack/plugins/reporting/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ describe('Reporting Plugin', () => {
expect(plugin.start(coreStart, pluginStart)).not.toHaveProperty('then');
});

it('registers an advanced setting for PDF logos', async () => {
const plugin = new ReportingPlugin(initContext);
plugin.setup(coreSetup, pluginSetup);
expect(coreSetup.uiSettings.register).toHaveBeenCalled();
expect(coreSetup.uiSettings.register.mock.calls[0][0]).toHaveProperty(
'xpackReporting:customPdfLogo'
);
});

it('logs start issues', async () => {
const plugin = new ReportingPlugin(initContext);
// @ts-ignore overloading error logger
Expand Down
29 changes: 28 additions & 1 deletion x-pack/plugins/reporting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core/server';
import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from '../common/constants';
import { ReportingCore } from './';
import { initializeBrowserDriverFactory } from './browsers';
import { buildConfig, ReportingConfigType } from './config';
Expand All @@ -20,6 +23,8 @@ import { setFieldFormats } from './services';
import { ReportingSetup, ReportingSetupDeps, ReportingStart, ReportingStartDeps } from './types';
import { registerReportingUsageCollector } from './usage';

const kbToBase64Length = (kb: number) => Math.floor((kb * 1024 * 8) / 6);

declare module 'src/core/server' {
interface RequestHandlerContext {
reporting?: ReportingStart | null;
Expand All @@ -40,14 +45,36 @@ export class ReportingPlugin

public setup(core: CoreSetup, plugins: ReportingSetupDeps) {
// prevent throwing errors in route handlers about async deps not being initialized
core.http.registerRouteHandlerContext('reporting', () => {
core.http.registerRouteHandlerContext(PLUGIN_ID, () => {
if (this.reportingCore.pluginIsStarted()) {
return {}; // ReportingStart contract
} else {
return null;
}
});

core.uiSettings.register({
[UI_SETTINGS_CUSTOM_PDF_LOGO]: {
name: i18n.translate('xpack.reporting.pdfFooterImageLabel', {
defaultMessage: 'PDF footer image',
}),
value: null,
description: i18n.translate('xpack.reporting.pdfFooterImageDescription', {
defaultMessage: `Custom image to use in the PDF's footer`,
}),
type: 'image',
schema: schema.nullable(schema.byteSize({ max: '200kb' })),
category: [PLUGIN_ID],
// Used client-side for size validation
validation: {
maxSize: {
length: kbToBase64Length(200),
description: '200 kB',
},
},
},
});

const { elasticsearch, http } = core;
const { licensing, security } = plugins;
const { initializerContext: initContext, reportingCore } = this;
Expand Down

0 comments on commit 42371a5

Please sign in to comment.