Skip to content

Commit

Permalink
[Fleet] Fix display of local_metadata (elastic#65260)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed May 5, 2020
1 parent 3d1024c commit 72963d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export const AgentDetailsContent: React.FunctionComponent<{
title: i18n.translate('xpack.ingestManager.agentDetails.hostNameLabel', {
defaultMessage: 'Host name',
}),
description: agent.local_metadata['host.hostname'],
description:
typeof agent.local_metadata.host === 'object' &&
typeof agent.local_metadata.host.hostname === 'string'
? agent.local_metadata.host.hostname
: '-',
},
{
title: i18n.translate('xpack.ingestManager.agentDetails.hostIdLabel', {
Expand Down Expand Up @@ -60,13 +64,22 @@ export const AgentDetailsContent: React.FunctionComponent<{
title: i18n.translate('xpack.ingestManager.agentDetails.versionLabel', {
defaultMessage: 'Agent version',
}),
description: agent.local_metadata['agent.version'],
description:
typeof agent.local_metadata.elastic === 'object' &&
typeof agent.local_metadata.elastic.agent === 'object' &&
typeof agent.local_metadata.elastic.agent.version === 'string'
? agent.local_metadata.elastic.agent.version
: '-',
},
{
title: i18n.translate('xpack.ingestManager.agentDetails.platformLabel', {
defaultMessage: 'Platform',
}),
description: agent.local_metadata['os.platform'],
description:
typeof agent.local_metadata.os === 'object' &&
typeof agent.local_metadata.os.platform === 'string'
? agent.local_metadata.os.platform
: '-',
},
].map(({ title, description }) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export const AgentDetailsPage: React.FunctionComponent = () => {
<EuiFlexItem>
<EuiText>
<h1>
{agentData?.item?.local_metadata['host.hostname'] || (
{typeof agentData?.item?.local_metadata?.host === 'object' &&
typeof agentData?.item?.local_metadata?.host?.hostname === 'string' ? (
agentData.item.local_metadata.host.hostname
) : (
<FormattedMessage
id="xpack.ingestManager.agentDetails.agentDetailsTitle"
defaultMessage="Agent '{id}'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ const RowActions = React.memo<{ agent: Agent; onReassignClick: () => void; refre
}
);

function safeMetadata(val: any) {
if (typeof val !== 'string') {
return '-';
}
return val;
}

export const AgentListPage: React.FunctionComponent<{}> = () => {
const defaultKuery: string = (useUrlParams().urlParams.kuery as string) || '';
const hasWriteCapabilites = useCapabilities().write;
Expand Down Expand Up @@ -238,13 +245,13 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {

const columns = [
{
field: 'local_metadata.host',
field: 'local_metadata.host.hostname',
name: i18n.translate('xpack.ingestManager.agentList.hostColumnTitle', {
defaultMessage: 'Host',
}),
render: (host: string, agent: Agent) => (
<ConnectedLink color="primary" path={`${FLEET_AGENT_DETAIL_PATH}${agent.id}`}>
{agent.local_metadata['host.hostname'] || host || ''}
{safeMetadata(host)}
</ConnectedLink>
),
},
Expand Down Expand Up @@ -308,13 +315,12 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
},
},
{
field: 'local_metadata.version',
field: 'local_metadata.elastic.agent.version',
width: '100px',
name: i18n.translate('xpack.ingestManager.agentList.versionTitle', {
defaultMessage: 'Version',
}),
render: (version: string, agent: Agent) =>
agent.local_metadata['agent.version'] || version || '',
render: (version: string, agent: Agent) => safeMetadata(version),
},
{
field: 'last_checkin',
Expand Down Expand Up @@ -505,7 +511,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
loading={isLoading && agentsRequest.isInitialRequest}
hasActions={true}
noItemsMessage={
isLoading ? (
isLoading && agentsRequest.isInitialRequest ? (
<FormattedMessage
id="xpack.ingestManager.agentList.loadingAgentsMessage"
defaultMessage="Loading agents…"
Expand Down

0 comments on commit 72963d6

Please sign in to comment.