From 541bf07cf068dc90fd9ad429027edbc1f88477da Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Tue, 1 Oct 2024 11:56:46 +0200 Subject: [PATCH 1/8] Change agent summary render --- .../controllers/overview/components/stats.js | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/plugins/main/public/controllers/overview/components/stats.js b/plugins/main/public/controllers/overview/components/stats.js index 782e7c9638..4d82287683 100644 --- a/plugins/main/public/controllers/overview/components/stats.js +++ b/plugins/main/public/controllers/overview/components/stats.js @@ -10,7 +10,7 @@ * * Find more information about this on the LICENSE file. */ -import React, { Component } from 'react'; +import React, { Component, useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { EuiCard, @@ -18,6 +18,7 @@ import { EuiFlexGroup, EuiPage, EuiToolTip, + EuiEmptyPrompt, } from '@elastic/eui'; import { withErrorBoundary } from '../../../components/common/hocs'; import { API_NAME_AGENT_STATUS } from '../../../../common/constants'; @@ -30,6 +31,8 @@ import { LastAlertsStat } from './last-alerts-stat'; import { VisualizationBasic } from '../../../components/common/charts/visualizations/basic'; import NavigationService from '../../../react-services/navigation-service'; import './stats.scss'; +import { WzButtonPermissions } from '../../../components/common/permissions/button'; + export const Stats = withErrorBoundary( class Stats extends Component { constructor(props) { @@ -86,14 +89,13 @@ export const Stats = withErrorBoundary( - ({ onClick, label, @@ -103,11 +105,36 @@ export const Stats = withErrorBoundary( : 0, color, }), - ) - } - noDataTitle='No results' - noDataMessage='No results were found.' - /> + )} + /> + ) : ( + !hasResults && + !this.props === undefined && ( + No agents were added to the manager} + body={

Add agents to fleet to start monitoring

} + actions={ + + Deploy new agent + + } + /> + ) + )}
From a90ebbbb0bdce25e095c5f58198345354332df75 Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Tue, 1 Oct 2024 12:23:26 +0200 Subject: [PATCH 2/8] Added Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a25674f56..92413e6e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Update malware detection group values in data sources [#6963](https://github.com/wazuh/wazuh-dashboard-plugins/issues/6963) - Changed the registration id of the Settings application for compatibility with OpenSearch Dashboard 2.16.0 [#6938](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6938) - Changed Malware detection dashboard visualizations [#6964](https://github.com/wazuh/wazuh-dashboard-plugins/issues/6964) +- Changed the agents summary in overview with no results to an agent deployment help message. [#7041](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7041) ### Fixed From e786309b232e15deebfba76aa795efb2d8442e98 Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Tue, 1 Oct 2024 12:53:21 +0200 Subject: [PATCH 3/8] updated snaps --- .../__snapshots__/stats.test.tsx.snap | 47 ------------------- 1 file changed, 47 deletions(-) diff --git a/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap b/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap index 29b8d3d0da..297f31d58a 100644 --- a/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap +++ b/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap @@ -21,53 +21,6 @@ exports[`Stats component renders correctly to match the snapshot 1`] = ` class="euiTitle euiTitle--small euiCard__title" id="htmlIdTitle" /> -
-
-
- -
-

- No results -

- -
-
- No results were found. -
- -
-
-
Date: Tue, 1 Oct 2024 14:10:30 +0200 Subject: [PATCH 4/8] solve styles bug --- .../main/public/controllers/overview/components/stats.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/main/public/controllers/overview/components/stats.js b/plugins/main/public/controllers/overview/components/stats.js index 4d82287683..e8010bc352 100644 --- a/plugins/main/public/controllers/overview/components/stats.js +++ b/plugins/main/public/controllers/overview/components/stats.js @@ -10,7 +10,7 @@ * * Find more information about this on the LICENSE file. */ -import React, { Component, useEffect, useState } from 'react'; +import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { EuiCard, @@ -109,10 +109,8 @@ export const Stats = withErrorBoundary( /> ) : ( !hasResults && - !this.props === undefined && ( + this.props !== undefined && ( No agents were added to the manager} body={

Add agents to fleet to start monitoring

} actions={ Date: Tue, 1 Oct 2024 14:28:34 +0200 Subject: [PATCH 5/8] Update Snaps --- .../__snapshots__/stats.test.tsx.snap | 255 +----------------- 1 file changed, 1 insertion(+), 254 deletions(-) diff --git a/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap b/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap index 297f31d58a..a469dde9e4 100644 --- a/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap +++ b/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap @@ -1,256 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Stats component renders correctly to match the snapshot 1`] = ` -
-
-
-
-
-
- -
- - - Agents summary - - -
-
-
-
-
- -
-
-
- -
-
- -
-
- -
-
- -
-
-
-
- - - Last 24 hours alerts - - -
-
-
-
-
-`; +exports[`Stats component renders correctly to match the snapshot 1`] = `
`; From 1c7f567de130d4e76c41ab9c7e63291571115bd2 Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Wed, 2 Oct 2024 08:38:17 +0200 Subject: [PATCH 6/8] Move redirect url to a const --- .../controllers/overview/components/stats.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/main/public/controllers/overview/components/stats.js b/plugins/main/public/controllers/overview/components/stats.js index e8010bc352..affbdd2bf0 100644 --- a/plugins/main/public/controllers/overview/components/stats.js +++ b/plugins/main/public/controllers/overview/components/stats.js @@ -84,6 +84,14 @@ export const Stats = withErrorBoundary( const hasResults = this.agentStatus.some( ({ status }) => this.props[status], ); + + const addAgentUrl = NavigationService.getInstance().getUrlForApp( + endpointSummary.id, + { + path: `#${endpointSummary.redirectTo()}deploy`, + }, + ); + return ( @@ -120,12 +128,7 @@ export const Stats = withErrorBoundary( { action: 'agent:create', resource: '*:*:*' }, ]} iconType='plusInCircle' - href={NavigationService.getInstance().getUrlForApp( - endpointSummary.id, - { - path: `#${endpointSummary.redirectTo()}deploy`, - }, - )} + href={addAgentUrl} > Deploy new agent From 339f6973e50d5886858abce3ca7384a64fda9770 Mon Sep 17 00:00:00 2001 From: JuanGarriuz Date: Wed, 2 Oct 2024 12:09:40 +0200 Subject: [PATCH 7/8] Change deploy text --- .../main/public/controllers/overview/components/stats.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/main/public/controllers/overview/components/stats.js b/plugins/main/public/controllers/overview/components/stats.js index affbdd2bf0..612e17f939 100644 --- a/plugins/main/public/controllers/overview/components/stats.js +++ b/plugins/main/public/controllers/overview/components/stats.js @@ -119,7 +119,14 @@ export const Stats = withErrorBoundary( !hasResults && this.props !== undefined && ( Add agents to fleet to start monitoring

} + body={ +

+ This instance has no agents registered. +
+ Please deploy agents to begin monitoring your + endpoints. +

+ } actions={ Date: Wed, 2 Oct 2024 13:48:47 +0200 Subject: [PATCH 8/8] Solve test faillure --- .../__snapshots__/stats.test.tsx.snap | 307 +++++++++++++++++- .../controllers/overview/components/stats.js | 14 +- .../overview/components/stats.test.tsx | 31 ++ 3 files changed, 343 insertions(+), 9 deletions(-) diff --git a/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap b/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap index a469dde9e4..845f1dd350 100644 --- a/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap +++ b/plugins/main/public/controllers/overview/components/__snapshots__/stats.test.tsx.snap @@ -1,3 +1,308 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Stats component renders correctly to match the snapshot 1`] = `
`; +exports[`Stats component renders correctly to match the snapshot 1`] = ` +
+
+
+
+
+
+ +
+
+ +
+

+ This instance has no agents registered. +
+ Please deploy agents to begin monitoring your endpoints. +

+
+
+
+ +
+
+
+ + + Agents summary + + +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ + + Last 24 hours alerts + + +
+
+
+
+
+`; diff --git a/plugins/main/public/controllers/overview/components/stats.js b/plugins/main/public/controllers/overview/components/stats.js index 612e17f939..60d1c790bf 100644 --- a/plugins/main/public/controllers/overview/components/stats.js +++ b/plugins/main/public/controllers/overview/components/stats.js @@ -85,13 +85,6 @@ export const Stats = withErrorBoundary( ({ status }) => this.props[status], ); - const addAgentUrl = NavigationService.getInstance().getUrlForApp( - endpointSummary.id, - { - path: `#${endpointSummary.redirectTo()}deploy`, - }, - ); - return ( @@ -135,7 +128,12 @@ export const Stats = withErrorBoundary( { action: 'agent:create', resource: '*:*:*' }, ]} iconType='plusInCircle' - href={addAgentUrl} + href={NavigationService.getInstance().getUrlForApp( + endpointSummary.id, + { + path: `#${endpointSummary.redirectTo()}deploy`, + }, + )} > Deploy new agent diff --git a/plugins/main/public/controllers/overview/components/stats.test.tsx b/plugins/main/public/controllers/overview/components/stats.test.tsx index 0e03c26535..574fb4ac79 100644 --- a/plugins/main/public/controllers/overview/components/stats.test.tsx +++ b/plugins/main/public/controllers/overview/components/stats.test.tsx @@ -16,6 +16,37 @@ import React from 'react'; import { render, act } from '@testing-library/react'; import '@testing-library/jest-dom'; import { Stats } from './stats'; +import jsonBeautifier from '../../../utils/json-beautifier'; + +jest.mock('../../../react-services/navigation-service', () => { + return { + getInstance() { + return { + getUrlForApp() { + return ''; + }, + }; + }, + }; +}); + +jest.mock('../../../components/common/hooks/use-user-is-admin', () => { + return { + useUserPermissionsIsAdminRequirements() { + console.log('UserPermisionsIsAdmin'); + return ['', []]; + }, + }; +}); + +jest.mock('../../../components/common/hooks/useUserPermissions', () => { + return { + useUserPermissionsRequirements() { + console.log('UserPermisions'); + return [false, []]; + }, + }; +}); jest.mock( '../../../../../../node_modules/@elastic/eui/lib/services/accessibility/html_id_generator',