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][Eui Visual Refresh] Make agent status colors theme aware #204070

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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
* 2.0.
*/

import { EuiFlexGroup, EuiHealth, EuiNotificationBadge, EuiFlexItem } from '@elastic/eui';
import {
EuiFlexGroup,
EuiHealth,
EuiNotificationBadge,
EuiFlexItem,
useEuiTheme,
} from '@elastic/eui';
import React, { memo } from 'react';

import {
Expand All @@ -31,9 +37,10 @@ export const AgentStatusBadges: React.FC<{

const AgentStatusBadge: React.FC<{ status: SimplifiedAgentStatus; count: number }> = memo(
({ status, count }) => {
const { euiTheme } = useEuiTheme();
return (
<>
<EuiHealth color={getColorForAgentStatus(status)}>
<EuiHealth color={getColorForAgentStatus(status, euiTheme)}>
<EuiFlexGroup alignItems="center" gutterSize="s">
<EuiFlexItem grow={false}>{getLabelForAgentStatus(status)}</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

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

import { AGENT_STATUSES, getColorForAgentStatus } from '../../services/agent_status';
Expand All @@ -25,16 +25,17 @@ const StyledEuiColorPaletteDisplay = styled(EuiColorPaletteDisplay)`
export const AgentStatusBar: React.FC<{
agentStatus: { [k in SimplifiedAgentStatus]: number };
}> = ({ agentStatus }) => {
const { euiTheme } = useEuiTheme();
const palette = useMemo(() => {
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),
color: getColorForAgentStatus(status, euiTheme),
});
return acc;
}, [] as Array<{ stop: number; color: string }>);
}, [agentStatus]);
}, [agentStatus, euiTheme]);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,11 @@
* 2.0.
*/

import { euiPaletteColorBlindBehindText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { euiLightVars } from '@kbn/ui-theme';

import type { SimplifiedAgentStatus } from '../../../types';
import type { EuiThemeComputed } from '@elastic/eui-theme-common';

const visColors = euiPaletteColorBlindBehindText();
const colorToHexMap = {
// using variables as mentioned here https://elastic.github.io/eui/#/guidelines/getting-started
default: euiLightVars.euiColorLightShade,
primary: visColors[1],
success: visColors[0],
accent: visColors[2],
warning: visColors[5],
danger: visColors[9],
inactive: euiLightVars.euiColorDarkShade,
lightest: euiLightVars.euiColorDisabled,
};
import type { SimplifiedAgentStatus } from '../../../types';

export const AGENT_STATUSES: SimplifiedAgentStatus[] = [
'healthy',
Expand All @@ -33,20 +20,23 @@ export const AGENT_STATUSES: SimplifiedAgentStatus[] = [
'unenrolled',
];

export function getColorForAgentStatus(agentStatus: SimplifiedAgentStatus): string {
export function getColorForAgentStatus(
agentStatus: SimplifiedAgentStatus,
euiTheme: EuiThemeComputed<{}>
): string {
switch (agentStatus) {
case 'healthy':
return colorToHexMap.success;
return euiTheme.colors.backgroundFilledSuccess;
case 'offline':
return colorToHexMap.default;
return euiTheme.colors.lightShade;
case 'inactive':
return colorToHexMap.inactive;
return euiTheme.colors.darkShade;
case 'unhealthy':
return colorToHexMap.warning;
return euiTheme.colors.backgroundFilledWarning;
case 'updating':
return colorToHexMap.primary;
return euiTheme.colors.backgroundFilledPrimary;
case 'unenrolled':
return colorToHexMap.lightest;
return euiTheme.colors.backgroundBaseDisabled;
default:
throw new Error(`Unsupported Agent status ${agentStatus}`);
}
Expand Down
Loading