Skip to content

Commit

Permalink
[Reporting] Initial Export types plugin (#158479)
Browse files Browse the repository at this point in the history
## Summary

Closes #158512

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

Co-authored-by: Tim Sullivan <[email protected]>
  • Loading branch information
rshen91 and tsullivan authored May 31, 2023
1 parent 1c1f016 commit 3746b73
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ packages/kbn-repo-source-classifier @elastic/kibana-operations
packages/kbn-repo-source-classifier-cli @elastic/kibana-operations
packages/kbn-reporting/common @elastic/appex-sharedux
x-pack/examples/reporting_example @elastic/appex-sharedux
x-pack/plugins/reporting_export_types @elastic/appex-sharedux
x-pack/plugins/reporting @elastic/appex-sharedux
x-pack/test/plugin_functional/plugins/resolver_test @elastic/security-solution
examples/response_stream @elastic/ml-ui
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ Elastic.
|An awesome Kibana reporting plugin
|{kib-repo}blob/{branch}/x-pack/plugins/reporting_export_types/README.md[reportingExportTypes]
|This plugin is intended to be a central point for the export types of reporting to convene before hitting the reporting plugin.
|{kib-repo}blob/{branch}/x-pack/plugins/rollup/README.md[rollup]
|Welcome to the Kibana rollup plugin! This plugin provides Kibana support for Elasticsearch's rollup feature. Please refer to the Elasticsearch documentation to understand rollup indices and how to create rollup jobs.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@
"@kbn/repo-packages": "link:packages/kbn-repo-packages",
"@kbn/reporting-common": "link:packages/kbn-reporting/common",
"@kbn/reporting-example-plugin": "link:x-pack/examples/reporting_example",
"@kbn/reporting-export-types-plugin": "link:x-pack/plugins/reporting_export_types",
"@kbn/reporting-plugin": "link:x-pack/plugins/reporting",
"@kbn/resolver-test-plugin": "link:x-pack/test/plugin_functional/plugins/resolver_test",
"@kbn/response-stream-plugin": "link:examples/response_stream",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@
"@kbn/reporting-common/*": ["packages/kbn-reporting/common/*"],
"@kbn/reporting-example-plugin": ["x-pack/examples/reporting_example"],
"@kbn/reporting-example-plugin/*": ["x-pack/examples/reporting_example/*"],
"@kbn/reporting-export-types-plugin": ["x-pack/plugins/reporting_export_types"],
"@kbn/reporting-export-types-plugin/*": ["x-pack/plugins/reporting_export_types/*"],
"@kbn/reporting-plugin": ["x-pack/plugins/reporting"],
"@kbn/reporting-plugin/*": ["x-pack/plugins/reporting/*"],
"@kbn/resolver-test-plugin": ["x-pack/test/plugin_functional/plugins/resolver_test"],
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/canvas/server/feature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let mockReportingPlugin: ReportingStart;
beforeEach(() => {
mockReportingPlugin = {
usesUiCapabilities: () => false,
registerExportTypes: () => {},
};
});

Expand Down Expand Up @@ -87,6 +88,7 @@ it('Provides a feature declaration ', () => {
it(`Calls on Reporting whether to include Generate PDF as a sub-feature`, () => {
mockReportingPlugin = {
usesUiCapabilities: () => true,
registerExportTypes: () => {},
};
expect(getCanvasFeature({ reporting: mockReportingPlugin })).toMatchInlineSnapshot(`
Object {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/server/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class ReportingCore {

this.getContract = () => ({
usesUiCapabilities: () => config.roles.enabled === false,
registerExportTypes: (id) => id,
});

this.executing = new Set();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('POST /diagnose/browser', () => {
httpSetup.registerRouteHandlerContext<ReportingRequestHandlerContext, 'reporting'>(
reportingSymbol,
'reporting',
() => ({ usesUiCapabilities: () => false })
() => ({ usesUiCapabilities: () => false, registerExportTypes: jest.fn() })
);

const docLinksSetupMock = docLinksServiceMock.createSetupContract();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('POST /diagnose/screenshot', () => {
httpSetup.registerRouteHandlerContext<ReportingRequestHandlerContext, 'reporting'>(
reportingSymbol,
'reporting',
() => ({ usesUiCapabilities: () => false })
() => ({ usesUiCapabilities: () => false, registerExportTypes: jest.fn() })
);

core = await createMockReportingCore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('POST /api/reporting/generate', () => {
httpSetup.registerRouteHandlerContext<ReportingRequestHandlerContext, 'reporting'>(
reportingSymbol,
'reporting',
() => ({ usesUiCapabilities: jest.fn() })
() => ({ usesUiCapabilities: jest.fn(), registerExportTypes: jest.fn() })
);

const mockSetupDeps = createMockPluginSetup({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('GET /api/reporting/jobs/download', () => {
httpSetup.registerRouteHandlerContext<ReportingRequestHandlerContext, 'reporting'>(
reportingSymbol,
'reporting',
() => ({ usesUiCapabilities: jest.fn() })
() => ({ usesUiCapabilities: jest.fn(), registerExportTypes: jest.fn() })
);

mockSetupDeps = createMockPluginSetup({
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/reporting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type { BaseParams, BasePayload, UrlOrUrlLocatorTuple } from '../common/ty
import type { ReportingConfigType } from './config';
import type { ReportingCore } from './core';
import type { ReportTaskParams } from './lib/tasks';
import { ExportTypesRegistry } from './lib';

/**
* Plugin Setup Contract
Expand All @@ -43,6 +44,7 @@ export interface ReportingSetup {
* Used to inform plugins if Reporting config is compatible with UI Capabilities / Application Sub-Feature Controls
*/
usesUiCapabilities: () => boolean;
registerExportTypes: ExportTypesRegistry['register'];
}

/**
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/reporting_export_types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# exportTypePlugin

This plugin is intended to be a central point for the export types of reporting to convene before hitting the reporting plugin.
25 changes: 25 additions & 0 deletions x-pack/plugins/reporting_export_types/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "plugin",
"id": "@kbn/reporting-export-types-plugin",
"owner": "@elastic/appex-sharedux",
"description": "Currently PDF, PNG or CSV export types for the reporting plugin",
"plugin": {
"id": "reportingExportTypes",
"server": true,
"browser": false,
"configPath": [
"xpack",
"reporting"
],
"requiredPlugins": [
"reporting"
],
"optionalPlugins": [
"security",
"spaces",
"usageCollection"
],
"requiredBundles": [
]
}
}
18 changes: 18 additions & 0 deletions x-pack/plugins/reporting_export_types/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { PluginInitializerContext, Logger } from '@kbn/core/server';
import { ExportTypesPlugin } from './plugin';

// This exports static code and TypeScript types,
// as well as, Kibana Platform `plugin()` initializer.

export function plugin(initializerContext: PluginInitializerContext, logger: Logger) {
return new ExportTypesPlugin(initializerContext, logger);
}

export type { ExportTypesPluginSetup, ExportTypesPluginStart } from './types';
40 changes: 40 additions & 0 deletions x-pack/plugins/reporting_export_types/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from '@kbn/core/server';

import { ConfigSchema } from '@kbn/reporting-plugin/server/config';
import { ExportTypesPluginSetup, ExportTypesPluginStart } from './types';

export class ExportTypesPlugin
implements Plugin<{}, {}, ExportTypesPluginSetup, ExportTypesPluginStart>
{
exportTypes = [
// new CsvExportType(),
// new PdfExportType(),
// new PngExportType(),
];

constructor(initializerContext: PluginInitializerContext<typeof ConfigSchema>, logger: Logger) {
logger = initializerContext.logger.get();
}

public setup(core: CoreSetup, pluginsSetup: ExportTypesPluginSetup) {
const { reporting } = pluginsSetup;
this.exportTypes.forEach((eType) => {
reporting.registerExportTypes(eType);
});
return {};
}

public start(core: CoreStart, plugins: ExportTypesPluginStart) {
this.exportTypes.forEach((eType) => {});
return {};
}

public stop() {}
}
14 changes: 14 additions & 0 deletions x-pack/plugins/reporting_export_types/server/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { ReportingSetup, ReportingStart } from '@kbn/reporting-plugin/server/types';

export interface ExportTypesPluginSetup {
reporting: ReportingSetup;
}
export interface ExportTypesPluginStart {
reporting: ReportingStart;
}
16 changes: 16 additions & 0 deletions x-pack/plugins/reporting_export_types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types"
},
"include": [
"common/**/*",
"server/**/*",
"../../../typings/**/*"
],
"kbn_references": [
"@kbn/core",
"@kbn/reporting-plugin",
],
"exclude": ["target/**/*"]
}
6 changes: 5 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4819,6 +4819,10 @@
version "0.0.0"
uid ""

"@kbn/reporting-export-types-plugin@link:x-pack/plugins/reporting_export_types":
version "0.0.0"
uid ""

"@kbn/reporting-plugin@link:x-pack/plugins/reporting":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -9496,7 +9500,7 @@
dependencies:
"@types/yargs-parser" "*"

"@types/yargs@^17.0.8", "@types/yargs@^17.0.10":
"@types/yargs@^17.0.10", "@types/yargs@^17.0.8":
version "17.0.24"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.24.tgz#b3ef8d50ad4aa6aecf6ddc97c580a00f5aa11902"
integrity sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==
Expand Down

0 comments on commit 3746b73

Please sign in to comment.