Skip to content

Commit

Permalink
Adds back in custom images for reporting + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Griffith committed Sep 4, 2020
1 parent 4c2ef98 commit 9bd5bb1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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
31 changes: 29 additions & 2 deletions x-pack/plugins/reporting/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
* 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';
import { createQueueFactory, LevelLogger, runValidations, ReportingStore } from './lib';
import { createQueueFactory, LevelLogger, ReportingStore, runValidations } from './lib';
import { registerRoutes } from './routes';
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 @@ -34,14 +39,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 9bd5bb1

Please sign in to comment.