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 display of local_metadata #65260

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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:

Choose a reason for hiding this comment

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

LOL i was expecting some black magic

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,21 @@ 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.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 ? (
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this to avoid a blink effect, every 30 seconds.

<FormattedMessage
id="xpack.ingestManager.agentList.loadingAgentsMessage"
defaultMessage="Loading agents…"
Expand Down