-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Ingest Manager] Convert select agent config step to use combo box #73172
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9db03e2
Initial pass at using combo box instead of selectable for agent configs
jen-huang a8fa6e5
Merge remote-tracking branch 'upstream/master' into ingest/72865
jen-huang d368dc5
Hide agent count messaging if fleet isn't set up
jen-huang cce2f1b
Fix types
jen-huang 746073c
Fix i18n
jen-huang a7b5446
Merge remote-tracking branch 'upstream/master' into ingest/72865
jen-huang 69eca42
Fix i18n again
jen-huang dede0b9
Merge remote-tracking branch 'upstream/master' into ingest/72865
jen-huang 6fb3057
Add comment explaining styling
jen-huang 374400f
Merge branch 'master' into ingest/72865
elasticmachine 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,19 @@ | |
* 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, { useEffect, useState, Fragment } from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSelectable, | ||
EuiSpacer, | ||
EuiComboBox, | ||
EuiComboBoxOptionOption, | ||
EuiTextColor, | ||
EuiPortal, | ||
EuiButtonEmpty, | ||
EuiFormRow, | ||
EuiLink, | ||
} from '@elastic/eui'; | ||
import { Error } from '../../../components'; | ||
import { AgentConfig, PackageInfo, GetAgentConfigsResponseItem } from '../../../types'; | ||
|
@@ -23,16 +25,39 @@ import { | |
useGetAgentConfigs, | ||
sendGetOneAgentConfig, | ||
useCapabilities, | ||
useFleetStatus, | ||
} from '../../../hooks'; | ||
import { CreateAgentConfigFlyout } from '../list_page/components'; | ||
|
||
const AgentConfigWrapper = styled(EuiFormRow)` | ||
.euiFormRow__label { | ||
width: 100%; | ||
} | ||
`; | ||
|
||
// Custom styling for drop down list items due to: | ||
// 1) the max-width and overflow properties is added to prevent long config | ||
// names/descriptions from overflowing the flex items | ||
// 2) max-width is built from the grow property on the flex items because the value | ||
// changes based on if Fleet is enabled/setup or not | ||
const AgentConfigNameColumn = styled(EuiFlexItem)` | ||
max-width: ${(props) => `${((props.grow as number) / 9) * 100}%`}; | ||
overflow: hidden; | ||
`; | ||
const AgentConfigDescriptionColumn = styled(EuiFlexItem)` | ||
max-width: ${(props) => `${((props.grow as number) / 9) * 100}%`}; | ||
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. Same as above. |
||
overflow: hidden; | ||
`; | ||
|
||
export const StepSelectConfig: React.FunctionComponent<{ | ||
pkgkey: string; | ||
updatePackageInfo: (packageInfo: PackageInfo | undefined) => void; | ||
agentConfig: AgentConfig | undefined; | ||
updateAgentConfig: (config: AgentConfig | undefined) => void; | ||
setIsLoadingSecondStep: (isLoading: boolean) => void; | ||
}> = ({ pkgkey, updatePackageInfo, agentConfig, updateAgentConfig, setIsLoadingSecondStep }) => { | ||
const { isReady: isFleetReady } = useFleetStatus(); | ||
|
||
// Selected config state | ||
const [selectedConfigId, setSelectedConfigId] = useState<string | undefined>( | ||
agentConfig ? agentConfig.id : undefined | ||
|
@@ -106,6 +131,40 @@ export const StepSelectConfig: React.FunctionComponent<{ | |
} | ||
}, [selectedConfigId, agentConfig, updateAgentConfig, setIsLoadingSecondStep]); | ||
|
||
const agentConfigOptions: Array<EuiComboBoxOptionOption<string>> = packageInfoData | ||
? agentConfigs.map((agentConf) => { | ||
const alreadyHasLimitedPackage = | ||
(isLimitedPackage && | ||
doesAgentConfigAlreadyIncludePackage(agentConf, packageInfoData.response.name)) || | ||
false; | ||
return { | ||
label: agentConf.name, | ||
value: agentConf.id, | ||
disabled: alreadyHasLimitedPackage, | ||
'data-test-subj': 'agentConfigItem', | ||
}; | ||
}) | ||
: []; | ||
|
||
const selectedConfigOption = agentConfigOptions.find( | ||
(option) => option.value === selectedConfigId | ||
); | ||
|
||
// Try to select default agent config | ||
useEffect(() => { | ||
if (!selectedConfigId && agentConfigs.length && agentConfigOptions.length) { | ||
const defaultAgentConfig = agentConfigs.find((config) => config.is_default); | ||
if (defaultAgentConfig) { | ||
const defaultAgentConfigOption = agentConfigOptions.find( | ||
(option) => option.value === defaultAgentConfig.id | ||
); | ||
if (defaultAgentConfigOption && !defaultAgentConfigOption.disabled) { | ||
setSelectedConfigId(defaultAgentConfig.id); | ||
} | ||
} | ||
} | ||
}, [agentConfigs, agentConfigOptions, selectedConfigId]); | ||
|
||
// Display package error if there is one | ||
if (packageInfoError) { | ||
return ( | ||
|
@@ -154,77 +213,95 @@ export const StepSelectConfig: React.FunctionComponent<{ | |
) : null} | ||
<EuiFlexGroup direction="column" gutterSize="m"> | ||
<EuiFlexItem> | ||
<EuiSelectable | ||
searchable | ||
allowExclusions={false} | ||
singleSelection={true} | ||
isLoading={isAgentConfigsLoading || isPackageInfoLoading} | ||
options={agentConfigs.map((agentConf) => { | ||
const alreadyHasLimitedPackage = | ||
(isLimitedPackage && | ||
packageInfoData && | ||
doesAgentConfigAlreadyIncludePackage(agentConf, packageInfoData.response.name)) || | ||
false; | ||
return { | ||
label: agentConf.name, | ||
key: agentConf.id, | ||
checked: selectedConfigId === agentConf.id ? 'on' : undefined, | ||
disabled: alreadyHasLimitedPackage, | ||
'data-test-subj': 'agentConfigItem', | ||
}; | ||
})} | ||
renderOption={(option) => ( | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={false}>{option.label}</EuiFlexItem> | ||
<AgentConfigWrapper | ||
fullWidth={true} | ||
label={ | ||
<EuiFlexGroup justifyContent="spaceBetween"> | ||
<EuiFlexItem> | ||
<EuiTextColor color="subdued"> | ||
{agentConfigsById[option.key!].description} | ||
</EuiTextColor> | ||
<FormattedMessage | ||
id="xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigLabel" | ||
defaultMessage="Agent configuration" | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiTextColor color="subdued"> | ||
<FormattedMessage | ||
id="xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigAgentsCountText" | ||
defaultMessage="{count, plural, one {# agent} other {# agents}}" | ||
values={{ | ||
count: agentConfigsById[option.key!].agents || 0, | ||
}} | ||
/> | ||
</EuiTextColor> | ||
<div> | ||
<EuiLink | ||
disabled={!hasWriteCapabilites} | ||
onClick={() => setIsCreateAgentConfigFlyoutOpen(true)} | ||
> | ||
<FormattedMessage | ||
id="xpack.ingestManager.createPackageConfig.StepSelectConfig.addButton" | ||
defaultMessage="Create agent configuration" | ||
/> | ||
</EuiLink> | ||
</div> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
)} | ||
listProps={{ | ||
bordered: true, | ||
}} | ||
searchProps={{ | ||
placeholder: i18n.translate( | ||
'xpack.ingestManager.createPackageConfig.StepSelectConfig.filterAgentConfigsInputPlaceholder', | ||
} | ||
helpText={ | ||
isFleetReady && selectedConfigId ? ( | ||
<FormattedMessage | ||
id="xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigAgentsDescriptionText" | ||
defaultMessage="{count, plural, one {# agent} other {# agents}} are enrolled with the selected agent configuration." | ||
values={{ | ||
count: agentConfigsById[selectedConfigId].agents || 0, | ||
}} | ||
/> | ||
) : null | ||
} | ||
> | ||
<EuiComboBox | ||
placeholder={i18n.translate( | ||
'xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigPlaceholderText', | ||
{ | ||
defaultMessage: 'Search for agent configurations', | ||
defaultMessage: 'Select an agent configuration to add this integration to', | ||
} | ||
), | ||
}} | ||
height={180} | ||
onChange={(options) => { | ||
const selectedOption = options.find((option) => option.checked === 'on'); | ||
if (selectedOption) { | ||
if (selectedOption.key !== selectedConfigId) { | ||
setSelectedConfigId(selectedOption.key); | ||
)} | ||
singleSelection={{ asPlainText: true }} | ||
isClearable={false} | ||
fullWidth={true} | ||
isLoading={isAgentConfigsLoading || isPackageInfoLoading} | ||
options={agentConfigOptions} | ||
renderOption={(option: EuiComboBoxOptionOption<string>) => { | ||
return ( | ||
<EuiFlexGroup> | ||
<AgentConfigNameColumn grow={2}> | ||
<span className="eui-textTruncate">{option.label}</span> | ||
</AgentConfigNameColumn> | ||
<AgentConfigDescriptionColumn grow={isFleetReady ? 5 : 7}> | ||
<EuiTextColor className="eui-textTruncate" color="subdued"> | ||
{agentConfigsById[option.value!].description} | ||
</EuiTextColor> | ||
</AgentConfigDescriptionColumn> | ||
{isFleetReady ? ( | ||
<EuiFlexItem grow={2} className="eui-textRight"> | ||
<EuiTextColor color="subdued"> | ||
<FormattedMessage | ||
id="xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigAgentsCountText" | ||
defaultMessage="{count, plural, one {# agent} other {# agents}} enrolled" | ||
values={{ | ||
count: agentConfigsById[option.value!].agents || 0, | ||
}} | ||
/> | ||
</EuiTextColor> | ||
</EuiFlexItem> | ||
) : null} | ||
</EuiFlexGroup> | ||
); | ||
}} | ||
selectedOptions={selectedConfigOption ? [selectedConfigOption] : []} | ||
onChange={(options) => { | ||
const selectedOption = options[0] || undefined; | ||
if (selectedOption) { | ||
if (selectedOption.value !== selectedConfigId) { | ||
setSelectedConfigId(selectedOption.value); | ||
} | ||
} else { | ||
setSelectedConfigId(undefined); | ||
} | ||
} else { | ||
setSelectedConfigId(undefined); | ||
} | ||
}} | ||
> | ||
{(list, search) => ( | ||
<Fragment> | ||
{search} | ||
<EuiSpacer size="m" /> | ||
{list} | ||
</Fragment> | ||
)} | ||
</EuiSelectable> | ||
}} | ||
/> | ||
</AgentConfigWrapper> | ||
</EuiFlexItem> | ||
{/* Display selected agent config error if there is one */} | ||
{selectedConfigError ? ( | ||
|
@@ -240,22 +317,6 @@ export const StepSelectConfig: React.FunctionComponent<{ | |
/> | ||
</EuiFlexItem> | ||
) : null} | ||
<EuiFlexItem> | ||
<div> | ||
<EuiButtonEmpty | ||
iconType="plusInCircle" | ||
isDisabled={!hasWriteCapabilites} | ||
onClick={() => setIsCreateAgentConfigFlyoutOpen(true)} | ||
flush="left" | ||
size="s" | ||
> | ||
<FormattedMessage | ||
id="xpack.ingestManager.createPackageConfig.StepSelectConfig.addButton" | ||
defaultMessage="New agent configuration" | ||
/> | ||
</EuiButtonEmpty> | ||
</div> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
|
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
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.
Why is this additional calculation needed? Would it make sense to add a comment about it?
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.
max-width
property is added to prevent long config names/descriptions from overflowing the flex itemsgrow
property on the flex items because that property changes based on if Fleet is enabled/setup or not (when Fleet is not available, the "agents enrolled" column is not displayed)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.
pushed up a change with comments added