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

[Fleet] Fix displaying agent status bar with no agents #156541

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import { createFleetTestRendererMock } from '../../../../../../mock';

import { AgentStatusBar } from './status_bar';

describe('AgentStatusBar', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test!

it('should render the status bar if there is some agent displayed', () => {
const renderer = createFleetTestRendererMock();
const res = renderer.render(
<AgentStatusBar
agentStatus={
{
healthy: 10,
inactive: 0,
offline: 0,
} as any
}
/>
);
expect(res.queryByTestId('agentStatusBar')).not.toBeNull();
});

it('should not render the status bar if there is no agent displayed', () => {
const renderer = createFleetTestRendererMock();
const res = renderer.render(
<AgentStatusBar
agentStatus={
{
healthy: 0,
inactive: 0,
offline: 0,
} as any
}
/>
);
expect(res.queryByTestId('agentStatusBar')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import styled from 'styled-components';
import { EuiColorPaletteDisplay } from '@elastic/eui';
import { EuiColorPaletteDisplay, EuiSpacer } from '@elastic/eui';
import React, { useMemo } from 'react';

import { AGENT_STATUSES, getColorForAgentStatus } from '../../services/agent_status';
Expand Down Expand Up @@ -35,13 +35,30 @@ export const AgentStatusBar: React.FC<{
return acc;
}, [] as Array<{ stop: number; color: string }>);
}, [agentStatus]);

// const totalAgents = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgotten comment? :D

// return AGENT_STATUSES.reduce((acc, status) => {
// const previousStop = acc.length > 0 ? acc[acc.length - 1].stop : 0;
// acc.push({
// stop: previousStop + (agentStatus[status] || 0),
// color: getColorForAgentStatus(status),
// });
// return acc;
// }, 0);
// }, [agentStatus]);

const hasNoAgent = palette[palette.length - 1].stop === 0;

if (hasNoAgent) {
return <EuiSpacer size="s" />;
}

return (
<>
<StyledEuiColorPaletteDisplay
className="ingest-agent-status-bar"
size="s"
palette={palette}
/>
</>
<StyledEuiColorPaletteDisplay
data-test-subj="agentStatusBar"
className="ingest-agent-status-bar"
size="s"
palette={palette}
/>
);
};