Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when changing api in agent preview of endpoints summary #6802

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added HAProxy helper settings to cluster configuration [#6653](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6653)
- Added ability to open the report file or Reporting application from the toast message [#6558](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6558)
- Added support for agents to Office 365 [#6558](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6558)
- Added pinned agent data validation when rendering the Inventory data, Stats and Configuration tabs in Agent preview of Endpoints Summary [#6800](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6800)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,43 @@ export const setBreadcrumbs = (breadcrumbs, router) => {
if (breadcrumbs === '' || breadcrumbs === undefined) {
return;
}
const breadcrumbsCustom = breadcrumbs?.map(breadcrumb =>
breadcrumb.agent
? {
className:
'euiLink euiLink--subdued osdBreadcrumbs wz-vertical-align-middle',
onClick: ev => {
ev.stopPropagation();
if (getWzCurrentAppID() === endpointSummary.id) {
NavigationService.getInstance().navigate(
`/agents?tab=welcome&agent=${breadcrumb.agent.id}`,
);
} else {
NavigationService.getInstance().navigateToApp(
endpointSummary.id,
{
path: `#/agents?tab=welcome&agent=${breadcrumb.agent.id}`,
},
);
}
const breadcrumbsCustom = breadcrumbs
?.map(breadcrumb =>
breadcrumb?.agent?.id
? {
className:
'euiLink euiLink--subdued osdBreadcrumbs wz-vertical-align-middle',
onClick: ev => {
ev.stopPropagation();
if (getWzCurrentAppID() === endpointSummary.id) {
NavigationService.getInstance().navigate(
`/agents?tab=welcome&agent=${breadcrumb.agent.id}`,
);
} else {
NavigationService.getInstance().navigateToApp(
endpointSummary.id,
{
path: `#/agents?tab=welcome&agent=${breadcrumb.agent.id}`,
},
);
}
},
truncate: true,
text: breadcrumb.agent.name,
}
: /*
Some use cases cause get Breadcrumbs to have the agent property
undefined. In this case a null is added and then with the filter it
is filtered
*/
typeof breadcrumb.agent !== 'undefined'
? null
: {
...breadcrumb,
className: 'osdBreadcrumbs',
},
truncate: true,
text: breadcrumb.agent.name,
}
: {
...breadcrumb,
className: 'osdBreadcrumbs',
},
);
)
.filter(value => value);

getCore().chrome.setBreadcrumbs(breadcrumbsCustom);

Expand Down
16 changes: 3 additions & 13 deletions plugins/main/public/components/common/modules/main-agent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import React, { Component, Fragment } from 'react';
import {
EuiFlexGroup,
EuiFlexItem,
EuiCallOut,
EuiTitle,
EuiButtonEmpty,
} from '@elastic/eui';
Expand Down Expand Up @@ -106,7 +105,6 @@ export class MainModuleAgent extends Component {

render() {
const { agent, section, selectView } = this.props;
const title = this.renderTitle();
const ModuleTabView = (this.props.tabs || []).find(
tab => tab.id === selectView,
);
Expand All @@ -118,11 +116,11 @@ export class MainModuleAgent extends Component {
: 'wz-module'
}
>
<div className='wz-module-header-agent-wrapper'>
<div className='wz-module-header-agent'>{title}</div>
</div>
{agent && agent.os && (
<Fragment>
<div className='wz-module-header-agent-wrapper'>
<div className='wz-module-header-agent'>{this.renderTitle()}</div>
</div>
<div>
<div
className={
Expand Down Expand Up @@ -186,14 +184,6 @@ export class MainModuleAgent extends Component {
)}
</Fragment>
)}
{(!agent || !agent.os) && (
<EuiCallOut
style={{ margin: '66px 16px 0 16px' }}
title='This agent has never connected'
color='warning'
iconType='alert'
></EuiCallOut>
)}
</div>
);
}
Expand Down
28 changes: 1 addition & 27 deletions plugins/main/public/components/common/welcome/agents-welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
EuiToolTip,
EuiButtonIcon,
EuiPageBody,
EuiLink,
} from '@elastic/eui';
import {
FimEventsTable,
Expand All @@ -43,10 +42,7 @@ import { withErrorBoundary, withGlobalBreadcrumb, withGuard } from '../hocs';
import { compose } from 'redux';
import { API_NAME_AGENT_STATUS } from '../../../../common/constants';
import { WAZUH_MODULES } from '../../../../common/wazuh-modules';
import {
PromptAgentNeverConnected,
PromptNoSelectedAgent,
} from '../../agents/prompts';
import { PromptAgentNeverConnected } from '../../agents/prompts';
import { WzButton } from '../buttons';
import {
Applications,
Expand Down Expand Up @@ -83,28 +79,6 @@ export const AgentsWelcome = compose(
: []),
];
}),
withGuard(
props => !(props.agent && props.agent.id),
() => (
<>
<PromptNoSelectedAgent
body={
<>
You need to select an agent or return to
<RedirectAppLinks application={getCore().application}>
<EuiLink
aria-label='go to Endpoint summary'
href={`${endpointSummary.id}#/agents-preview`}
>
Endpoint summary
</EuiLink>
</RedirectAppLinks>
</>
}
/>
</>
),
),
withGuard(
props => props.agent.status === API_NAME_AGENT_STATUS.NEVER_CONNECTED,
PromptAgentNeverConnected,
Expand Down
68 changes: 52 additions & 16 deletions plugins/main/public/components/endpoints-summary/agent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, { useState, useEffect } from 'react';
import { EuiPage, EuiPageBody, EuiProgress } from '@elastic/eui';
import { EuiPage, EuiPageBody, EuiProgress, EuiLink } from '@elastic/eui';
import { AgentsWelcome } from '../../common/welcome/agents-welcome';
import { Agent } from '../types';
import { MainSyscollector } from '../../agents/syscollector/main';
import { MainAgentStats } from '../../agents/stats';
import WzManagementConfiguration from '../../../controllers/management/components/management/configuration/configuration-main.js';
import { withErrorBoundary, withRouteResolvers } from '../../common/hocs';
import {
withErrorBoundary,
withGuard,
withRouteResolvers,
} from '../../common/hocs';
import { compose } from 'redux';
import { PinnedAgentManager } from '../../wz-agent-selector/wz-agent-selector-service';
import { MainModuleAgent } from '../../common/modules/main-agent';
Expand All @@ -18,11 +22,46 @@ import {
import { useRouterSearch } from '../../common/hooks/use-router-search';
import { Redirect, Route, Switch } from '../../router-search';
import NavigationService from '../../../react-services/navigation-service';
import { connect } from 'react-redux';
import { PromptNoSelectedAgent } from '../../agents/prompts';
import { RedirectAppLinks } from '../../../../../../src/plugins/opensearch_dashboards_react/public';
import { getCore } from '../../../kibana-services';
import { endpointSummary } from '../../../utils/applications';

const mapStateToProps = state => ({
agent: state.appStateReducers?.currentAgentData,
});

export const AgentView = compose(
withErrorBoundary,
withRouteResolvers({ enableMenu, ip, nestedResolve, savedSearch }),
)(() => {
connect(mapStateToProps),
withGuard(
props => !(props.agent && props.agent.id),
() => (
<>
<PromptNoSelectedAgent
body={
<>
You need to select an agent or return to
<RedirectAppLinks application={getCore().application}>
<EuiLink
aria-label='go to Endpoint summary'
href={`${endpointSummary.id}#/agents-preview`}
onClick={() =>
NavigationService.getInstance().navigate(`/agents-preview`)
}
>
Endpoint summary
</EuiLink>
</RedirectAppLinks>
</>
}
/>
</>
),
),
)(({ agent: agentData }) => {
const { tab = 'welcome' } = useRouterSearch();
const navigationService = NavigationService.getInstance();

Expand All @@ -35,23 +74,20 @@ export const AgentView = compose(

const pinnedAgentManager = new PinnedAgentManager();

const [agent, setAgent] = useState<Agent>();
const [isLoadingAgent, setIsLoadingAgent] = useState(true);

const getAgent = async () => {
const syncAgent = async () => {
setIsLoadingAgent(true);
await pinnedAgentManager.syncPinnedAgentSources();
const isPinnedAgent = pinnedAgentManager.isPinnedAgent();
setAgent(isPinnedAgent ? pinnedAgentManager.getPinnedAgent() : null);
setIsLoadingAgent(false);
};

useEffect(() => {
getAgent();
syncAgent();
}, [tab]);

const switchTab = (tab: string) => {
navigationService.navigate(`/agents?tab=${tab}&agent=${agent?.id}`);
navigationService.navigate(`/agents?tab=${tab}&agent=${agentData?.id}`);
};

if (isLoadingAgent) {
Expand All @@ -67,21 +103,21 @@ export const AgentView = compose(
return (
<Switch>
<Route path='?tab=syscollector'>
<MainModuleAgent agent={agent} section={tab} />
<MainSyscollector agent={agent} />
<MainModuleAgent agent={agentData} section={tab} />
<MainSyscollector agent={agentData} />
</Route>
<Route path='?tab=stats'>
<MainModuleAgent agent={agent} section={tab} />
<MainAgentStats agent={agent} />
<MainModuleAgent agent={agentData} section={tab} />
<MainAgentStats agent={agentData} />
</Route>
<Route path='?tab=configuration'>
<MainModuleAgent agent={agent} section={tab} />
<WzManagementConfiguration agent={agent} />
<MainModuleAgent agent={agentData} section={tab} />
<WzManagementConfiguration agent={agentData} />
</Route>
<Route path='?tab=welcome'>
<AgentsWelcome
switchTab={switchTab}
agent={agent}
agent={agentData}
pinAgent={pinnedAgentManager.pinAgent}
unPinAgent={pinnedAgentManager.unPinAgent}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ export class PinnedAgentManager {
const includesAgentViewURL = this.navigationService
.getPathname()
.includes(this.AGENT_VIEW_URL);
const params = this.navigationService.getParams();

const urlSearchParams = this.navigationService.getParams();

urlSearchParams.set(
params.set(
includesAgentViewURL
? PinnedAgentManager.AGENT_ID_VIEW_KEY
: PinnedAgentManager.AGENT_ID_URL_VIEW_KEY,
String(agentData?.id),
);
this.navigationService.renewURL(urlSearchParams);
this.navigationService.renewURL(params);
}

unPinAgent(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*
* Find more information about this on the LICENSE file.
*/

import WzConfigurationSwitch from './configuration-switch';
import {
withErrorBoundary,
Expand All @@ -23,7 +22,7 @@ export default compose(
withErrorBoundary,
withGlobalBreadcrumb(props => {
let breadcrumb = false;
if (props.agent.id === '000') {
if (props.agent?.id === '000') {
breadcrumb = [{ text: settings.breadcrumbLabel }];
} else {
breadcrumb = [
Expand Down
Loading