Skip to content

Commit

Permalink
[Reporting] Clean Up TypeScript Definitions (elastic#76566)
Browse files Browse the repository at this point in the history
* [Reporting] Simplify Export Type Definitions, use defaults for generics, refactor

* ReportApiJSON interface for common

* rename JobSummary to JobStatusBucket for clarity

* revert unneeded create mock changes

* clean up the diff

* revert changes to worker.js

* rewrite comment

* rename type to jobtype in JobStatusBucket

* allow type inference

* JobSummarySet

* remove odd comment

* Reflect that browser timezone may be undefined in the BaseParams

* comment about optional browserTimezone

* revert unecessary es archive change

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
tsullivan and elasticmachine committed Sep 22, 2020
1 parent 1dfc2f5 commit e35b516
Show file tree
Hide file tree
Showing 87 changed files with 695 additions and 890 deletions.
71 changes: 37 additions & 34 deletions x-pack/plugins/reporting/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { ReportingConfigType } from '../server/config';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { LayoutInstance } from '../server/lib/layouts';
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 type JobId = string;
export type JobStatus =
Expand All @@ -17,45 +22,43 @@ export type JobStatus =
| 'processing'
| 'failed';

export interface SourceJob {
_id: JobId;
_source: {
status: JobStatus;
output: {
max_size_reached: boolean;
csv_contains_formulas: boolean;
};
payload: {
type: string;
title: string;
};
};
}

export interface JobContent {
content: string;
}

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

export interface JobStatusBuckets {
completed: JobSummary[];
failed: JobSummary[];
export interface ReportApiJSON {
id: string;
index: string;
kibana_name: string;
kibana_id: string;
browser_type: string | undefined;
created_at: string;
priority?: number;
jobtype: string;
created_by: string | false;
timeout?: number;
output?: {
content_type: string;
size: number;
warnings?: string[];
};
process_expiration?: string;
completed_at: string | undefined;
payload: {
layout?: LayoutParams;
title: string;
browserTimezone?: string;
};
meta: {
layout?: string;
objectType: string;
};
max_attempts: number;
started_at: string | undefined;
attempts: number;
status: string;
}

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

type ManagementLink = string;
export type ManagementLinkFn = () => ManagementLink;

export interface PollerOptions {
functionToPoll: () => Promise<any>;
pollFrequencyInMillis: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
EuiText,
EuiTitle,
} from '@elastic/eui';
import React, { Component, Fragment } from 'react';
import { get } from 'lodash';
import React, { Component, Fragment } from 'react';
import { ReportApiJSON } from '../../../common/types';
import { USES_HEADLESS_JOB_TYPES } from '../../../constants';
import { JobInfo, ReportingAPIClient } from '../../lib/reporting_api_client';
import { ReportingAPIClient } from '../../lib/reporting_api_client';

interface Props {
jobId: string;
Expand All @@ -29,14 +30,14 @@ interface State {
isLoading: boolean;
isFlyoutVisible: boolean;
calloutTitle: string;
info: JobInfo | null;
info: ReportApiJSON | null;
error: Error | null;
}

const NA = 'n/a';
const UNKNOWN = 'unknown';

const getDimensions = (info: JobInfo): string => {
const getDimensions = (info: ReportApiJSON): string => {
const defaultDimensions = { width: null, height: null };
const { width, height } = get(info, 'payload.layout.dimensions', defaultDimensions);
if (width && height) {
Expand Down Expand Up @@ -121,10 +122,6 @@ export class ReportInfoButton extends Component<Props, State> {
title: 'Title',
description: get(info, 'payload.title') || NA,
},
{
title: 'Type',
description: get(info, 'payload.type') || NA,
},
{
title: 'Layout',
description: get(info, 'meta.layout') || NA,
Expand Down Expand Up @@ -263,7 +260,7 @@ export class ReportInfoButton extends Component<Props, State> {
private loadInfo = async () => {
this.setState({ isLoading: true });
try {
const info: JobInfo = await this.props.apiClient.getInfo(this.props.jobId);
const info: ReportApiJSON = await this.props.apiClient.getInfo(this.props.jobId);
if (this.mounted) {
this.setState({ isLoading: false, info });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import { EuiButton } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { JobId, JobSummary } from '../../common/types';
import { JobSummary } from '../';
import { JobId } from '../../common/types';

interface Props {
getUrl: (jobId: JobId) => string;
Expand Down
4 changes: 2 additions & 2 deletions 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 All @@ -22,7 +22,7 @@ export const getFailureToast = (
<FormattedMessage
id="xpack.reporting.publicNotifier.error.couldNotCreateReportTitle"
defaultMessage="Could not create report for {reportObjectType} '{reportObjectTitle}'."
values={{ reportObjectType: job.type, reportObjectTitle: job.title }}
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
/>
),
text: toMountPoint(
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/reporting/public/components/job_success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
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, JobSummary } from '../../common/types';
import { JobId } from '../../common/types';
import { DownloadButton } from './job_download_button';
import { ReportLink } from './report_link';

Expand All @@ -21,7 +22,7 @@ export const getSuccessToast = (
<FormattedMessage
id="xpack.reporting.publicNotifier.successfullyCreatedReportNotificationTitle"
defaultMessage="Created report for {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.type, reportObjectTitle: job.title }}
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
/>
),
color: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
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, JobSummary } from '../../common/types';
import { JobId } from '../../common/types';
import { DownloadButton } from './job_download_button';
import { ReportLink } from './report_link';

Expand All @@ -21,7 +22,7 @@ export const getWarningFormulasToast = (
<FormattedMessage
id="xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportTitle"
defaultMessage="Report may contain formulas {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.type, reportObjectTitle: job.title }}
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
/>
),
text: toMountPoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
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, JobSummary } from '../../common/types';
import { JobId } from '../../common/types';
import { DownloadButton } from './job_download_button';
import { ReportLink } from './report_link';

Expand All @@ -21,7 +22,7 @@ export const getWarningMaxSizeToast = (
<FormattedMessage
id="xpack.reporting.publicNotifier.maxSizeReached.partialReportTitle"
defaultMessage="Created partial report for {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.type, reportObjectTitle: job.title }}
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
/>
),
text: toMountPoint(
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/reporting/public/components/report_listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ export interface Job {
type: string;
object_type: string;
object_title: string;
created_by?: string;
created_by?: string | false;
created_at: string;
started_at?: string;
completed_at?: string;
status: string;
statusLabel: string;
max_size_reached: boolean;
max_size_reached?: boolean;
attempts: number;
max_attempts: number;
csv_contains_formulas: boolean;
warnings: string[];
warnings?: string[];
}

export interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import { EuiButton, EuiCopy, EuiForm, EuiFormRow, EuiSpacer, EuiText } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import React, { Component, ReactElement } from 'react';
import url from 'url';
import { ToastsSetup } from 'src/core/public';
import { ReportingAPIClient } from '../lib/reporting_api_client';
import url from 'url';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { BaseParams } from '../../common/types';
import { ReportingAPIClient } from '../lib/reporting_api_client';

interface Props {
apiClient: ReportingAPIClient;
Expand All @@ -19,7 +20,7 @@ interface Props {
layoutId: string | undefined;
objectId?: string;
objectType: string;
getJobParams: () => any;
getJobParams: () => BaseParams;
options?: ReactElement<any>;
isDirty: boolean;
onClose: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiSpacer, EuiSwitch } from '@elastic/eui';
import { EuiSpacer, EuiSwitch, EuiSwitchEvent } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Component, Fragment } from 'react';
import { ToastsSetup } from 'src/core/public';
import { ReportingPanelContent } from './reporting_panel_content';
import { BaseParams } from '../../common/types';
import { ReportingAPIClient } from '../lib/reporting_api_client';
import { ReportingPanelContent } from './reporting_panel_content';

interface Props {
apiClient: ReportingAPIClient;
toasts: ToastsSetup;
reportType: string;
objectId?: string;
objectType: string;
getJobParams: () => any;
getJobParams: () => BaseParams;
isDirty: boolean;
onClose: () => void;
}
Expand Down Expand Up @@ -83,7 +84,7 @@ export class ScreenCapturePanelContent extends Component<Props, State> {
);
};

private handlePrintLayoutChange = (evt: any) => {
private handlePrintLayoutChange = (evt: EuiSwitchEvent) => {
this.setState({ usePrintLayout: evt.target.checked });
};

Expand Down
21 changes: 21 additions & 0 deletions x-pack/plugins/reporting/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,31 @@
import { PluginInitializerContext } from 'src/core/public';
import { ReportingPublicPlugin } from './plugin';
import * as jobCompletionNotifications from './lib/job_completion_notifications';
import { JobId, JobStatus } from '../common/types';

export function plugin(initializerContext: PluginInitializerContext) {
return new ReportingPublicPlugin(initializerContext);
}

export { ReportingPublicPlugin as Plugin };
export { jobCompletionNotifications };

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;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e35b516

Please sign in to comment.