Skip to content

Commit

Permalink
[Reporting] Fix copy issue in report notifications (#123607)
Browse files Browse the repository at this point in the history
* refactor constants to better group report types separately

* format

* update comment

* split report type and job type constants into separate files

* added prettyReportTypeName getter to Job

* use pretty name if it exists, otherwise fallback to whatever is in jobtype

* slight restructure to existing copy to make it sound more natural

* added basic test for pretty names

* another update to existing copy, this time for the warning notification

* slight update to make test clearer

* fixed i18n strings for error notification and refactored success for consistency

* removed previous copy

* updated snapshots

* remove old i18n

* incorporoated copy feedback

* updated snapshots
  • Loading branch information
jloleysens authored Jan 25, 2022
1 parent 7f5e6c3 commit 8a8a12a
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* 2.0.
*/

import * as reportTypes from './report_types';
import * as jobTypes from './job_types';

const { PDF_JOB_TYPE, PDF_JOB_TYPE_V2, PNG_JOB_TYPE, PNG_JOB_TYPE_V2 } = jobTypes;

export const PLUGIN_ID = 'reporting';

export const REPORTING_TRANSACTION_TYPE = PLUGIN_ID;
Expand Down Expand Up @@ -55,19 +60,15 @@ export const UI_SETTINGS_CSV_SEPARATOR = 'csv:separator';
export const UI_SETTINGS_CSV_QUOTE_VALUES = 'csv:quoteValues';
export const UI_SETTINGS_DATEFORMAT_TZ = 'dateFormat:tz';

// Export Type Definitions
export const CSV_REPORT_TYPE = 'CSV';
export const CSV_JOB_TYPE = 'csv_searchsource';
// Re-export type definitions here for convenience.
export * from './report_types';
export * from './job_types';

export const PDF_REPORT_TYPE = 'printablePdf';
export const PDF_REPORT_TYPE_V2 = 'printablePdfV2';
export const PDF_JOB_TYPE = 'printable_pdf';
export const PDF_JOB_TYPE_V2 = 'printable_pdf_v2';
type ReportTypeDeclaration = typeof reportTypes;
export type ReportTypes = ReportTypeDeclaration[keyof ReportTypeDeclaration];

export const PNG_REPORT_TYPE = 'PNG';
export const PNG_REPORT_TYPE_V2 = 'pngV2';
export const PNG_JOB_TYPE = 'PNG';
export const PNG_JOB_TYPE_V2 = 'PNGV2';
type JobTypeDeclaration = typeof jobTypes;
export type JobTypes = JobTypeDeclaration[keyof JobTypeDeclaration];

export const CSV_SEARCHSOURCE_IMMEDIATE_TYPE = 'csv_searchsource_immediate';

Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/reporting/common/constants/job_types.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 const CSV_JOB_TYPE = 'csv_searchsource';

export const PDF_JOB_TYPE = 'printable_pdf';
export const PDF_JOB_TYPE_V2 = 'printable_pdf_v2';

export const PNG_JOB_TYPE = 'PNG';
export const PNG_JOB_TYPE_V2 = 'PNGV2';
14 changes: 14 additions & 0 deletions x-pack/plugins/reporting/common/constants/report_types.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 const CSV_REPORT_TYPE = 'CSV';

export const PDF_REPORT_TYPE = 'printablePdf';
export const PDF_REPORT_TYPE_V2 = 'printablePdfV2';

export const PNG_REPORT_TYPE = 'PNG';
export const PNG_REPORT_TYPE_V2 = 'pngV2';

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

24 changes: 24 additions & 0 deletions x-pack/plugins/reporting/public/lib/job.test.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 { mockJobs } from '../../common/test';
import * as jobTypes from '../../common/constants/job_types';
import { Job } from './job';

describe('Job', () => {
it('should provide a pretty name for all known job types', () => {
for (const jobType of Object.values(jobTypes)) {
const job = new Job({ ...mockJobs[0], jobtype: jobType });
expect(job.prettyJobTypeName).toEqual(expect.any(String));
}
});

it('should provide "undefined" for unknown job types', () => {
const job = new Job({ ...mockJobs[0], jobtype: 'foo' });
expect(job.prettyJobTypeName).toBeUndefined();
});
});
25 changes: 23 additions & 2 deletions x-pack/plugins/reporting/public/lib/job.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { EuiText, EuiTextColor } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import React from 'react';
import { JOB_STATUSES } from '../../common/constants';
import {
import { JOB_STATUSES, JobTypes } from '../../common/constants';
import type {
BaseParamsV2,
JobId,
ReportApiJSON,
Expand Down Expand Up @@ -157,6 +157,27 @@ export class Job {
return this.status === JOB_STATUSES.COMPLETED || this.status === JOB_STATUSES.WARNINGS;
}

public get prettyJobTypeName(): undefined | string {
switch (this.jobtype as JobTypes) {
case 'printable_pdf':
case 'printable_pdf_v2':
return i18n.translate('xpack.reporting.jobType.pdfOutputName', {
defaultMessage: 'PDF',
});
case 'PNG':
case 'PNGV2':
return i18n.translate('xpack.reporting.jobType.pngOutputName', {
defaultMessage: 'PNG',
});
case 'csv_searchsource':
return i18n.translate('xpack.reporting.jobType.csvOutputName', {
defaultMessage: 'CSV',
});
default:
return undefined;
}
}

public get prettyTimeout(): string {
if (this.timeout == null) {
return i18n.translate('xpack.reporting.jobStatusDetail.timeoutSecondsUnknown', {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/public/lib/stream_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getReportStatus(src: Job): JobSummary {
id: src.id,
status: src.status,
title: src.title,
jobtype: src.jobtype,
jobtype: src.prettyJobTypeName ?? src.jobtype,
maxSizeReached: src.max_size_reached,
csvContainsFormulas: src.csv_contains_formulas,
};
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/reporting/public/notifier/job_failure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import React, { Fragment } from 'react';
import { ThemeServiceStart, ToastInput } from 'src/core/public';
import { toMountPoint } from '../../../../../src/plugins/kibana_react/public';
import { JobSummary, ManagementLinkFn } from '../../common/types';
import type { JobSummary, ManagementLinkFn } from '../../common/types';

export const getFailureToast = (
errorText: string,
Expand All @@ -23,8 +23,8 @@ export const getFailureToast = (
title: toMountPoint(
<FormattedMessage
id="xpack.reporting.publicNotifier.error.couldNotCreateReportTitle"
defaultMessage="Could not create report for {reportObjectType} '{reportObjectTitle}'."
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
defaultMessage="Cannot create {reportType} report for '{reportObjectTitle}'."
values={{ reportType: job.jobtype, reportObjectTitle: job.title }}
/>,
{ theme$: theme.theme$ }
),
Expand All @@ -47,13 +47,13 @@ export const getFailureToast = (
<p>
<FormattedMessage
id="xpack.reporting.publicNotifier.error.checkManagement"
defaultMessage="More information is available at {path}."
defaultMessage="Go to {path} for details."
values={{
path: (
<a href={getManagmenetLink()}>
<FormattedMessage
id="xpack.reporting.publicNotifier.error.reportingSectionUrlLinkLabel"
defaultMessage="Management &gt; Kibana &gt; Reporting"
defaultMessage="Stack Management &gt; Kibana &gt; Reporting"
/>
</a>
),
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/reporting/public/notifier/job_success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const getSuccessToast = (
title: toMountPoint(
<FormattedMessage
id="xpack.reporting.publicNotifier.successfullyCreatedReportNotificationTitle"
defaultMessage="Created report for {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
defaultMessage="{reportType} created for '{reportObjectTitle}'"
values={{ reportType: job.jobtype, reportObjectTitle: job.title }}
/>,
{ theme$: theme.theme$ }
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const getWarningFormulasToast = (
title: toMountPoint(
<FormattedMessage
id="xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportTitle"
defaultMessage="Report may contain formulas {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
defaultMessage="{reportType} may contain formulas"
values={{ reportType: job.jobtype }}
/>,
{ theme$: theme.theme$ }
),
Expand All @@ -32,7 +32,8 @@ export const getWarningFormulasToast = (
<p>
<FormattedMessage
id="xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportMessage"
defaultMessage="The report contains characters which spreadsheet applications can interpret as formulas."
defaultMessage="The report '{reportObjectTitle}' contains characters which spreadsheet applications can interpret as formulas."
values={{ reportObjectTitle: job.title }}
/>
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const getWarningMaxSizeToast = (
title: toMountPoint(
<FormattedMessage
id="xpack.reporting.publicNotifier.maxSizeReached.partialReportTitle"
defaultMessage="Created partial report for {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.jobtype, reportObjectTitle: job.title }}
defaultMessage="Created partial {reportType} for '{reportObjectTitle}'"
values={{ reportType: job.jobtype, reportObjectTitle: job.title }}
/>,
{ theme$: theme.theme$ }
),
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/reporting/public/notifier/report_link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interface Props {

export const ReportLink = ({ getUrl }: Props) => (
<FormattedMessage
id="xpack.reporting.publicNotifier.reportLink.pickItUpFromPathDescription"
defaultMessage="Pick it up from {path}."
id="xpack.reporting.publicNotifier.reportLinkDescription"
defaultMessage="Download it now, or get it later in {path}."
values={{
path: (
<a href={getUrl()}>
Expand Down
6 changes: 0 additions & 6 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -19998,21 +19998,15 @@
"xpack.reporting.panelContent.unsavedStateErrorTitle": "保存されていない作業内容",
"xpack.reporting.pdfFooterImageDescription": "PDFのフッターに使用するカスタム画像です",
"xpack.reporting.pdfFooterImageLabel": "PDFフッター画像",
"xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportMessage": "レポートには、スプレッドシートアプリケーションで式と解釈される可能性のある文字が含まれています。",
"xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportTitle": "レポートには式{reportObjectType} '{reportObjectTitle}'が含まれている場合があります",
"xpack.reporting.publicNotifier.downloadReportButtonLabel": "レポートをダウンロード",
"xpack.reporting.publicNotifier.error.calloutTitle": "レポートジョブが失敗しました",
"xpack.reporting.publicNotifier.error.checkManagement": "詳細については、{path}を参照してください。",
"xpack.reporting.publicNotifier.error.couldNotCreateReportTitle": "{reportObjectType}「{reportObjectTitle}」のレポートを作成できませんでした。",
"xpack.reporting.publicNotifier.error.reportingSectionUrlLinkLabel": "管理 > Kibana > レポート",
"xpack.reporting.publicNotifier.error.tryRefresh": "ページを更新してみてください。",
"xpack.reporting.publicNotifier.httpErrorMessage": "レポートジョブステータスを確認できませんでした",
"xpack.reporting.publicNotifier.maxSizeReached.partialReportDescription": "レポートが最大サイズに達し、部分データが含まれています。",
"xpack.reporting.publicNotifier.maxSizeReached.partialReportTitle": "{reportObjectType}「{reportObjectTitle}」の部分レポートが作成されました",
"xpack.reporting.publicNotifier.pollingErrorMessage": "レポート通知エラー",
"xpack.reporting.publicNotifier.reportLink.pickItUpFromPathDescription": "{path}から開始します。",
"xpack.reporting.publicNotifier.reportLink.reportingSectionUrlLinkLabel": "スタック管理 > アラートとインサイト > レポート",
"xpack.reporting.publicNotifier.successfullyCreatedReportNotificationTitle": "{reportObjectType}「{reportObjectTitle}」のレポートが作成されました",
"xpack.reporting.redirectApp.errorTitle": "リダイレクトエラー",
"xpack.reporting.redirectApp.redirectConsoleErrorPrefixLabel": "リダイレクトページエラー:",
"xpack.reporting.registerFeature.reportingDescription": "Discover、可視化、ダッシュボードから生成されたレポートを管理します。",
Expand Down
6 changes: 0 additions & 6 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -20289,21 +20289,15 @@
"xpack.reporting.panelContent.unsavedStateErrorTitle": "未保存的工作",
"xpack.reporting.pdfFooterImageDescription": "要在 PDF 的页脚中使用的定制图像",
"xpack.reporting.pdfFooterImageLabel": "PDF 页脚图像",
"xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportMessage": "报告包含电子表格应用程序可解释为公式的字符。",
"xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportTitle": "报告可能包含公式 {reportObjectType} '{reportObjectTitle}'",
"xpack.reporting.publicNotifier.downloadReportButtonLabel": "下载报告",
"xpack.reporting.publicNotifier.error.calloutTitle": "报告作业失败",
"xpack.reporting.publicNotifier.error.checkManagement": "更多信息位于 {path}。",
"xpack.reporting.publicNotifier.error.couldNotCreateReportTitle": "无法为 {reportObjectType} '{reportObjectTitle}' 创建报告。",
"xpack.reporting.publicNotifier.error.reportingSectionUrlLinkLabel": "管理 > Kibana > Reporting",
"xpack.reporting.publicNotifier.error.tryRefresh": "请尝试刷新页面。",
"xpack.reporting.publicNotifier.httpErrorMessage": "无法检查 Reporting 作业状态!",
"xpack.reporting.publicNotifier.maxSizeReached.partialReportDescription": "报告已达到最大大小,仅包含部分数据。",
"xpack.reporting.publicNotifier.maxSizeReached.partialReportTitle": "已为 {reportObjectType} '{reportObjectTitle}' 创建部分报告",
"xpack.reporting.publicNotifier.pollingErrorMessage": "报告通知器错误!",
"xpack.reporting.publicNotifier.reportLink.pickItUpFromPathDescription": "从 {path} 中提取。",
"xpack.reporting.publicNotifier.reportLink.reportingSectionUrlLinkLabel": "“堆栈管理”>“告警和洞见”>“报告”",
"xpack.reporting.publicNotifier.successfullyCreatedReportNotificationTitle": "已为 {reportObjectType}“{reportObjectTitle}”创建报告",
"xpack.reporting.redirectApp.errorTitle": "重定向错误",
"xpack.reporting.redirectApp.redirectConsoleErrorPrefixLabel": "重定向页面错误:",
"xpack.reporting.registerFeature.reportingDescription": "管理您从 Discover、Visualize 和 Dashboard 生成的报告。",
Expand Down

0 comments on commit 8a8a12a

Please sign in to comment.