-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest Manager] Change agent config YAML view to flyout (#67918)
* Consolidate context menu/row action components and usage, and some export/imports * Missed export * Move agent config yaml tab to flyout, add and consolidate agent config action menus * Fix i18n * Add download config YAML endpoint and link from flyout, add common config->yaml service * Actually remove the tab lol * Fix i18n
- Loading branch information
Showing
30 changed files
with
481 additions
and
373 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
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts
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,39 @@ | ||
/* | ||
* 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 { safeDump } from 'js-yaml'; | ||
import { FullAgentConfig } from '../types'; | ||
|
||
const CONFIG_KEYS_ORDER = [ | ||
'id', | ||
'name', | ||
'revision', | ||
'type', | ||
'outputs', | ||
'settings', | ||
'datasources', | ||
'enabled', | ||
'package', | ||
'input', | ||
]; | ||
|
||
export const configToYaml = (config: FullAgentConfig): string => { | ||
return safeDump(config, { | ||
skipInvalid: true, | ||
sortKeys: (keyA: string, keyB: string) => { | ||
const indexA = CONFIG_KEYS_ORDER.indexOf(keyA); | ||
const indexB = CONFIG_KEYS_ORDER.indexOf(keyB); | ||
if (indexA >= 0 && indexB < 0) { | ||
return -1; | ||
} | ||
|
||
if (indexA < 0 && indexB >= 0) { | ||
return 1; | ||
} | ||
|
||
return indexA - indexB; | ||
}, | ||
}); | ||
}; |
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
68 changes: 68 additions & 0 deletions
68
...ins/ingest_manager/public/applications/ingest_manager/components/context_menu_actions.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,68 @@ | ||
/* | ||
* 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 React, { useCallback, useState } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
EuiButtonIcon, | ||
EuiContextMenu, | ||
EuiContextMenuPanel, | ||
EuiPopover, | ||
EuiButton, | ||
} from '@elastic/eui'; | ||
import { EuiButtonProps } from '@elastic/eui/src/components/button/button'; | ||
import { EuiContextMenuProps } from '@elastic/eui/src/components/context_menu/context_menu'; | ||
import { EuiContextMenuPanelProps } from '@elastic/eui/src/components/context_menu/context_menu_panel'; | ||
|
||
type Props = { | ||
button?: { | ||
props: EuiButtonProps; | ||
children: JSX.Element; | ||
}; | ||
} & ( | ||
| { | ||
items: EuiContextMenuPanelProps['items']; | ||
} | ||
| { | ||
panels: EuiContextMenuProps['panels']; | ||
} | ||
); | ||
|
||
export const ContextMenuActions = React.memo<Props>(({ button, ...props }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const handleCloseMenu = useCallback(() => setIsOpen(false), [setIsOpen]); | ||
const handleToggleMenu = useCallback(() => setIsOpen(!isOpen), [isOpen]); | ||
|
||
return ( | ||
<EuiPopover | ||
anchorPosition="downRight" | ||
panelPaddingSize="none" | ||
button={ | ||
button ? ( | ||
<EuiButton {...button.props} onClick={handleToggleMenu}> | ||
{button.children} | ||
</EuiButton> | ||
) : ( | ||
<EuiButtonIcon | ||
iconType="boxesHorizontal" | ||
onClick={handleToggleMenu} | ||
aria-label={i18n.translate('xpack.ingestManager.genericActionsMenuText', { | ||
defaultMessage: 'Open', | ||
})} | ||
/> | ||
) | ||
} | ||
isOpen={isOpen} | ||
closePopover={handleCloseMenu} | ||
> | ||
{'items' in props ? ( | ||
<EuiContextMenuPanel items={props.items} /> | ||
) : ( | ||
<EuiContextMenu panels={props.panels} initialPanelId={0} /> | ||
)} | ||
</EuiPopover> | ||
); | ||
}); |
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
38 changes: 0 additions & 38 deletions
38
...ingest_manager/public/applications/ingest_manager/components/table_row_actions_nested.tsx
This file was deleted.
Oops, something went wrong.
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
69 changes: 69 additions & 0 deletions
69
...ager/public/applications/ingest_manager/sections/agent_config/components/actions_menu.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,69 @@ | ||
/* | ||
* 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 React, { memo, useState } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { EuiContextMenuItem, EuiPortal } from '@elastic/eui'; | ||
import { useCapabilities, useLink } from '../../../hooks'; | ||
import { ContextMenuActions } from '../../../components'; | ||
import { ConfigYamlFlyout } from './config_yaml_flyout'; | ||
|
||
export const AgentConfigActionMenu = memo<{ configId: string; fullButton?: boolean }>( | ||
({ configId, fullButton = false }) => { | ||
const { getHref } = useLink(); | ||
const hasWriteCapabilities = useCapabilities().write; | ||
const [isYamlFlyoutOpen, setIsYamlFlyoutOpen] = useState<boolean>(false); | ||
return ( | ||
<> | ||
{isYamlFlyoutOpen ? ( | ||
<EuiPortal> | ||
<ConfigYamlFlyout configId={configId} onClose={() => setIsYamlFlyoutOpen(false)} /> | ||
</EuiPortal> | ||
) : null} | ||
<ContextMenuActions | ||
button={ | ||
fullButton | ||
? { | ||
props: { | ||
iconType: 'arrowDown', | ||
iconSide: 'right', | ||
}, | ||
children: ( | ||
<FormattedMessage | ||
id="xpack.ingestManager.agentConfigActionMenu.buttonText" | ||
defaultMessage="Actions" | ||
/> | ||
), | ||
} | ||
: undefined | ||
} | ||
items={[ | ||
<EuiContextMenuItem | ||
icon="inspect" | ||
onClick={() => setIsYamlFlyoutOpen(!isYamlFlyoutOpen)} | ||
key="viewConfig" | ||
> | ||
<FormattedMessage | ||
id="xpack.ingestManager.agentConfigActionMenu.viewConfigText" | ||
defaultMessage="View config" | ||
/> | ||
</EuiContextMenuItem>, | ||
<EuiContextMenuItem | ||
disabled={!hasWriteCapabilities} | ||
icon="plusInCircle" | ||
href={getHref('add_datasource_from_configuration', { configId })} | ||
key="createDatasource" | ||
> | ||
<FormattedMessage | ||
id="xpack.ingestManager.agentConfigActionMenu.createDatasourceActionText" | ||
defaultMessage="Create data source" | ||
/> | ||
</EuiContextMenuItem>, | ||
]} | ||
/> | ||
</> | ||
); | ||
} | ||
); |
99 changes: 99 additions & 0 deletions
99
...ublic/applications/ingest_manager/sections/agent_config/components/config_yaml_flyout.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,99 @@ | ||
/* | ||
* 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 React, { memo } from 'react'; | ||
import styled from 'styled-components'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { | ||
EuiCodeBlock, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiFlyout, | ||
EuiFlyoutHeader, | ||
EuiTitle, | ||
EuiFlyoutBody, | ||
EuiFlyoutFooter, | ||
EuiButtonEmpty, | ||
EuiButton, | ||
} from '@elastic/eui'; | ||
import { useGetOneAgentConfigFull, useGetOneAgentConfig, useCore } from '../../../hooks'; | ||
import { Loading } from '../../../components'; | ||
import { configToYaml, agentConfigRouteService } from '../../../services'; | ||
|
||
const FlyoutBody = styled(EuiFlyoutBody)` | ||
.euiFlyoutBody__overflowContent { | ||
padding: 0; | ||
} | ||
`; | ||
|
||
export const ConfigYamlFlyout = memo<{ configId: string; onClose: () => void }>( | ||
({ configId, onClose }) => { | ||
const core = useCore(); | ||
const { isLoading: isLoadingYaml, data: yamlData } = useGetOneAgentConfigFull(configId); | ||
const { data: configData } = useGetOneAgentConfig(configId); | ||
|
||
const body = | ||
isLoadingYaml && !yamlData ? ( | ||
<Loading /> | ||
) : ( | ||
<EuiCodeBlock language="yaml" isCopyable fontSize="m"> | ||
{configToYaml(yamlData!.item)} | ||
</EuiCodeBlock> | ||
); | ||
|
||
const downloadLink = core.http.basePath.prepend( | ||
agentConfigRouteService.getInfoFullDownloadPath(configId) | ||
); | ||
|
||
return ( | ||
<EuiFlyout onClose={onClose} size="l" maxWidth={640}> | ||
<EuiFlyoutHeader hasBorder aria-labelledby="IngestManagerConfigYamlFlyoutTitle"> | ||
<EuiTitle size="m"> | ||
<h2 id="IngestManagerConfigYamlFlyoutTitle"> | ||
{configData?.item ? ( | ||
<FormattedMessage | ||
id="xpack.ingestManager.configDetails.yamlflyoutTitleWithName" | ||
defaultMessage="'{name}' agent configuration" | ||
values={{ name: configData.item.name }} | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id="xpack.ingestManager.configDetails.yamlflyoutTitleWithoutName" | ||
defaultMessage="Agent configuration" | ||
/> | ||
)} | ||
</h2> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
<FlyoutBody>{body}</FlyoutBody> | ||
<EuiFlyoutFooter> | ||
<EuiFlexGroup justifyContent="spaceBetween"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty iconType="cross" onClick={onClose} flush="left"> | ||
<FormattedMessage | ||
id="xpack.ingestManager.configDetails.yamlFlyoutCloseButtonLabel" | ||
defaultMessage="Close" | ||
/> | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
href={downloadLink} | ||
iconType="download" | ||
isDisabled={Boolean(isLoadingYaml && !yamlData)} | ||
> | ||
<FormattedMessage | ||
id="xpack.ingestManager.configDetails.yamlDownloadButtonLabel" | ||
defaultMessage="Download configuration" | ||
/> | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlyoutFooter> | ||
</EuiFlyout> | ||
); | ||
} | ||
); |
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
Oops, something went wrong.