Skip to content

Commit aa2a77f

Browse files
Joel Griffithelasticmachine
andauthored
Adds back in custom images for reporting + tests (#76810) (#76825)
# Conflicts: # x-pack/plugins/reporting/server/plugin.ts Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 6683949 commit aa2a77f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

x-pack/plugins/reporting/server/plugin.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ describe('Reporting Plugin', () => {
8686
expect(plugin.start(coreStart, pluginStart)).not.toHaveProperty('then');
8787
});
8888

89+
it('registers an advanced setting for PDF logos', async () => {
90+
const plugin = new ReportingPlugin(initContext);
91+
plugin.setup(coreSetup, pluginSetup);
92+
expect(coreSetup.uiSettings.register).toHaveBeenCalled();
93+
expect(coreSetup.uiSettings.register.mock.calls[0][0]).toHaveProperty(
94+
'xpackReporting:customPdfLogo'
95+
);
96+
});
97+
8998
it('logs start issues', async () => {
9099
const plugin = new ReportingPlugin(initContext);
91100
// @ts-ignore overloading error logger

x-pack/plugins/reporting/server/plugin.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

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

26+
const kbToBase64Length = (kb: number) => Math.floor((kb * 1024 * 8) / 6);
27+
2328
declare module 'src/core/server' {
2429
interface RequestHandlerContext {
2530
reporting?: ReportingStart | null;
@@ -40,14 +45,36 @@ export class ReportingPlugin
4045

4146
public setup(core: CoreSetup, plugins: ReportingSetupDeps) {
4247
// prevent throwing errors in route handlers about async deps not being initialized
43-
core.http.registerRouteHandlerContext('reporting', () => {
48+
core.http.registerRouteHandlerContext(PLUGIN_ID, () => {
4449
if (this.reportingCore.pluginIsStarted()) {
4550
return {}; // ReportingStart contract
4651
} else {
4752
return null;
4853
}
4954
});
5055

56+
core.uiSettings.register({
57+
[UI_SETTINGS_CUSTOM_PDF_LOGO]: {
58+
name: i18n.translate('xpack.reporting.pdfFooterImageLabel', {
59+
defaultMessage: 'PDF footer image',
60+
}),
61+
value: null,
62+
description: i18n.translate('xpack.reporting.pdfFooterImageDescription', {
63+
defaultMessage: `Custom image to use in the PDF's footer`,
64+
}),
65+
type: 'image',
66+
schema: schema.nullable(schema.byteSize({ max: '200kb' })),
67+
category: [PLUGIN_ID],
68+
// Used client-side for size validation
69+
validation: {
70+
maxSize: {
71+
length: kbToBase64Length(200),
72+
description: '200 kB',
73+
},
74+
},
75+
},
76+
});
77+
5178
const { elasticsearch, http } = core;
5279
const { licensing, security } = plugins;
5380
const { initializerContext: initContext, reportingCore } = this;

0 commit comments

Comments
 (0)