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 agents chart loading state #7120

Merged
merged 3 commits into from
Oct 24, 2024
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 @@ -29,6 +29,7 @@ All notable changes to the Wazuh app project will be documented in this file.

- Fixed read-only users could not access to Statistics application [#7001](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7001)
- Fixed no-agent-alert spawn with selected agent in agent-welcome view [#7029](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7029)
- Fixed loading state of the agents status chart in the home overview [#7120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7120)
- Fixed security policy exception when it contained deprecated actions [#7042](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7042)
- Fixed export formatted csv data with special characters from tables [#7048](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7048)
- Fixed column reordering feature [#7072](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7072)
Expand Down
4 changes: 3 additions & 1 deletion plugins/main/public/components/overview/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Overview: React.FC = withRouteResolvers({
savedSearch,
})(() => {
const [agentsCounts, setAgentsCounts] = useState<object>({});
const [isAgentsLoading, setIsAgentsLoading] = useState<boolean>(true);
const { tab = 'welcome', tabView = 'dashboard', agentId } = useRouterSearch();
const navigationService = NavigationService.getInstance();
const pinnedAgentManager = new PinnedAgentManager();
Expand Down Expand Up @@ -131,6 +132,7 @@ export const Overview: React.FC = withRouteResolvers({
},
} = await WzRequest.apiReq('GET', '/agents/summary/status', {});
setAgentsCounts(data);
setIsAgentsLoading(false);
} catch (error) {
return Promise.reject(error);
}
Expand Down Expand Up @@ -167,7 +169,7 @@ export const Overview: React.FC = withRouteResolvers({
<EuiPage paddingSize='l'>
<EuiFlexGroup direction='column'>
<EuiFlexItem>
<Stats {...agentsCounts} />
<Stats {...agentsCounts} isAgentsLoading={isAgentsLoading} />
</EuiFlexItem>
<EuiFlexItem>
<OverviewWelcome {...agentsCounts} />
Expand Down
82 changes: 49 additions & 33 deletions plugins/main/public/controllers/overview/components/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,39 @@ export const Stats = withErrorBoundary(
);
}

/**
* Calculate the size of the visualization evaluating if it renders the internal loading or the chart
* based on the viewport size
*/
getVisualizationSize() {
const normalLoadingSize = { width: 377, height: '150px' };
const mobileLoadingSize = {
height: '150px',
};
const loadingSize =
window.innerWidth < 768 ? mobileLoadingSize : normalLoadingSize;
const size = this.props.isAgentsLoading
? loadingSize
: { width: '100%', height: '150px' };
return size;
}

render() {
const { isAgentsLoading } = this.props;
const hasResults = this.agentStatus.some(
({ status }) => this.props[status],
);
const showAgentsChart = isAgentsLoading || hasResults;

return (
<EuiFlexGroup gutterSize='l'>
<EuiFlexItem grow={false}>
<EuiCard betaBadgeLabel='Agents summary' title=''>
{hasResults ? (
{showAgentsChart ? (
<VisualizationBasic
isLoading={this.state.loadingSummary}
isLoading={isAgentsLoading}
type='donut'
size={{ width: '100%', height: '150px' }}
size={this.getVisualizationSize()}
showLegend
data={this.agentStatus.map(
({ status, label, color, onClick }) => ({
Expand All @@ -107,36 +126,33 @@ export const Stats = withErrorBoundary(
)}
/>
) : (
!hasResults &&
this.props !== undefined && (
<EuiEmptyPrompt
body={
<p>
This instance has no agents registered.
<br />
Please deploy agents to begin monitoring your endpoints.
</p>
}
actions={
<WzButtonPermissions
color='primary'
fill
permissions={[
{ action: 'agent:create', resource: '*:*:*' },
]}
iconType='plusInCircle'
href={NavigationService.getInstance().getUrlForApp(
endpointSummary.id,
{
path: `#${endpointSummary.redirectTo()}deploy`,
},
)}
>
Deploy new agent
</WzButtonPermissions>
}
/>
)
<EuiEmptyPrompt
body={
<p>
This instance has no agents registered.
<br />
Please deploy agents to begin monitoring your endpoints.
</p>
}
actions={
<WzButtonPermissions
color='primary'
fill
permissions={[
{ action: 'agent:create', resource: '*:*:*' },
]}
iconType='plusInCircle'
href={NavigationService.getInstance().getUrlForApp(
endpointSummary.id,
{
path: `#${endpointSummary.redirectTo()}deploy`,
},
)}
>
Deploy new agent
</WzButtonPermissions>
}
/>
)}
</EuiCard>
</EuiFlexItem>
Expand Down
Loading