diff --git a/CHANGELOG.md b/CHANGELOG.md index cc557c2785..5a4d889c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Added try catch strategy with ErrorOrchestrator service on Management > Ruleset [#3410](https://github.com/wazuh/wazuh-kibana-app/pull/3410) - Added try catch strategy with ErrorOrchestrator service on Overview [#3408](https://github.com/wazuh/wazuh-kibana-app/pull/3408) - Added try catch strategy with ErrorOrchestrator service on ManagementController [#3374](https://github.com/wazuh/wazuh-kibana-app/pull/3374) +- Added try catch strategy with ErrorOrchestrator service on Management > Reporting [#3427](https://github.com/wazuh/wazuh-kibana-app/pull/3427) - Added try catch strategy with ErrorOrchestrator service on FIM & SCA sections [#3417](https://github.com/wazuh/wazuh-kibana-app/pull/3417) ### Changed diff --git a/public/controllers/management/components/management/reporting/__snapshots__/reporting-main.test.tsx.snap b/public/controllers/management/components/management/reporting/__snapshots__/reporting-main.test.tsx.snap new file mode 100644 index 0000000000..7e4c4c48a2 --- /dev/null +++ b/public/controllers/management/components/management/reporting/__snapshots__/reporting-main.test.tsx.snap @@ -0,0 +1,962 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Reporting component renders correctly to match the snapshot 1`] = ` + + + + + +
+ +
+ +
+ +
+ +
+ +
+ +

+ Reporting +

+
+
+
+
+
+
+
+ + + +
+ + + +
+
+
+
+
+
+ +
+ +
+ +
+ +
+ From here you can check all your reports. +
+
+
+
+
+
+
+
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + + +
+
+ + + + +
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+ +
+ +
+ + +
+ +
+ + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > + +
+
+ + + +
+
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ + + Actions + + +
+
+
+ +
+
+
+
+
+ +
+ +
+ + +
+ +
+ +
+ +
+ + + + + +`; diff --git a/public/controllers/management/components/management/reporting/reporting-main.test.tsx b/public/controllers/management/components/management/reporting/reporting-main.test.tsx new file mode 100644 index 0000000000..9c097e8eb8 --- /dev/null +++ b/public/controllers/management/components/management/reporting/reporting-main.test.tsx @@ -0,0 +1,33 @@ +/* + * Wazuh app - React test for Reporting component. + * + * Copyright (C) 2015-2021 Wazuh, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Find more information about this on the LICENSE file. + * + */ + +import React from 'react'; +import { mount } from 'enzyme'; +import WzReporting from './reporting-main'; + +jest.mock('../../../../../kibana-services', () => ({ + getAngularModule: jest.fn(), + getHttp: () => ({ + basePath: { + prepend: (str) => str, + }, + }), +})); + +describe('Reporting component', () => { + it('renders correctly to match the snapshot', () => { + const wrapper = mount(); + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/controllers/management/components/management/reporting/reporting-table.js b/public/controllers/management/components/management/reporting/reporting-table.js index d01d2847b7..504f50e9fc 100644 --- a/public/controllers/management/components/management/reporting/reporting-table.js +++ b/public/controllers/management/components/management/reporting/reporting-table.js @@ -10,32 +10,31 @@ * Find more information about this on the LICENSE file. */ import React, { Component } from 'react'; -import { - EuiInMemoryTable, - EuiCallOut, - EuiOverlayMask, - EuiConfirmModal -} from '@elastic/eui'; +import { EuiInMemoryTable, EuiCallOut, EuiOverlayMask, EuiConfirmModal } from '@elastic/eui'; import { connect } from 'react-redux'; import ReportingHandler from './utils/reporting-handler'; -import { getToasts } from '../../../../../kibana-services'; +import { getToasts } from '../../../../../kibana-services'; import { updateIsProcessing, updateShowModal, - updateListItemsForRemove + updateListItemsForRemove, } from '../../../../../redux/actions/reportingActions'; import ReportingColums from './utils/columns-main'; +import { UI_ERROR_SEVERITIES } from '../../../../../react-services/error-orchestrator/types'; +import { UI_LOGGER_LEVELS } from '../../../../../../common/constants'; +import { getErrorOrchestrator } from '../../../../../react-services/common-services'; + class WzReportingTable extends Component { _isMounted = false; constructor(props) { super(props); this.state = { items: [], - isLoading: false + isLoading: false, }; this.reportingHandler = ReportingHandler; @@ -47,8 +46,22 @@ class WzReportingTable extends Component { } async componentDidUpdate() { - if (this.props.state.isProcessing && this._isMounted) { - await this.getItems(); + try { + if (this.props.state.isProcessing && this._isMounted) { + await this.getItems(); + } + } catch (error) { + const options = { + context: `${WzReportingTable.name}.componentDidUpdate`, + level: UI_LOGGER_LEVELS.ERROR, + severity: UI_ERROR_SEVERITIES.BUSINESS, + error: { + error: error, + message: error.message || error, + title: error.name || error, + }, + }; + getErrorOrchestrator().handleError(options); } } @@ -65,12 +78,12 @@ class WzReportingTable extends Component { const items = ((rawItems || {}).data || {}).reports || []; this.setState({ items, - isProcessing: false + isProcessing: false, }); this.props.updateIsProcessing(false); } catch (error) { this.props.updateIsProcessing(false); - return Promise.reject(error); + throw error; } } @@ -81,11 +94,30 @@ class WzReportingTable extends Component { const columns = this.reportingColumns.columns; const message = isLoading ? null : 'No results...'; + const deleteReport = (itemList) => { + try { + this.deleteReport(itemList); + this.props.updateShowModal(false); + } catch (error) { + const options = { + context: `${WzReportingTable.name}.deleteReport`, + level: UI_LOGGER_LEVELS.ERROR, + severity: UI_ERROR_SEVERITIES.BUSINESS, + error: { + error: error, + message: error.message || error, + title: `${error.name}: Error deleting report`, + }, + }; + getErrorOrchestrator().handleError(options); + } + }; + const sorting = { sort: { field: 'date', - direction: 'desc' - } + direction: 'desc', + }, }; if (!error) { @@ -106,10 +138,7 @@ class WzReportingTable extends Component { this.props.updateShowModal(false)} - onConfirm={() => { - this.deleteReport(itemList); - this.props.updateShowModal(false); - }} + onConfirm={() => deleteReport(itemList)} cancelButtonText="Cancel" confirmButtonText="Delete" defaultFocusedButton="cancel" @@ -129,39 +158,36 @@ class WzReportingTable extends Component { color: color, title: title, text: text, - toastLifeTimeMs: time + toastLifeTimeMs: time, }); }; async deleteReport(items) { - const results = items.map(async (item, i) => { - await this.reportingHandler.deleteReport(item.name); - }); - - Promise.all(results).then(completed => { + try { + const results = items.map(async (item, i) => { + await this.reportingHandler.deleteReport(item.name); + }); + await Promise.all(results); this.props.updateIsProcessing(true); this.showToast('success', 'Success', 'Deleted successfully', 3000); - }); + } catch (error) { + throw error; + } } } -const mapStateToProps = state => { +const mapStateToProps = (state) => { return { - state: state.reportingReducers + state: state.reportingReducers, }; }; -const mapDispatchToProps = dispatch => { +const mapDispatchToProps = (dispatch) => { return { - updateIsProcessing: isProcessing => - dispatch(updateIsProcessing(isProcessing)), - updateShowModal: showModal => dispatch(updateShowModal(showModal)), - updateListItemsForRemove: itemList => - dispatch(updateListItemsForRemove(itemList)) + updateIsProcessing: (isProcessing) => dispatch(updateIsProcessing(isProcessing)), + updateShowModal: (showModal) => dispatch(updateShowModal(showModal)), + updateListItemsForRemove: (itemList) => dispatch(updateListItemsForRemove(itemList)), }; }; -export default connect( - mapStateToProps, - mapDispatchToProps -)(WzReportingTable); +export default connect(mapStateToProps, mapDispatchToProps)(WzReportingTable); diff --git a/public/controllers/management/components/management/reporting/utils/actions-buttons-main.js b/public/controllers/management/components/management/reporting/utils/actions-buttons-main.js index 028f6c03e1..31b84b830c 100644 --- a/public/controllers/management/components/management/reporting/utils/actions-buttons-main.js +++ b/public/controllers/management/components/management/reporting/utils/actions-buttons-main.js @@ -17,6 +17,10 @@ import { connect } from 'react-redux'; import { updateIsProcessing } from '../../../../../../redux/actions/reportingActions'; +import { UI_ERROR_SEVERITIES } from '../../../../../../react-services/error-orchestrator/types'; +import { UI_LOGGER_LEVELS } from '../../../../../../../common/constants'; +import { getErrorOrchestrator } from '../../../../../../react-services/common-services'; + class WzReportingActionButtons extends Component { _isMounted = false; @@ -41,7 +45,17 @@ class WzReportingActionButtons extends Component { try { this.props.updateIsProcessing(true); } catch (error) { - return Promise.reject(error); + const options = { + context: `${WzReportingActionButtons.name}.refresh`, + level: UI_LOGGER_LEVELS.ERROR, + severity: UI_ERROR_SEVERITIES.UI, + error: { + error: error, + message: error.message || error, + title: error.name || error, + }, + }; + getErrorOrchestrator().handleError(options); } } diff --git a/public/controllers/management/components/management/reporting/utils/reporting-handler.js b/public/controllers/management/components/management/reporting/utils/reporting-handler.js index c276a0d710..3fa15dae82 100644 --- a/public/controllers/management/components/management/reporting/utils/reporting-handler.js +++ b/public/controllers/management/components/management/reporting/utils/reporting-handler.js @@ -22,7 +22,7 @@ export default class ReportingHandler { const result = await WzRequest.genericReq('GET', '/reports', {}); return result; } catch (error) { - return Promise.reject(error); + throw error; } } @@ -39,7 +39,7 @@ export default class ReportingHandler { ); return result; } catch (error) { - return Promise.reject(error); + throw error; } } }