From 8a8a12aa7eb79e2770a8c081f49b4a5d692b4502 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Tue, 25 Jan 2022 11:48:07 +0100 Subject: [PATCH] [Reporting] Fix copy issue in report notifications (#123607) * 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 --- .../{constants.ts => constants/index.ts} | 23 ++++++++------- .../reporting/common/constants/job_types.ts | 14 +++++++++ .../common/constants/report_types.ts | 14 +++++++++ .../__snapshots__/stream_handler.test.ts.snap | 29 ++++++++++--------- .../plugins/reporting/public/lib/job.test.ts | 24 +++++++++++++++ x-pack/plugins/reporting/public/lib/job.tsx | 25 ++++++++++++++-- .../reporting/public/lib/stream_handler.ts | 2 +- .../reporting/public/notifier/job_failure.tsx | 10 +++---- .../reporting/public/notifier/job_success.tsx | 4 +-- .../public/notifier/job_warning_formulas.tsx | 7 +++-- .../public/notifier/job_warning_max_size.tsx | 4 +-- .../reporting/public/notifier/report_link.tsx | 4 +-- .../translations/translations/ja-JP.json | 6 ---- .../translations/translations/zh-CN.json | 6 ---- 14 files changed, 119 insertions(+), 53 deletions(-) rename x-pack/plugins/reporting/common/{constants.ts => constants/index.ts} (89%) create mode 100644 x-pack/plugins/reporting/common/constants/job_types.ts create mode 100644 x-pack/plugins/reporting/common/constants/report_types.ts create mode 100644 x-pack/plugins/reporting/public/lib/job.test.ts diff --git a/x-pack/plugins/reporting/common/constants.ts b/x-pack/plugins/reporting/common/constants/index.ts similarity index 89% rename from x-pack/plugins/reporting/common/constants.ts rename to x-pack/plugins/reporting/common/constants/index.ts index 2d2f0d41fc8c2..b8cf8a27d7fb4 100644 --- a/x-pack/plugins/reporting/common/constants.ts +++ b/x-pack/plugins/reporting/common/constants/index.ts @@ -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; @@ -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'; diff --git a/x-pack/plugins/reporting/common/constants/job_types.ts b/x-pack/plugins/reporting/common/constants/job_types.ts new file mode 100644 index 0000000000000..b11391d81fa14 --- /dev/null +++ b/x-pack/plugins/reporting/common/constants/job_types.ts @@ -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'; diff --git a/x-pack/plugins/reporting/common/constants/report_types.ts b/x-pack/plugins/reporting/common/constants/report_types.ts new file mode 100644 index 0000000000000..baa9153e1a819 --- /dev/null +++ b/x-pack/plugins/reporting/common/constants/report_types.ts @@ -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'; diff --git a/x-pack/plugins/reporting/public/lib/__snapshots__/stream_handler.test.ts.snap b/x-pack/plugins/reporting/public/lib/__snapshots__/stream_handler.test.ts.snap index 9c72de2bf0ed8..46b5556827070 100644 --- a/x-pack/plugins/reporting/public/lib/__snapshots__/stream_handler.test.ts.snap +++ b/x-pack/plugins/reporting/public/lib/__snapshots__/stream_handler.test.ts.snap @@ -33,9 +33,13 @@ Array [ "reactNode":

@@ -59,12 +63,11 @@ Array [ }, "title": MountPoint { "reactNode": , @@ -92,7 +95,7 @@ Array [

@@ -113,12 +116,12 @@ Array [ }, "title": MountPoint { "reactNode": , @@ -161,12 +164,12 @@ Array [ }, "title": MountPoint { "reactNode": , @@ -202,12 +205,12 @@ Array [ }, "title": MountPoint { "reactNode": , diff --git a/x-pack/plugins/reporting/public/lib/job.test.ts b/x-pack/plugins/reporting/public/lib/job.test.ts new file mode 100644 index 0000000000000..8e6ebe51cc66d --- /dev/null +++ b/x-pack/plugins/reporting/public/lib/job.test.ts @@ -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(); + }); +}); diff --git a/x-pack/plugins/reporting/public/lib/job.tsx b/x-pack/plugins/reporting/public/lib/job.tsx index 99c609bfe607f..5cae9108f57ac 100644 --- a/x-pack/plugins/reporting/public/lib/job.tsx +++ b/x-pack/plugins/reporting/public/lib/job.tsx @@ -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, @@ -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', { diff --git a/x-pack/plugins/reporting/public/lib/stream_handler.ts b/x-pack/plugins/reporting/public/lib/stream_handler.ts index 27e220221156e..e9645f3bb8735 100644 --- a/x-pack/plugins/reporting/public/lib/stream_handler.ts +++ b/x-pack/plugins/reporting/public/lib/stream_handler.ts @@ -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, }; diff --git a/x-pack/plugins/reporting/public/notifier/job_failure.tsx b/x-pack/plugins/reporting/public/notifier/job_failure.tsx index 87fbc72d29ab8..0f858333dae18 100644 --- a/x-pack/plugins/reporting/public/notifier/job_failure.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_failure.tsx @@ -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, @@ -23,8 +23,8 @@ export const getFailureToast = ( title: toMountPoint( , { theme$: theme.theme$ } ), @@ -47,13 +47,13 @@ export const getFailureToast = (

), diff --git a/x-pack/plugins/reporting/public/notifier/job_success.tsx b/x-pack/plugins/reporting/public/notifier/job_success.tsx index f949c27f6fedb..76170a8a6c2c4 100644 --- a/x-pack/plugins/reporting/public/notifier/job_success.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_success.tsx @@ -22,8 +22,8 @@ export const getSuccessToast = ( title: toMountPoint( , { theme$: theme.theme$ } ), diff --git a/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx b/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx index 08c87a40a829a..ae1d61b7bd4bf 100644 --- a/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_warning_formulas.tsx @@ -22,8 +22,8 @@ export const getWarningFormulasToast = ( title: toMountPoint( , { theme$: theme.theme$ } ), @@ -32,7 +32,8 @@ export const getWarningFormulasToast = (

diff --git a/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx b/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx index 629ac44adeae8..6e3a68a9beee3 100644 --- a/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx +++ b/x-pack/plugins/reporting/public/notifier/job_warning_max_size.tsx @@ -22,8 +22,8 @@ export const getWarningMaxSizeToast = ( title: toMountPoint( , { theme$: theme.theme$ } ), diff --git a/x-pack/plugins/reporting/public/notifier/report_link.tsx b/x-pack/plugins/reporting/public/notifier/report_link.tsx index e202cab8b3c90..9c3518163e5f4 100644 --- a/x-pack/plugins/reporting/public/notifier/report_link.tsx +++ b/x-pack/plugins/reporting/public/notifier/report_link.tsx @@ -14,8 +14,8 @@ interface Props { export const ReportLink = ({ getUrl }: Props) => ( diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index e4577914163be..7cfc68edcf7d8 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -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、可視化、ダッシュボードから生成されたレポートを管理します。", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 2995e97ffc1c8..75e4803b48353 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -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 生成的报告。",