Skip to content

Commit

Permalink
Update copy and use fixed values for log level filter in agent logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Nov 23, 2020
1 parent 493381e commit 8eb3744
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,18 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { memo, useState, useEffect } from 'react';
import React, { memo, useState } from 'react';
import { EuiPopover, EuiFilterButton, EuiFilterSelectItem } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useStartServices } from '../../../../../hooks';
import { AGENT_LOG_INDEX_PATTERN, LOG_LEVEL_FIELD } from './constants';
import { AGENT_LOG_LEVELS } from './constants';

const LEVEL_VALUES = Object.values(AGENT_LOG_LEVELS);

export const LogLevelFilter: React.FunctionComponent<{
selectedLevels: string[];
onToggleLevel: (level: string) => void;
}> = memo(({ selectedLevels, onToggleLevel }) => {
const { data } = useStartServices();
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [levelValues, setLevelValues] = useState<string[]>([]);

useEffect(() => {
const fetchValues = async () => {
setIsLoading(true);
try {
const values = await data.autocomplete.getValueSuggestions({
indexPattern: {
title: AGENT_LOG_INDEX_PATTERN,
fields: [LOG_LEVEL_FIELD],
},
field: LOG_LEVEL_FIELD,
query: '',
});
setLevelValues(values.sort());
} catch (e) {
setLevelValues([]);
}
setIsLoading(false);
};
fetchValues();
}, [data.autocomplete]);

return (
<EuiPopover
Expand All @@ -46,8 +23,7 @@ export const LogLevelFilter: React.FunctionComponent<{
iconType="arrowDown"
onClick={() => setIsOpen(true)}
isSelected={isOpen}
isLoading={isLoading}
numFilters={levelValues.length}
numFilters={LEVEL_VALUES.length}
hasActiveFilters={selectedLevels.length > 0}
numActiveFilters={selectedLevels.length}
>
Expand All @@ -60,7 +36,7 @@ export const LogLevelFilter: React.FunctionComponent<{
closePopover={() => setIsOpen(false)}
panelPaddingSize="none"
>
{levelValues.map((level) => (
{LEVEL_VALUES.map((level) => (
<EuiFilterSelectItem
checked={selectedLevels.includes(level) ? 'on' : undefined}
key={level}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Agent } from '../../../../../types';
import { sendPostAgentAction, useStartServices } from '../../../../../hooks';
import { AGENT_LOG_LEVELS, DEFAULT_LOG_LEVEL } from './constants';

const LEVEL_VALUES = Object.values(AGENT_LOG_LEVELS);

export const SelectLogLevel: React.FC<{ agent: Agent }> = memo(({ agent }) => {
const { notifications } = useStartServices();
const [isLoading, setIsLoading] = useState(false);
Expand All @@ -38,15 +40,17 @@ export const SelectLogLevel: React.FC<{ agent: Agent }> = memo(({ agent }) => {
setAgentLogLevel(selectedLogLevel);
notifications.toasts.addSuccess(
i18n.translate('xpack.fleet.agentLogs.selectLogLevel.successText', {
defaultMessage: 'Changed agent logging level to "{logLevel}".',
defaultMessage: `Changed agent logging level to '{logLevel}'.`,
values: {
logLevel: selectedLogLevel,
},
})
);
} catch (error) {
notifications.toasts.addError(error, {
title: 'Error',
title: i18n.translate('xpack.fleet.agentLogs.selectLogLevel.errorTitleText', {
defaultMessage: 'Error updating agent logging level',
}),
});
}
setIsLoading(false);
Expand Down Expand Up @@ -74,12 +78,7 @@ export const SelectLogLevel: React.FC<{ agent: Agent }> = memo(({ agent }) => {
onChange={(event) => {
setSelectedLogLevel(event.target.value);
}}
options={[
{ text: AGENT_LOG_LEVELS.ERROR, value: AGENT_LOG_LEVELS.ERROR },
{ text: AGENT_LOG_LEVELS.WARNING, value: AGENT_LOG_LEVELS.WARNING },
{ text: AGENT_LOG_LEVELS.INFO, value: AGENT_LOG_LEVELS.INFO },
{ text: AGENT_LOG_LEVELS.DEBUG, value: AGENT_LOG_LEVELS.DEBUG },
]}
options={LEVEL_VALUES.map((level) => ({ text: level, value: level }))}
/>
</EuiFlexItem>
{agentLogLevel !== selectedLogLevel && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import React from 'react';
import { FormattedMessage, FormattedRelative } from '@kbn/i18n/react';
import { EuiHealth, EuiToolTip } from '@elastic/eui';
import { EuiHealth, EuiBadge, EuiToolTip } from '@elastic/eui';
import { Agent } from '../../../types';

interface Props {
Expand All @@ -14,9 +14,9 @@ interface Props {

const Status = {
Online: (
<EuiHealth color="success">
<FormattedMessage id="xpack.fleet.agentHealth.onlineStatusText" defaultMessage="Online" />
</EuiHealth>
<EuiBadge color="secondary">
<FormattedMessage id="xpack.fleet.agentHealth.healthyStatusText" defaultMessage="Healthy" />
</EuiBadge>
),
Offline: (
<EuiHealth color="subdued">
Expand Down Expand Up @@ -89,10 +89,9 @@ function getStatusComponent(agent: Agent): React.ReactElement {
}
}

export const AgentHealth: React.FunctionComponent<Props> = ({ agent }) => {
export const AgentHealth: React.FunctionComponent<Props> = ({ agent, ...props }) => {
const { last_checkin: lastCheckIn } = agent;
const msLastCheckIn = new Date(lastCheckIn || 0).getTime();

return (
<EuiToolTip
position="top"
Expand Down

0 comments on commit 8eb3744

Please sign in to comment.