forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0225a8c
commit 798503a
Showing
15 changed files
with
570 additions
and
163 deletions.
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
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
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
132 changes: 132 additions & 0 deletions
132
...apm/public/components/shared/tutorial/config_agent/environment_configuration_selector.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,132 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
EuiButtonEmpty, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiPopover, | ||
EuiPopoverFooter, | ||
EuiPopoverTitle, | ||
EuiSelectable, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React, { useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { px } from '../../../../style/variables'; | ||
|
||
export interface EnvironmentConfigurationOption { | ||
key: string; | ||
label: string; | ||
apmServerUrl?: string; | ||
secretToken?: string; | ||
checked?: 'on'; | ||
} | ||
|
||
const StyledEuiButtomEmpty = styled(EuiButtonEmpty)` | ||
.euiButtonContent { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
`; | ||
|
||
interface Props { | ||
options: EnvironmentConfigurationOption[]; | ||
selectedOption?: EnvironmentConfigurationOption; | ||
onChange: (selectedOption?: EnvironmentConfigurationOption) => void; | ||
fleetLink: { | ||
label: string; | ||
href: string; | ||
}; | ||
} | ||
|
||
function findCheckedOption(options: EnvironmentConfigurationOption[]) { | ||
return options.find(({ checked }) => checked === 'on'); | ||
} | ||
|
||
export function EnvironmentConfigurationSelector({ | ||
options, | ||
selectedOption, | ||
onChange, | ||
fleetLink, | ||
}: Props) { | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
const [availableOptions, setAvailableOptions] = useState< | ||
EnvironmentConfigurationOption[] | ||
>(options); | ||
|
||
useEffect(() => { | ||
const checkedOption = findCheckedOption(availableOptions); | ||
onChange(checkedOption); | ||
}, [availableOptions, onChange]); | ||
|
||
function toggleIsPopoverOpen() { | ||
setIsPopoverOpen((state) => !state); | ||
} | ||
|
||
return ( | ||
<EuiPopover | ||
button={ | ||
<StyledEuiButtomEmpty | ||
color="text" | ||
style={{ width: px(300) }} | ||
iconType="arrowDown" | ||
iconSide="right" | ||
onClick={toggleIsPopoverOpen} | ||
> | ||
{selectedOption?.label} | ||
</StyledEuiButtomEmpty> | ||
} | ||
isOpen={isPopoverOpen} | ||
closePopover={toggleIsPopoverOpen} | ||
> | ||
<div style={{ width: px(400) }}> | ||
<EuiSelectable | ||
searchable | ||
searchProps={{ | ||
placeholder: i18n.translate( | ||
'xpack.apm.tutorial.config_agent.searc', | ||
{ defaultMessage: 'Search' } | ||
), | ||
compressed: true, | ||
}} | ||
options={availableOptions} | ||
onChange={(newOptions) => { | ||
const nextSelectedOption = findCheckedOption(newOptions); | ||
// When there is no checked option don't update the options so we always have at least one option selected | ||
if (nextSelectedOption) { | ||
setAvailableOptions(newOptions); | ||
} | ||
}} | ||
singleSelection | ||
> | ||
{(list, search) => { | ||
return ( | ||
<> | ||
<EuiPopoverTitle paddingSize="s">{search}</EuiPopoverTitle> | ||
{list} | ||
<EuiPopoverFooter paddingSize="none"> | ||
<EuiFlexGroup gutterSize="none"> | ||
<EuiFlexItem> | ||
<EuiButtonEmpty | ||
iconType="gear" | ||
size="s" | ||
href={fleetLink.href} | ||
> | ||
{fleetLink.label} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPopoverFooter> | ||
</> | ||
); | ||
}} | ||
</EuiSelectable> | ||
</div> | ||
</EuiPopover> | ||
); | ||
} |
Oops, something went wrong.