Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Backport from dev branch #289

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions kibana-reports/.cypress/integration/01-create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ describe('Cypress', () => {
// enter a report description
cy.get('#reportSettingsDescription').type('Description for cypress test');

// select a report source
cy.get('.euiComboBox').click({ force: true });

// create an on-demand report definition
cy.get('#createNewReportDefinition').click({ force: true });
});
Expand Down
2 changes: 1 addition & 1 deletion kibana-reports/.cypress/integration/04-download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Cypress', () => {
// create an on-demand report definition
cy.get('#createNewReportDefinition').click({ force: true });

cy.wait(5000);
cy.wait(10000);

// visit the details page of the newly created on-demand definition
cy.get('#reportDefinitionDetailsLink').first().click();
Expand Down
1 change: 1 addition & 0 deletions kibana-reports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@types/dompurify": "^2.0.4",
"@types/jsdom": "^16.2.4",
"@types/react-addons-test-utils": "^0.14.25",
"async-mutex": "^0.2.6",
"babel-polyfill": "^6.26.0",
"cheerio": "^1.0.0-rc.3",
"cron-validator": "^1.1.1",
Expand Down
2 changes: 2 additions & 0 deletions kibana-reports/public/components/context_menu/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ const generateInContextReport = (
} else {
if (response.status === 403) {
addSuccessOrFailureToast('permissionsFailure');
} else if (response.status === 503) {
addSuccessOrFailureToast('timeoutFailure', reportSource);
} else {
addSuccessOrFailureToast('failure');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const displayLoadingModal = () => {
}
};

export const addSuccessOrFailureToast = (status) => {
export const addSuccessOrFailureToast = (status, reportSource) => {
const generateToast = document.querySelectorAll('.euiGlobalToastList');
if (generateToast) {
try {
Expand All @@ -101,6 +101,14 @@ export const addSuccessOrFailureToast = (status) => {
setTimeout(function () {
document.getElementById('reportFailureToast').style.display = 'none';
}, 6000);
} else if (status === 'timeoutFailure') {
generateInProgressToast.innerHTML = reportGenerationFailure(
'Error generating report.',
`Timed out generating on-demand report from ${reportSource}. Try again later.`
);
setTimeout(function () {
document.getElementById('reportFailureToast').style.display = 'none';
}, 6000);
} else if (status === 'permissionsFailure') {
generateInProgressToast.innerHTML = permissionsMissingOnGeneration();
setTimeout(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ export const reportGenerationSuccess = () => {
`
}

export const reportGenerationFailure = () => {
export const reportGenerationFailure = (
title = 'Download error',
text = 'There was an error generating this report.'
) => {
return `
<div class="euiToast euiToast--danger" id="reportFailureToast">
<p class="euiScreenReaderOnly">A new notification appears</p>
Expand All @@ -259,7 +262,7 @@ export const reportGenerationFailure = () => {
role="img" aria-hidden="true">
<path fill-rule="evenodd" d="M7.59 10.059L7.35 5.18h1.3L8.4 10.06h-.81zm.394 1.901a.61.61 0 01-.448-.186.606.606 0 01-.186-.444c0-.174.062-.323.186-.446a.614.614 0 01.448-.184c.169 0 .315.06.44.182.124.122.186.27.186.448a.6.6 0 01-.189.446.607.607 0 01-.437.184zM2 14a1 1 0 01-.878-1.479l6-11a1 1 0 011.756 0l6 11A1 1 0 0114 14H2zm0-1h12L8 2 2 13z"></path>
</svg>
<span class="euiToastHeader__title">Download error</span>
<span class="euiToastHeader__title">${title}</span>
</div>
<button type="button" class="euiToast__closeButton" aria-label="Dismiss toast" id="closeReportFailureToast"
data-test-subj="toastCloseButton">
Expand All @@ -269,7 +272,7 @@ export const reportGenerationFailure = () => {
</svg>
</button>
<div class="euiText euiText--small euiToastBody">
<p>There was an error generating this report.</p>
<p>${text}</p>
</div>
</div>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,28 @@ describe('main_utils tests', () => {
handleErrorToast
);
});

test('test generateReportById timeout error handling', async () => {
expect.assertions(1);
const reportId = '1';
const handleSuccessToast = jest.fn();
const handleErrorToast = jest.fn();
const handlePermissionsMissingToast = jest.fn();

httpClientMock.get.mockReturnValue(
Promise.reject({ body: { statusCode: 503 } })
);

await generateReportById(
reportId,
httpClientMock,
handleSuccessToast,
handleErrorToast,
handlePermissionsMissingToast
);
expect(handleErrorToast).toHaveBeenCalledWith(
'Error generating report.',
'Timed out generating report ID 1. Try again later.'
);
});
});
9 changes: 5 additions & 4 deletions kibana-reports/public/components/main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,19 @@ export function Main(props) {
addReportDefinitionsTableErrorToastHandler(errorType);
};

const addErrorOnDemandDownloadToastHandler = () => {
const addErrorOnDemandDownloadToastHandler = (title = 'Error downloading report.', text = '') => {
const errorToast = {
title: 'Error downloading report.',
title,
text,
color: 'danger',
iconType: 'alert',
id: 'onDemandDownloadErrorToast',
};
setToasts(toasts.concat(errorToast));
};

const handleOnDemandDownloadErrorToast = () => {
addErrorOnDemandDownloadToastHandler();
const handleOnDemandDownloadErrorToast = (title?: string, text?: string) => {
addErrorOnDemandDownloadToastHandler(title, text);
};

const addSuccessOnDemandDownloadToastHandler = () => {
Expand Down
5 changes: 5 additions & 0 deletions kibana-reports/public/components/main/main_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ export const generateReportById = async (
console.log('error on generating report by id:', error);
if (error.body.statusCode === 403) {
handlePermissionsMissingToast();
} else if (error.body.statusCode === 503) {
handleErrorToast(
'Error generating report.',
`Timed out generating report ID ${reportId}. Try again later.`
);
} else {
handleErrorToast();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,19 @@ export function ReportDetails(props) {
addPermissionsMissingDownloadToastHandler();
}

const addErrorToastHandler = () => {
const addErrorToastHandler = (title = 'Error loading report details.', text = '') => {
const errorToast = {
title: 'Error loading report details.',
title,
text,
color: 'danger',
iconType: 'alert',
id: 'reportDetailsErrorToast',
};
setToasts(toasts.concat(errorToast));
};

const handleErrorToast = () => {
addErrorToastHandler();
const handleErrorToast = (title?: string, text?: string) => {
addErrorToastHandler(title, text);
};

const addSuccessToastHandler = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ export function CreateReport(props) {
settingsReportNameErrorMessage,
setSettingsReportNameErrorMessage,
] = useState('');
const [
showSettingsReportSourceError,
setShowSettingsReportSourceError
] = useState(false);
const [
settingsReportSourceErrorMessage,
setSettingsReportSourceErrorMessage
] = useState('');
const [
showTriggerIntervalNaNError,
setShowTriggerIntervalNaNError,
Expand Down Expand Up @@ -213,7 +221,6 @@ export function CreateReport(props) {
timeRange: timeRangeParams
) => {
const { httpClient } = props;

//TODO: need better handle
if (
metadata.trigger.trigger_type === 'On demand' &&
Expand All @@ -228,6 +235,8 @@ export function CreateReport(props) {
error,
setShowSettingsReportNameError,
setSettingsReportNameErrorMessage,
setShowSettingsReportSourceError,
setSettingsReportSourceErrorMessage,
setShowTriggerIntervalNaNError,
timeRange,
setShowTimeRangeError,
Expand Down Expand Up @@ -307,6 +316,8 @@ export function CreateReport(props) {
timeRange={timeRange}
showSettingsReportNameError={showSettingsReportNameError}
settingsReportNameErrorMessage={settingsReportNameErrorMessage}
showSettingsReportSourceError={showSettingsReportSourceError}
settingsReportSourceErrorMessage={settingsReportSourceErrorMessage}
showTimeRangeError={showTimeRangeError}
/>
<EuiSpacer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ export function EditReportDefinition(props) {
settingsReportNameErrorMessage,
setSettingsReportNameErrorMessage,
] = useState('');
const [
showSettingsReportSourceError,
setShowSettingsReportSourceError
] = useState(false);
const [
settingsReportSourceErrorMessage,
setSettingsReportSourceErrorMessage
] = useState('');
const [
showTriggerIntervalNaNError,
setShowTriggerIntervalNaNError,
Expand Down Expand Up @@ -216,6 +224,8 @@ export function EditReportDefinition(props) {
error,
setShowSettingsReportNameError,
setSettingsReportNameErrorMessage,
setShowSettingsReportSourceError,
setSettingsReportSourceErrorMessage,
setShowTriggerIntervalNaNError,
timeRange,
setShowTimeRangeError,
Expand Down Expand Up @@ -294,6 +304,8 @@ export function EditReportDefinition(props) {
timeRange={timeRange}
showSettingsReportNameError={showSettingsReportNameError}
settingsReportNameErrorMessage={settingsReportNameErrorMessage}
showSettingsReportSourceError={showSettingsReportSourceError}
settingsReportSourceErrorMessage={settingsReportSourceErrorMessage}
showTimeRangeError={showTimeRangeError}
/>
<EuiSpacer />
Expand Down
Loading