Skip to content

Commit

Permalink
Add create report definition (#7091)
Browse files Browse the repository at this point in the history
* Add create report definition

* rename file and remove console.log

* Add template body

* Create report definition when creating dashboard by reference

* Add button to reset report definition

* Add modal restart definition

* Add changelog
  • Loading branch information
yenienserrano authored Oct 17, 2024
1 parent 052d464 commit 4868eba
Show file tree
Hide file tree
Showing 9 changed files with 1,138 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"diffEditor.ignoreTrimWhitespace": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.inlineSuggest.enabled": true,
"editor.insertSpaces": true,
"editor.minimap.enabled": true,
"editor.rulers": [80, 100],
"editor.tabSize": 2,
"editor.trimAutoWhitespace": true,
"editor.wordWrap": "on",
"explorer.confirmDelete": true,
"files.autoSave": "off",
"javascript.updateImportsOnFileMove.enabled": "always",
"typescript.updateImportsOnFileMove.enabled": "always"
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file.
### Added

- Support for Wazuh 5.0.0
- Added creation of report definition when creating dashboard by reference and the button to reset the report [#7091](https:/wazuh/wazuh-dashboard-plugins/pull/7091)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import {
withVulnerabilitiesStateDataSource,
createDashboard,
} from '../../../../common/hocs/validate-states-index-pattern-and-dashboards';
import { SavedObject } from '../../../../../react-services';
import { SavedObject, ToastNotifications } from '../../../../../react-services';
import { EuiButton } from '@elastic/eui';
import { reportingDefinitions } from '../../../../../react-services/reporting/reporting-definitions';
import { vulnerabilityDetectionDashboardReport } from '../../../../../react-services/reporting/dashboards-generate-reports';
import { WzButtonPermissionsModalConfirm } from '../../../../common/buttons';

const DashboardByRenderer =
getPlugins().dashboard.DashboardContainerByValueRenderer;
Expand Down Expand Up @@ -139,11 +142,59 @@ const DashboardComponent = () => {
}
};

const handleRestartReportDefinition = async () => {
try {
ToastNotifications.add({
title: 'Restarting report definition...',
color: 'primary',
});
await reportingDefinitions.overrideReportDefinition(
vulnerabilityDetectionDashboardReport.idDashboardByReference,
);
ToastNotifications.success({
title: 'Report definition restarted successfully.',
});
} catch (error) {
ToastNotifications.error(
'plugins/main/public/components/overview/poc/dashboards/overview/dashboard.tsx',
error,
);
}
ToastNotifications;
};

return (
<>
{idDashboard ? (
<>
<EuiButton onClick={handleRestart}>Restart</EuiButton>
<WzButtonPermissionsModalConfirm
permissions={[
{
action: 'cluster:admin/opendistro/reports/definition/create',
resource: '*:*:*',
},
{
action: 'cluster:admin/opendistro/reports/definition/update',
resource: '*:*:*',
},
]}
className='wz-margin-10'
onConfirm={handleRestartReportDefinition}
modalTitle='Do you want to restart the report definition?'
tooltip={{
content:
'This will restart the definition of the report to the default',
position: 'top',
}}
modalProps={{
confirmButtonDisabled: false,
cancelButtonDisabled: false,
defaultFocusedButton: 'confirm',
}}
>
Restart report definition
</WzButtonPermissionsModalConfirm>
<DashboardSavedObject key={idDashboard} savedObjectId={idDashboard} />
</>
) : isLoading ? (
Expand Down
1 change: 1 addition & 0 deletions plugins/main/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { Applications, Categories } from './utils/applications';
import { euiPaletteColorBlind } from '@elastic/eui';
import NavigationService from './react-services/navigation-service';
import { createHashHistory } from 'history';
import { reportingDefinitions } from './react-services/reporting/reporting-definitions';

export class WazuhPlugin
implements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface DashboardGenerateReport {
idDashboardByReference: string;
titleReport: string;
}

export const vulnerabilityDetectionDashboardReport: DashboardGenerateReport = {
idDashboardByReference: '94febc80-55a2-11ef-a580-5b5ba88681be',
titleReport: 'Vulnerability Detection Dashboard Report',
};

export const DASHBOARDS_GENERATE_REPORTS: Array<DashboardGenerateReport> = [
vulnerabilityDetectionDashboardReport,
];
Loading

0 comments on commit 4868eba

Please sign in to comment.