-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Update agent listing for better status reporting #84798
Merged
nchaulet
merged 7 commits into
elastic:master
from
nchaulet:feature-update-agent-listing-status
Dec 10, 2020
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b0dc70d
[Fleet] Update agent listing for better status reporting
nchaulet f9ab1bd
Fix translations
nchaulet 6d8e515
Move the agent list search bar and filters outside of the main component
nchaulet cefc4ec
Add isInitialRequest
nchaulet c8605ee
Merge branch 'master' of github.com:elastic/kibana into feature-updat…
nchaulet 8cef749
Merge branch 'master' into feature-update-agent-listing-status
kibanamachine b157073
Fix after review
nchaulet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,33 +4,21 @@ | |||||||||||||||||||
* you may not use this file except in compliance with the Elastic License. | ||||||||||||||||||||
*/ | ||||||||||||||||||||
|
||||||||||||||||||||
import React, { useState, useEffect } from 'react'; | ||||||||||||||||||||
import { IFieldType } from 'src/plugins/data/public'; | ||||||||||||||||||||
// @ts-ignore | ||||||||||||||||||||
import { EuiSuggest, EuiSuggestItemProps } from '@elastic/eui'; | ||||||||||||||||||||
import { i18n } from '@kbn/i18n'; | ||||||||||||||||||||
import { useDebounce, useStartServices } from '../hooks'; | ||||||||||||||||||||
import React, { useState, useEffect, useMemo } from 'react'; | ||||||||||||||||||||
import { | ||||||||||||||||||||
QueryStringInput, | ||||||||||||||||||||
IFieldType, | ||||||||||||||||||||
esKuery, | ||||||||||||||||||||
} from '../../../../../../../src/plugins/data/public'; | ||||||||||||||||||||
import { useStartServices } from '../hooks'; | ||||||||||||||||||||
import { INDEX_NAME, AGENT_SAVED_OBJECT_TYPE } from '../constants'; | ||||||||||||||||||||
|
||||||||||||||||||||
const DEBOUNCE_SEARCH_MS = 150; | ||||||||||||||||||||
const HIDDEN_FIELDS = [`${AGENT_SAVED_OBJECT_TYPE}.actions`]; | ||||||||||||||||||||
|
||||||||||||||||||||
interface Suggestion { | ||||||||||||||||||||
label: string; | ||||||||||||||||||||
description: string; | ||||||||||||||||||||
value: string; | ||||||||||||||||||||
type: { | ||||||||||||||||||||
color: string; | ||||||||||||||||||||
iconType: string; | ||||||||||||||||||||
}; | ||||||||||||||||||||
start: number; | ||||||||||||||||||||
end: number; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
interface Props { | ||||||||||||||||||||
value: string; | ||||||||||||||||||||
fieldPrefix: string; | ||||||||||||||||||||
onChange: (newValue: string) => void; | ||||||||||||||||||||
onChange: (newValue: string, submit?: boolean) => void; | ||||||||||||||||||||
placeholder?: string; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
|
@@ -40,135 +28,74 @@ export const SearchBar: React.FunctionComponent<Props> = ({ | |||||||||||||||||||
onChange, | ||||||||||||||||||||
placeholder, | ||||||||||||||||||||
}) => { | ||||||||||||||||||||
const { suggestions } = useSuggestions(fieldPrefix, value); | ||||||||||||||||||||
|
||||||||||||||||||||
// TODO fix type when correctly typed in EUI | ||||||||||||||||||||
const onAutocompleteClick = (suggestion: any) => { | ||||||||||||||||||||
onChange( | ||||||||||||||||||||
[value.slice(0, suggestion.start), suggestion.value, value.slice(suggestion.end, -1)].join('') | ||||||||||||||||||||
); | ||||||||||||||||||||
}; | ||||||||||||||||||||
// TODO fix type when correctly typed in EUI | ||||||||||||||||||||
const onChangeSearch = (e: any) => { | ||||||||||||||||||||
onChange(e.value); | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
return ( | ||||||||||||||||||||
<EuiSuggest | ||||||||||||||||||||
// TODO fix when correctly typed | ||||||||||||||||||||
// @ts-ignore | ||||||||||||||||||||
value={value} | ||||||||||||||||||||
icon={'search'} | ||||||||||||||||||||
placeholder={ | ||||||||||||||||||||
placeholder || | ||||||||||||||||||||
i18n.translate('xpack.fleet.defaultSearchPlaceholderText', { | ||||||||||||||||||||
defaultMessage: 'Search', | ||||||||||||||||||||
}) | ||||||||||||||||||||
} | ||||||||||||||||||||
onInputChange={onChangeSearch} | ||||||||||||||||||||
onItemClick={onAutocompleteClick} | ||||||||||||||||||||
suggestions={suggestions.map((suggestion) => { | ||||||||||||||||||||
return { | ||||||||||||||||||||
...suggestion, | ||||||||||||||||||||
// For type | ||||||||||||||||||||
onClick: () => {}, | ||||||||||||||||||||
descriptionDisplay: 'wrap', | ||||||||||||||||||||
labelWidth: '40', | ||||||||||||||||||||
}; | ||||||||||||||||||||
})} | ||||||||||||||||||||
/> | ||||||||||||||||||||
); | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
export function transformSuggestionType(type: string): { iconType: string; color: string } { | ||||||||||||||||||||
switch (type) { | ||||||||||||||||||||
case 'field': | ||||||||||||||||||||
return { iconType: 'kqlField', color: 'tint4' }; | ||||||||||||||||||||
case 'value': | ||||||||||||||||||||
return { iconType: 'kqlValue', color: 'tint0' }; | ||||||||||||||||||||
case 'conjunction': | ||||||||||||||||||||
return { iconType: 'kqlSelector', color: 'tint3' }; | ||||||||||||||||||||
case 'operator': | ||||||||||||||||||||
return { iconType: 'kqlOperand', color: 'tint1' }; | ||||||||||||||||||||
default: | ||||||||||||||||||||
return { iconType: 'kqlOther', color: 'tint1' }; | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
function useSuggestions(fieldPrefix: string, search: string) { | ||||||||||||||||||||
const { data } = useStartServices(); | ||||||||||||||||||||
const [indexPatternFields, setIndexPatternFields] = useState<IFieldType[]>(); | ||||||||||||||||||||
|
||||||||||||||||||||
const debouncedSearch = useDebounce(search, DEBOUNCE_SEARCH_MS); | ||||||||||||||||||||
const [suggestions, setSuggestions] = useState<Suggestion[]>([]); | ||||||||||||||||||||
const isQueryValid = useMemo(() => { | ||||||||||||||||||||
if (!value || value === '') { | ||||||||||||||||||||
return true; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
const fetchSuggestions = async () => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
const res = (await data.indexPatterns.getFieldsForWildcard({ | ||||||||||||||||||||
pattern: INDEX_NAME, | ||||||||||||||||||||
})) as IFieldType[]; | ||||||||||||||||||||
if (!data || !data.autocomplete) { | ||||||||||||||||||||
throw new Error('Missing data plugin'); | ||||||||||||||||||||
} | ||||||||||||||||||||
const query = debouncedSearch || ''; | ||||||||||||||||||||
// @ts-ignore | ||||||||||||||||||||
const esSuggestions = ( | ||||||||||||||||||||
await data.autocomplete.getQuerySuggestions({ | ||||||||||||||||||||
language: 'kuery', | ||||||||||||||||||||
indexPatterns: [ | ||||||||||||||||||||
{ | ||||||||||||||||||||
title: INDEX_NAME, | ||||||||||||||||||||
fields: res, | ||||||||||||||||||||
}, | ||||||||||||||||||||
], | ||||||||||||||||||||
boolFilter: [], | ||||||||||||||||||||
query, | ||||||||||||||||||||
selectionStart: query.length, | ||||||||||||||||||||
selectionEnd: query.length, | ||||||||||||||||||||
}) | ||||||||||||||||||||
) | ||||||||||||||||||||
.filter((suggestion) => { | ||||||||||||||||||||
if (suggestion.type === 'conjunction') { | ||||||||||||||||||||
return true; | ||||||||||||||||||||
} | ||||||||||||||||||||
if (suggestion.type === 'value') { | ||||||||||||||||||||
return true; | ||||||||||||||||||||
} | ||||||||||||||||||||
if (suggestion.type === 'operator') { | ||||||||||||||||||||
return true; | ||||||||||||||||||||
} | ||||||||||||||||||||
esKuery.fromKueryExpression(value); | ||||||||||||||||||||
return true; | ||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||
return false; | ||||||||||||||||||||
} | ||||||||||||||||||||
}, [value]); | ||||||||||||||||||||
|
||||||||||||||||||||
if (fieldPrefix && suggestion.text.startsWith(fieldPrefix)) { | ||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||
const fetchFields = async () => { | ||||||||||||||||||||
try { | ||||||||||||||||||||
const fields = ( | ||||||||||||||||||||
((await data.indexPatterns.getFieldsForWildcard({ | ||||||||||||||||||||
pattern: INDEX_NAME, | ||||||||||||||||||||
})) as IFieldType[]) || [] | ||||||||||||||||||||
).filter((field) => { | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took me a bit to parse this. WDYT about something like?
Suggested change
|
||||||||||||||||||||
if (fieldPrefix && field.name.startsWith(fieldPrefix)) { | ||||||||||||||||||||
for (const hiddenField of HIDDEN_FIELDS) { | ||||||||||||||||||||
if (suggestion.text.startsWith(hiddenField)) { | ||||||||||||||||||||
if (field.name.startsWith(hiddenField)) { | ||||||||||||||||||||
return false; | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
return true; | ||||||||||||||||||||
} | ||||||||||||||||||||
}); | ||||||||||||||||||||
setIndexPatternFields(fields); | ||||||||||||||||||||
} catch (err) { | ||||||||||||||||||||
setIndexPatternFields(undefined); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
fetchFields(); | ||||||||||||||||||||
}, [data.indexPatterns, fieldPrefix]); | ||||||||||||||||||||
|
||||||||||||||||||||
return false; | ||||||||||||||||||||
}) | ||||||||||||||||||||
.map((suggestion: any) => ({ | ||||||||||||||||||||
label: suggestion.text, | ||||||||||||||||||||
description: suggestion.description || '', | ||||||||||||||||||||
type: transformSuggestionType(suggestion.type), | ||||||||||||||||||||
start: suggestion.start, | ||||||||||||||||||||
end: suggestion.end, | ||||||||||||||||||||
value: suggestion.text, | ||||||||||||||||||||
})); | ||||||||||||||||||||
|
||||||||||||||||||||
setSuggestions(esSuggestions); | ||||||||||||||||||||
} catch (err) { | ||||||||||||||||||||
setSuggestions([]); | ||||||||||||||||||||
} | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||
fetchSuggestions(); | ||||||||||||||||||||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||||||||||||||||||||
}, [debouncedSearch]); | ||||||||||||||||||||
|
||||||||||||||||||||
return { | ||||||||||||||||||||
suggestions, | ||||||||||||||||||||
}; | ||||||||||||||||||||
} | ||||||||||||||||||||
return ( | ||||||||||||||||||||
<QueryStringInput | ||||||||||||||||||||
iconType="search" | ||||||||||||||||||||
disableLanguageSwitcher={true} | ||||||||||||||||||||
indexPatterns={ | ||||||||||||||||||||
indexPatternFields | ||||||||||||||||||||
? [ | ||||||||||||||||||||
{ | ||||||||||||||||||||
title: INDEX_NAME, | ||||||||||||||||||||
fields: indexPatternFields, | ||||||||||||||||||||
}, | ||||||||||||||||||||
] | ||||||||||||||||||||
: [] | ||||||||||||||||||||
} | ||||||||||||||||||||
query={{ | ||||||||||||||||||||
query: value, | ||||||||||||||||||||
language: 'kuery', | ||||||||||||||||||||
}} | ||||||||||||||||||||
isInvalid={!isQueryValid} | ||||||||||||||||||||
disableAutoFocus={true} | ||||||||||||||||||||
placeholder={placeholder} | ||||||||||||||||||||
onChange={(newQuery) => { | ||||||||||||||||||||
onChange(newQuery.query as string); | ||||||||||||||||||||
}} | ||||||||||||||||||||
onSubmit={(newQuery) => { | ||||||||||||||||||||
onChange(newQuery.query as string, true); | ||||||||||||||||||||
}} | ||||||||||||||||||||
/> | ||||||||||||||||||||
); | ||||||||||||||||||||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...et/public/applications/fleet/sections/agents/agent_list_page/components/status_badges.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiFlexGroup, EuiHealth, EuiNotificationBadge, EuiFlexItem } from '@elastic/eui'; | ||
import React, { memo, useMemo } from 'react'; | ||
import { | ||
AGENT_STATUSES, | ||
getColorForAgentStatus, | ||
getLabelForAgentStatus, | ||
} from '../../services/agent_status'; | ||
import { SimplifiedAgentStatus } from '../../../../types'; | ||
|
||
export const AgentStatusBadges: React.FC<{ | ||
showInactive?: boolean; | ||
agentStatus: { [k in SimplifiedAgentStatus]: number }; | ||
}> = memo(({ agentStatus, showInactive }) => { | ||
const agentStatuses = useMemo(() => { | ||
return AGENT_STATUSES.filter((status) => (showInactive ? true : status !== 'inactive')); | ||
}, [showInactive]); | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="m"> | ||
{agentStatuses.map((status) => ( | ||
<EuiFlexItem key={status} grow={false}> | ||
<AgentStatusBadge status={status} count={agentStatus[status] || 0} /> | ||
</EuiFlexItem> | ||
))} | ||
</EuiFlexGroup> | ||
); | ||
}); | ||
|
||
const AgentStatusBadge: React.FC<{ status: SimplifiedAgentStatus; count: number }> = memo( | ||
({ status, count }) => { | ||
return ( | ||
<> | ||
<EuiHealth color={getColorForAgentStatus(status)}> | ||
<EuiFlexGroup alignItems="center" gutterSize="s"> | ||
<EuiFlexItem grow={false}>{getLabelForAgentStatus(status)}</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiNotificationBadge size="s" color="subdued"> | ||
{count} | ||
</EuiNotificationBadge> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiHealth> | ||
</> | ||
); | ||
} | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some validation of the kuery