Skip to content

Commit

Permalink
[Reporting] Fix job completion notification to disappear after 24 hou…
Browse files Browse the repository at this point in the history
…rs (#133381) (#133409)

(cherry picked from commit 1e39a2c)

# Conflicts:
#	x-pack/plugins/reporting/public/lib/__snapshots__/stream_handler.test.ts.snap
#	x-pack/plugins/reporting/public/lib/stream_handler.ts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
dokmic and kibanamachine authored Jun 3, 2022
1 parent 8899b42 commit 4917dee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 41 deletions.

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

3 changes: 1 addition & 2 deletions x-pack/plugins/reporting/public/lib/stream_handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { omit } from 'lodash';
import sinon, { stub } from 'sinon';
import { NotificationsStart } from 'src/core/public';
import { coreMock } from '../../../../../src/core/public/mocks';
Expand Down Expand Up @@ -99,7 +98,7 @@ describe('stream handler', () => {
expect(mockShowDanger.callCount).toBe(0);
expect(mockShowSuccess.callCount).toBe(1);
expect(mockShowWarning.callCount).toBe(0);
expect(omit(mockShowSuccess.args[0][0], 'toastLifeTimeMs')).toMatchSnapshot();
expect(mockShowSuccess.args[0]).toMatchSnapshot();
done();
});
});
Expand Down
17 changes: 14 additions & 3 deletions x-pack/plugins/reporting/public/lib/stream_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import {
import { Job } from './job';
import { ReportingAPIClient } from './reporting_api_client';

/**
* @todo Replace with `Infinity` once elastic/eui#5945 is resolved.
* @see https://github.com/elastic/eui/issues/5945
*/
const COMPLETED_JOB_TOAST_TIMEOUT = 24 * 60 * 60 * 1000; // 24 hours

function updateStored(jobIds: JobId[]): void {
sessionStorage.setItem(JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JSON.stringify(jobIds));
}
Expand All @@ -47,6 +53,8 @@ export class ReportingNotifierStreamHandler {
failed: failedJobs,
}: JobSummarySet): Rx.Observable<JobSummarySet> {
const showNotificationsAsync = async () => {
const completedOptions = { toastLifeTimeMs: COMPLETED_JOB_TOAST_TIMEOUT };

// notifications with download link
for (const job of completedJobs) {
if (job.csvContainsFormulas) {
Expand All @@ -55,19 +63,22 @@ export class ReportingNotifierStreamHandler {
job,
this.apiClient.getManagementLink,
this.apiClient.getDownloadLink
)
),
completedOptions
);
} else if (job.maxSizeReached) {
this.notifications.toasts.addWarning(
getWarningMaxSizeToast(
job,
this.apiClient.getManagementLink,
this.apiClient.getDownloadLink
)
),
completedOptions
);
} else {
this.notifications.toasts.addSuccess(
getSuccessToast(job, this.apiClient.getManagementLink, this.apiClient.getDownloadLink)
getSuccessToast(job, this.apiClient.getManagementLink, this.apiClient.getDownloadLink),
completedOptions
);
}
}
Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/reporting/public/notifier/job_success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,5 @@ export const getSuccessToast = (
<DownloadButton getUrl={getDownloadLink} job={job} />
</Fragment>
),
/**
* If timeout is an Infinity value, a Not-a-Number (NaN) value, or negative, then timeout will be zero.
* And we cannot use `Number.MAX_SAFE_INTEGER` because EUI's Timer implementation
* subtracts it from the current time to evaluate the remainder.
* @see https://www.w3.org/TR/2011/WD-html5-20110525/timers.html
*/
toastLifeTimeMs: Number.MAX_SAFE_INTEGER - Date.now(),
'data-test-subj': 'completeReportSuccess',
});

0 comments on commit 4917dee

Please sign in to comment.