Move reporting job types to /common (#114400)

* move pdf types to /common folder

* move pdf v2 types to /common folder

* move png v2 types to /common folder

* move png types to /common

* move csv_searchsource_immediate types to /common

* move csv_searchsource type sto /common

* move csv types to /common folder

* export job params types on server and client

* use JobParamsPDF in example app

* use JobParamsPDFV2 in Canvas

* dont export twice

* export JobId

* improve export syntax

* update jest snapshot

* fix imports

* add JobAppParamsPDFV2 type

* add JobAppParamsPDF type

* update test snapshot

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Vadim Kibana 2021-11-03 18:43:04 +01:00 committed by GitHub
parent 2cd007ebfc
commit 0d0e17b097
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 248 additions and 114 deletions

View file

@ -34,9 +34,12 @@ import { BrowserRouter as Router, useHistory } from 'react-router-dom';
import * as Rx from 'rxjs';
import { takeWhile } from 'rxjs/operators';
import { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/public';
import type {
JobAppParamsPDF,
JobParamsPDFV2,
JobParamsPNGV2,
} from '../../../../plugins/reporting/public';
import { constants, ReportingStart } from '../../../../plugins/reporting/public';
import type { JobParamsPDFV2 } from '../../../../plugins/reporting/server/export_types/printable_pdf_v2/types';
import type { JobParamsPNGV2 } from '../../../../plugins/reporting/server/export_types/png_v2/types';
import { REPORTING_EXAMPLE_LOCATOR_ID } from '../../common';
@ -81,7 +84,7 @@ export const Main = ({ basename, reporting, screenshotMode }: ReportingExampleAp
});
});
const getPDFJobParamsDefault = () => {
const getPDFJobParamsDefault = (): JobAppParamsPDF => {
return {
layout: {
id: constants.LAYOUT_TYPES.PRESERVE_LAYOUT,

View file

@ -9,6 +9,7 @@ import type { RedirectOptions } from 'src/plugins/share/public';
import { CANVAS_APP_LOCATOR } from '../../../../common/locator';
import { CanvasAppLocatorParams } from '../../../../common/locator';
import { CanvasWorkpad } from '../../../../types';
import { JobAppParamsPDFV2 } from '../../../../../reporting/public';
export interface CanvasWorkpadSharingData {
workpad: Pick<CanvasWorkpad, 'id' | 'name' | 'height' | 'width'>;
@ -18,7 +19,7 @@ export interface CanvasWorkpadSharingData {
export function getPdfJobParams(
{ workpad: { id, name: title, width, height }, pageCount }: CanvasWorkpadSharingData,
version: string
) {
): JobAppParamsPDFV2 {
// The viewport in Reporting by specifying the dimensions. In order for things to work,
// we need a viewport that will include all of the pages in the workpad. The viewport
// also needs to include any offset values from the 0,0 position, otherwise the cropped

View file

@ -0,0 +1,29 @@
/*
* 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 { Ensure, SerializableRecord } from '@kbn/utility-types';
import type { LayoutParams } from './layout';
export type JobId = string;
export type BaseParams = Ensure<
{
layout?: LayoutParams;
objectType: string;
title: string;
browserTimezone: string; // to format dates in the user's time zone
version: string; // to handle any state migrations
},
SerializableRecord
>;
// base params decorated with encrypted headers that come into runJob functions
export interface BasePayload extends BaseParams {
headers: string;
spaceId?: string;
isDeprecated?: boolean;
}

View file

@ -5,8 +5,7 @@
* 2.0.
*/
import type { FieldSpec } from 'src/plugins/data/common';
import { BaseParams, BasePayload } from '../../types';
import { BaseParams, BasePayload } from '../base';
export type RawValue = string | object | null | undefined;
@ -57,16 +56,6 @@ export interface SearchRequestDeprecatedCSV {
| any;
}
type FormatsMapDeprecatedCSV = Map<
string,
{
id: string;
params: {
pattern: string;
};
}
>;
export interface SavedSearchGeneratorResultDeprecatedCSV {
maxSizeReached: boolean;
csvContainsFormulas?: boolean;

View file

@ -6,9 +6,7 @@
*/
import type { SearchSourceFields } from 'src/plugins/data/common';
import type { BaseParams, BasePayload } from '../../types';
export type RawValue = string | object | null | undefined;
import type { BaseParams, BasePayload } from '../base';
interface BaseParamsCSV {
searchSource: SearchSourceFields;

View file

@ -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.
*/
export * from './csv';
export * from './csv_searchsource';
export * from './csv_searchsource_immediate';
export * from './png';
export * from './png_v2';
export * from './printable_pdf';
export * from './printable_pdf_v2';

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { LayoutParams } from '../../lib/layouts';
import { BaseParams, BasePayload } from '../../types';
import type { LayoutParams } from '../layout';
import type { BaseParams, BasePayload } from '../base';
interface BaseParamsPNG {
layout: LayoutParams;

View file

@ -5,9 +5,9 @@
* 2.0.
*/
import type { LocatorParams } from '../../../common/types';
import type { LayoutParams } from '../../lib/layouts';
import type { BaseParams, BasePayload } from '../../types';
import type { LocatorParams } from '../url';
import type { LayoutParams } from '../layout';
import type { BaseParams, BasePayload } from '../base';
// Job params: structure of incoming user request data
export interface JobParamsPNGV2 extends BaseParams {

View file

@ -5,8 +5,8 @@
* 2.0.
*/
import { LayoutParams } from '../../lib/layouts';
import { BaseParams, BasePayload } from '../../types';
import type { LayoutParams } from '../layout';
import type { BaseParams, BasePayload } from '../base';
interface BaseParamsPDF {
layout: LayoutParams;
@ -17,6 +17,8 @@ interface BaseParamsPDF {
// Job params: structure of incoming user request data, after being parsed from RISON
export type JobParamsPDF = BaseParamsPDF & BaseParams;
export type JobAppParamsPDF = Omit<JobParamsPDF, 'browserTimezone' | 'version'>;
// Job payload: structure of stored job data provided by create_job
export interface TaskPayloadPDF extends BasePayload {
layout: LayoutParams;
@ -24,8 +26,7 @@ export interface TaskPayloadPDF extends BasePayload {
objects: Array<{ relativeUrl: string }>;
}
type Legacy = Omit<JobParamsPDF, 'relativeUrls'>;
export interface JobParamsPDFLegacy extends Legacy {
export interface JobParamsPDFLegacy extends Omit<JobParamsPDF, 'relativeUrls'> {
savedObjectId: string;
queryString: string;
}

View file

@ -0,0 +1,33 @@
/*
* 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 { LocatorParams } from '../url';
import type { LayoutParams } from '../layout';
import type { BaseParams, BasePayload } from '../base';
interface BaseParamsPDFV2 {
layout: LayoutParams;
/**
* This value is used to re-create the same visual state as when the report was requested as well as navigate to the correct page.
*/
locatorParams: LocatorParams[];
}
// Job params: structure of incoming user request data, after being parsed from RISON
export type JobParamsPDFV2 = BaseParamsPDFV2 & BaseParams;
export type JobAppParamsPDFV2 = Omit<JobParamsPDFV2, 'browserTimezone' | 'version'>;
// Job payload: structure of stored job data provided by create_job
export interface TaskPayloadPDFV2 extends BasePayload, BaseParamsPDFV2 {
layout: LayoutParams;
/**
* The value of forceNow is injected server-side every time a given report is generated.
*/
forceNow: string;
}

View file

@ -5,7 +5,20 @@
* 2.0.
*/
import type { Ensure, SerializableRecord } from '@kbn/utility-types';
import type { Size, LayoutParams } from './layout';
import type { JobId, BaseParams, BasePayload } from './base';
export type { JobId, BaseParams, BasePayload };
export type { Size, LayoutParams };
export type {
DownloadReportFn,
IlmPolicyMigrationStatus,
IlmPolicyStatusResponse,
LocatorParams,
ManagementLinkFn,
UrlOrUrlLocatorTuple,
} from './url';
export * from './export_types';
export interface PageSizeParams {
pageMarginTop: number;
@ -21,22 +34,6 @@ export interface PdfImageSize {
height?: number;
}
export type Size = Ensure<
{
width: number;
height: number;
},
SerializableRecord
>;
export type LayoutParams = Ensure<
{
id: string;
dimensions?: Size;
},
SerializableRecord
>;
export interface ReportDocumentHead {
_id: string;
_index: string;
@ -56,24 +53,6 @@ export interface TaskRunResult {
warnings?: string[];
}
export type BaseParams = Ensure<
{
layout?: LayoutParams;
objectType: string;
title: string;
browserTimezone: string; // to format dates in the user's time zone
version: string; // to handle any state migrations
},
SerializableRecord
>;
// base params decorated with encrypted headers that come into runJob functions
export interface BasePayload extends BaseParams {
headers: string;
spaceId?: string;
isDeprecated?: boolean;
}
export interface ReportSource {
/*
* Required fields: populated in RequestHandler.enqueueJob when the request comes in to
@ -119,8 +98,6 @@ export interface ReportDocument extends ReportDocumentHead {
_source: ReportSource;
}
export type JobId = string;
/*
* JobStatus:
* - Begins as 'pending'
@ -173,28 +150,3 @@ export interface JobSummarySet {
completed: JobSummary[];
failed: JobSummary[];
}
type DownloadLink = string;
export type DownloadReportFn = (jobId: JobId) => DownloadLink;
type ManagementLink = string;
export type ManagementLinkFn = () => ManagementLink;
export interface LocatorParams<
P extends SerializableRecord = SerializableRecord & { forceNow?: string }
> {
id: string;
version: string;
params: P;
}
export type IlmPolicyMigrationStatus = 'policy-not-found' | 'indices-not-managed-by-policy' | 'ok';
export interface IlmPolicyStatusResponse {
status: IlmPolicyMigrationStatus;
}
type Url = string;
type UrlLocatorTuple = [url: Url, locatorParams: LocatorParams];
export type UrlOrUrlLocatorTuple = Url | UrlLocatorTuple;

View file

@ -0,0 +1,24 @@
/*
* 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 { Ensure, SerializableRecord } from '@kbn/utility-types';
export type Size = Ensure<
{
width: number;
height: number;
},
SerializableRecord
>;
export type LayoutParams = Ensure<
{
id: string;
dimensions?: Size;
},
SerializableRecord
>;

View file

@ -0,0 +1,34 @@
/*
* 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 { SerializableRecord } from '@kbn/utility-types';
import type { JobId } from './base';
type DownloadLink = string;
export type DownloadReportFn = (jobId: JobId) => DownloadLink;
type ManagementLink = string;
export type ManagementLinkFn = () => ManagementLink;
export interface LocatorParams<
P extends SerializableRecord = SerializableRecord & { forceNow?: string }
> {
id: string;
version: string;
params: P;
}
export type IlmPolicyMigrationStatus = 'policy-not-found' | 'indices-not-managed-by-policy' | 'ok';
export interface IlmPolicyStatusResponse {
status: IlmPolicyMigrationStatus;
}
type Url = string;
type UrlLocatorTuple = [url: Url, locatorParams: LocatorParams];
export type UrlOrUrlLocatorTuple = Url | UrlLocatorTuple;

View file

@ -18,6 +18,17 @@ export interface ReportingSetup {
export type ReportingStart = ReportingSetup;
export { constants } from '../common';
export type {
JobParamsCSV,
JobParamsDownloadCSV,
JobParamsPNG,
JobParamsPNGV2,
JobAppParamsPDFV2,
JobParamsPDF,
JobParamsPDFV2,
JobAppParamsPDF,
} from '../common/types';
export { ReportingAPIClient, ReportingPublicPlugin as Plugin };
export function plugin(initializerContext: PluginInitializerContext) {

View file

@ -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.
*/
export type {
RawValue,
JobParamsDeprecatedCSV,
TaskPayloadDeprecatedCSV,
SearchRequestDeprecatedCSV,
SavedSearchGeneratorResultDeprecatedCSV,
} from '../../../common/types';

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export type { RawValue, JobParamsCSV, TaskPayloadCSV } from '../../../common/types';

View file

@ -0,0 +1,12 @@
/*
* 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.
*/
export type {
FakeRequest,
JobParamsDownloadCSV,
SavedObjectServiceError,
} from '../../../common/types';

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export type { JobParamsPNG, TaskPayloadPNG } from '../../../common/types';

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export type { JobParamsPNGV2, TaskPayloadPNGV2 } from '../../../common/types';

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export type { JobParamsPDF, TaskPayloadPDF, JobParamsPDFLegacy } from '../../../common/types';

View file

@ -5,27 +5,4 @@
* 2.0.
*/
import { LocatorParams } from '../../../common/types';
import { LayoutParams } from '../../lib/layouts';
import { BaseParams, BasePayload } from '../../types';
interface BaseParamsPDFV2 {
layout: LayoutParams;
/**
* This value is used to re-create the same visual state as when the report was requested as well as navigate to the correct page.
*/
locatorParams: LocatorParams[];
}
// Job params: structure of incoming user request data, after being parsed from RISON
export type JobParamsPDFV2 = BaseParamsPDFV2 & BaseParams;
// Job payload: structure of stored job data provided by create_job
export interface TaskPayloadPDFV2 extends BasePayload, BaseParamsPDFV2 {
layout: LayoutParams;
/**
* The value of forceNow is injected server-side every time a given report is generated.
*/
forceNow: string;
}
export type { JobParamsPDFV2, TaskPayloadPDFV2 } from '../../../common/types';

View file

@ -14,6 +14,16 @@ export const plugin = (initContext: PluginInitializerContext<ReportingConfigType
export { config } from './config';
export { ReportingConfig } from './config/config';
export type {
JobParamsCSV,
JobParamsDownloadCSV,
JobParamsPNG,
JobParamsPNGV2,
JobParamsPDF,
JobParamsPDFV2,
} from '../common/types';
// internal imports
export { ReportingCore } from './core';
export {