Skip to content

Commit

Permalink
[Reporting] Move "common" types and constants to allow cross-plugin i…
Browse files Browse the repository at this point in the history
…ntegration (elastic#83198)
  • Loading branch information
tsullivan committed Nov 12, 2020
1 parent f1f2672 commit 4932dc5
Show file tree
Hide file tree
Showing 39 changed files with 282 additions and 279 deletions.
41 changes: 34 additions & 7 deletions x-pack/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ export const BROWSER_TYPE = 'chromium';
export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY =
'xpack.reporting.jobCompletionNotifications';

export const API_BASE_URL = '/api/reporting'; // "Generation URL" from share menu
export const API_BASE_URL_V1 = '/api/reporting/v1'; //
export const API_BASE_GENERATE_V1 = `${API_BASE_URL_V1}/generate`;
export const API_LIST_URL = '/api/reporting/jobs';
export const API_GENERATE_IMMEDIATE = `${API_BASE_URL_V1}/generate/immediate/csv/saved-object`;
export const API_DIAGNOSE_URL = `${API_BASE_URL}/diagnose`;

export const CONTENT_TYPE_CSV = 'text/csv';
export const CSV_REPORTING_ACTION = 'downloadCsvReport';
export const CSV_BOM_CHARS = '\ufeff';
Expand Down Expand Up @@ -57,15 +50,49 @@ export const UI_SETTINGS_CUSTOM_PDF_LOGO = 'xpackReporting:customPdfLogo';
export const UI_SETTINGS_CSV_SEPARATOR = 'csv:separator';
export const UI_SETTINGS_CSV_QUOTE_VALUES = 'csv:quoteValues';

export const LAYOUT_TYPES = {
PRESERVE_LAYOUT: 'preserve_layout',
PRINT: 'print',
};

// Export Type Definitions
export const CSV_REPORT_TYPE = 'CSV';
export const PDF_REPORT_TYPE = 'printablePdf';
export const PNG_REPORT_TYPE = 'PNG';

export const PDF_JOB_TYPE = 'printable_pdf';
export const PNG_JOB_TYPE = 'PNG';
export const CSV_JOB_TYPE = 'csv';
export const CSV_FROM_SAVEDOBJECT_JOB_TYPE = 'csv_from_savedobject';
export const USES_HEADLESS_JOB_TYPES = [PDF_JOB_TYPE, PNG_JOB_TYPE];

// Licenses
export const LICENSE_TYPE_TRIAL = 'trial';
export const LICENSE_TYPE_BASIC = 'basic';
export const LICENSE_TYPE_STANDARD = 'standard';
export const LICENSE_TYPE_GOLD = 'gold';
export const LICENSE_TYPE_PLATINUM = 'platinum';
export const LICENSE_TYPE_ENTERPRISE = 'enterprise';

// Routes
export const API_BASE_URL = '/api/reporting'; // "Generation URL" from share menu
export const API_BASE_GENERATE = `${API_BASE_URL}/generate`;
export const API_LIST_URL = `${API_BASE_URL}/jobs`;
export const API_DIAGNOSE_URL = `${API_BASE_URL}/diagnose`;

// hacky endpoint
export const API_BASE_URL_V1 = '/api/reporting/v1'; //
export const API_GENERATE_IMMEDIATE = `${API_BASE_URL_V1}/generate/immediate/csv/saved-object`;

// Management UI route
export const REPORTING_MANAGEMENT_HOME = '/app/management/insightsAndAlerting/reporting';

// Statuses
export enum JOB_STATUSES {
PENDING = 'pending',
PROCESSING = 'processing',
COMPLETED = 'completed',
FAILED = 'failed',
CANCELLED = 'cancelled',
WARNINGS = 'completed_with_warnings',
}
9 changes: 9 additions & 0 deletions x-pack/plugins/reporting/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { LayoutSelectorDictionary } from './types';

export { CancellationToken } from './cancellation_token';
export { Poller } from './poller';

export const getDefaultLayoutSelectors = (): LayoutSelectorDictionary => ({
screenshot: '[data-shared-items-container]',
renderComplete: '[data-shared-item]',
itemsCountAttribute: 'data-shared-items-count',
timefilterDurationAttribute: 'data-shared-timefilter-duration',
});
11 changes: 10 additions & 1 deletion x-pack/plugins/reporting/common/poller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
*/

import _ from 'lodash';
import { PollerOptions } from './types';

interface PollerOptions {
functionToPoll: () => Promise<any>;
pollFrequencyInMillis: number;
trailing?: boolean;
continuePollingOnError?: boolean;
pollFrequencyErrorMultiplier?: number;
successFunction?: (...args: any) => any;
errorFunction?: (error: Error) => any;
}

// @TODO Maybe move to observables someday
export class Poller {
Expand Down
127 changes: 108 additions & 19 deletions x-pack/plugins/reporting/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,94 @@
* you may not use this file except in compliance with the Elastic License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { ReportingConfigType } from '../server/config';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LayoutParams } from '../server/lib/layouts';
export { LayoutParams };
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { ReportDocument, ReportSource } from '../server/lib/store/report';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { BaseParams } from '../server/types';
export interface PageSizeParams {
pageMarginTop: number;
pageMarginBottom: number;
pageMarginWidth: number;
tableBorderWidth: number;
headingHeight: number;
subheadingHeight: number;
}

export interface LayoutSelectorDictionary {
screenshot: string;
renderComplete: string;
itemsCountAttribute: string;
timefilterDurationAttribute: string;
}

export interface PdfImageSize {
width: number;
height?: number;
}

export interface Size {
width: number;
height: number;
}

export interface LayoutParams {
id: string;
dimensions?: Size;
selectors?: LayoutSelectorDictionary;
}

export interface ReportDocumentHead {
_id: string;
_index: string;
_seq_no: unknown;
_primary_term: unknown;
}

export interface TaskRunResult {
content_type: string | null;
content: string | null;
csv_contains_formulas?: boolean;
size: number;
max_size_reached?: boolean;
warnings?: string[];
}

export interface ReportSource {
jobtype: string;
kibana_name: string;
kibana_id: string;
created_by: string | false;
payload: {
headers: string; // encrypted headers
browserTimezone?: string; // may use timezone from advanced settings
objectType: string;
title: string;
layout?: LayoutParams;
};
meta: { objectType: string; layout?: string };
browser_type: string;
max_attempts: number;
timeout: number;

status: JobStatus;
attempts: number;
output: TaskRunResult | null;
started_at?: string;
completed_at?: string;
created_at: string;
priority?: number;
process_expiration?: string;
}

/*
* The document created by Reporting to store in the .reporting index
*/
export interface ReportDocument extends ReportDocumentHead {
_source: ReportSource;
}

export interface BaseParams {
browserTimezone?: string; // browserTimezone is optional: it is not in old POST URLs that were generated prior to being added to this interface
layout?: LayoutParams;
objectType: string;
title: string;
}

export type JobId = string;
export type JobStatus =
Expand Down Expand Up @@ -59,18 +138,28 @@ export interface ReportApiJSON {
status: string;
}

export interface PollerOptions {
functionToPoll: () => Promise<any>;
pollFrequencyInMillis: number;
trailing?: boolean;
continuePollingOnError?: boolean;
pollFrequencyErrorMultiplier?: number;
successFunction?: (...args: any) => any;
errorFunction?: (error: Error) => any;
}

export interface LicenseCheckResults {
enableLinks: boolean;
showLinks: boolean;
message: string;
}

export interface JobSummary {
id: JobId;
status: JobStatus;
title: string;
jobtype: string;
maxSizeReached?: boolean;
csvContainsFormulas?: boolean;
}

export interface JobSummarySet {
completed: JobSummary[];
failed: JobSummary[];
}

type DownloadLink = string;
export type DownloadReportFn = (jobId: JobId) => DownloadLink;

type ManagementLink = string;
export type ManagementLinkFn = () => ManagementLink;
39 changes: 0 additions & 39 deletions x-pack/plugins/reporting/constants.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import React, { FunctionComponent } from 'react';
import { JobStatuses } from '../../../constants';
import { JOB_STATUSES } from '../../../common/constants';
import { Job as ListingJob, Props as ListingProps } from '../report_listing';

type Props = { record: ListingJob } & ListingProps;

export const ReportDownloadButton: FunctionComponent<Props> = (props: Props) => {
const { record, apiClient, intl } = props;

if (record.status !== JobStatuses.COMPLETED && record.status !== JobStatuses.WARNINGS) {
if (record.status !== JOB_STATUSES.COMPLETED && record.status !== JOB_STATUSES.WARNINGS) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { EuiButtonIcon, EuiCallOut, EuiPopover } from '@elastic/eui';
import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import React, { Component } from 'react';
import { JobStatuses } from '../../../constants';
import { JOB_STATUSES } from '../../../common/constants';
import { JobContent, ReportingAPIClient } from '../../lib/reporting_api_client';
import { Job as ListingJob } from '../report_listing';

Expand Down Expand Up @@ -43,7 +43,7 @@ class ReportErrorButtonUi extends Component<Props, State> {
public render() {
const { record, intl } = this.props;

if (record.status !== JobStatuses.FAILED) {
if (record.status !== JOB_STATUSES.FAILED) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
} from '@elastic/eui';
import { get } from 'lodash';
import React, { Component, Fragment } from 'react';
import { USES_HEADLESS_JOB_TYPES } from '../../../common/constants';
import { ReportApiJSON } from '../../../common/types';
import { USES_HEADLESS_JOB_TYPES } from '../../../constants';
import { ReportingAPIClient } from '../../lib/reporting_api_client';

interface Props {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/public/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { getFailureToast } from './job_failure';
export { getWarningFormulasToast } from './job_warning_formulas';
export { getWarningMaxSizeToast } from './job_warning_max_size';
export { getGeneralErrorToast } from './general_error';
export { ScreenCapturePanelContent } from './screen_capture_panel_content';
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import { EuiButton } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { JobSummary } from '../';
import { JobId } from '../../common/types';
import { JobId, JobSummary } from '../../common/types';

interface Props {
getUrl: (jobId: JobId) => string;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/public/components/job_failure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobSummary, ManagementLinkFn } from '../';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { JobSummary, ManagementLinkFn } from '../../common/types';

export const getFailureToast = (
errorText: string,
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/reporting/public/components/job_success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobSummary } from '../';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { JobId } from '../../common/types';
import { JobId, JobSummary } from '../../common/types';
import { DownloadButton } from './job_download_button';
import { ReportLink } from './report_link';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobSummary } from '../';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { JobId } from '../../common/types';
import { JobId, JobSummary } from '../../common/types';
import { DownloadButton } from './job_download_button';
import { ReportLink } from './report_link';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobSummary } from '../';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { JobId } from '../../common/types';
import { JobId, JobSummary } from '../../common/types';
import { DownloadButton } from './job_download_button';
import { ReportLink } from './report_link';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import { Component, default as React, Fragment } from 'react';
import { Subscription } from 'rxjs';
import { ApplicationStart, ToastsSetup } from 'src/core/public';
import { ILicense, LicensingPluginSetup } from '../../../licensing/public';
import { JOB_STATUSES as JobStatuses } from '../../common/constants';
import { Poller } from '../../common/poller';
import { durationToNumber } from '../../common/schema_utils';
import { JobStatuses } from '../../constants';
import { checkLicense } from '../lib/license_check';
import { JobQueueEntry, ReportingAPIClient } from '../lib/reporting_api_client';
import { ClientConfigType } from '../plugin';
Expand Down
Loading

0 comments on commit 4932dc5

Please sign in to comment.