Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds back in custom images for reporting + tests #76810

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema is required by types for register, however validation is what the client is looking at for validating that the size is appropriate

// 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