Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Clean Up TypeScript Definitions #76566

Merged
merged 19 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will now be used in the UI integration as types for AJAX payloads :)


export type JobId = string;
export type JobStatus =
Expand All @@ -17,45 +22,43 @@ export type JobStatus =
| 'processing'
| 'failed';

export interface SourceJob {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate of ReportDocument

_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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this public-only types to public/index

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And renamed to JobStatusBucket

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 @@ -263,7 +264,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,11 +7,12 @@
import { EuiButton } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { JobId, JobSummary } from '../../common/types';
import { JobStatusBucket } from '../';
import { JobId } from '../../common/types';
Copy link
Member Author

@tsullivan tsullivan Sep 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved JobSummary to public since it is never used on the server side


interface Props {
getUrl: (jobId: JobId) => string;
job: JobSummary;
job: JobStatusBucket;
}

export const DownloadButton = ({ getUrl, job }: Props) => {
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,12 +9,12 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobStatusBucket, ManagementLinkFn } from '../';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { JobSummary, ManagementLinkFn } from '../../common/types';

export const getFailureToast = (
errorText: string,
job: JobSummary,
job: JobStatusBucket,
getManagmenetLink: ManagementLinkFn
): ToastInput => {
return {
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,13 +7,14 @@
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobStatusBucket } 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';

export const getSuccessToast = (
job: JobSummary,
job: JobStatusBucket,
getReportLink: () => string,
getDownloadLink: (jobId: JobId) => string
): ToastInput => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobStatusBucket } 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';

export const getWarningFormulasToast = (
job: JobSummary,
job: JobStatusBucket,
getReportLink: () => string,
getDownloadLink: (jobId: JobId) => string
): ToastInput => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import { FormattedMessage } from '@kbn/i18n/react';
import React, { Fragment } from 'react';
import { ToastInput } from 'src/core/public';
import { JobStatusBucket } 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';

export const getWarningMaxSizeToast = (
job: JobSummary,
job: JobStatusBucket,
getReportLink: () => string,
getDownloadLink: (jobId: JobId) => string
): ToastInput => ({
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one still kinda bugs me, but understand why we have it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it would have been nice to map this differently from the beginning

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 JobStatusBucket {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed from JobSummary

id: JobId;
status: JobStatus;
title: string;
type: string;
maxSizeReached?: boolean;
csvContainsFormulas?: boolean;
}

export interface JobStatusBuckets {
completed: JobStatusBucket[];
failed: JobStatusBucket[];
}

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