Skip to content

Commit

Permalink
Move reporting job types to /common (#114400) (#117388)
Browse files Browse the repository at this point in the history
* 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>

Co-authored-by: Vadim Kibana <82822460+vadimkibana@users.noreply.github.com>
  • Loading branch information
kibanamachine and vadimkibana authored Nov 3, 2021
1 parent c92257d commit 9e14095
Show file tree
Hide file tree
Showing 23 changed files with 248 additions and 114 deletions.
9 changes: 6 additions & 3 deletions x-pack/examples/reporting_example/public/containers/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -81,7 +84,7 @@ export const Main = ({ basename, reporting, screenshotMode }: ReportingExampleAp
});
});

const getPDFJobParamsDefault = () => {
const getPDFJobParamsDefault = (): JobAppParamsPDF => {
return {
layout: {
id: constants.LAYOUT_TYPES.PRESERVE_LAYOUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'>;
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions x-pack/plugins/reporting/common/types/base.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -57,16 +56,6 @@ export interface SearchRequestDeprecatedCSV {
| any;
}

type FormatsMapDeprecatedCSV = Map<
string,
{
id: string;
params: {
pattern: string;
};
}
>;

export interface SavedSearchGeneratorResultDeprecatedCSV {
maxSizeReached: boolean;
csvContainsFormulas?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/reporting/common/types/export_types/index.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.
*/

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';
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,15 +17,16 @@ 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;
forceNow?: string;
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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -119,8 +98,6 @@ export interface ReportDocument extends ReportDocumentHead {
_source: ReportSource;
}

export type JobId = string;

/*
* JobStatus:
* - Begins as 'pending'
Expand Down Expand Up @@ -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;
24 changes: 24 additions & 0 deletions x-pack/plugins/reporting/common/types/layout.ts
Original file line number Diff line number Diff line change
@@ -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
>;
34 changes: 34 additions & 0 deletions x-pack/plugins/reporting/common/types/url.ts
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions x-pack/plugins/reporting/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 9e14095

Please sign in to comment.