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.
Exposed AddMessageVariables as separate component (elastic#63007)
* Exposed AddMessageVariables as separate component and added styles to allow to handle bigger list of messageVariables * Fixed failing tests and styles * Fixed due to comments
- Loading branch information
1 parent
f699bd1
commit c95db69
Showing
12 changed files
with
211 additions
and
387 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
4 changes: 4 additions & 0 deletions
4
x-pack/plugins/triggers_actions_ui/public/application/components/add_message_variables.scss
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,4 @@ | ||
.messageVariablesPanel { | ||
@include euiYScrollWithShadows; | ||
max-height: $euiSize * 20; | ||
} |
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/triggers_actions_ui/public/application/components/add_message_variables.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, { useState } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiPopover, EuiButtonIcon, EuiContextMenuPanel, EuiContextMenuItem } from '@elastic/eui'; | ||
import './add_message_variables.scss'; | ||
|
||
interface Props { | ||
messageVariables: string[] | undefined; | ||
paramsProperty: string; | ||
onSelectEventHandler: (variable: string) => void; | ||
} | ||
|
||
export const AddMessageVariables: React.FunctionComponent<Props> = ({ | ||
messageVariables, | ||
paramsProperty, | ||
onSelectEventHandler, | ||
}) => { | ||
const [isVariablesPopoverOpen, setIsVariablesPopoverOpen] = useState<boolean>(false); | ||
|
||
const getMessageVariables = () => | ||
messageVariables?.map((variable: string) => ( | ||
<EuiContextMenuItem | ||
key={variable} | ||
icon="empty" | ||
onClick={() => { | ||
onSelectEventHandler(variable); | ||
setIsVariablesPopoverOpen(false); | ||
}} | ||
> | ||
{`{{${variable}}}`} | ||
</EuiContextMenuItem> | ||
)); | ||
|
||
const addVariableButtonTitle = i18n.translate( | ||
'xpack.triggersActionsUI.components.addMessageVariables.addVariableTitle', | ||
{ | ||
defaultMessage: 'Add alert variable', | ||
} | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
button={ | ||
<EuiButtonIcon | ||
data-test-subj={`${paramsProperty}AddVariableButton`} | ||
title={addVariableButtonTitle} | ||
onClick={() => setIsVariablesPopoverOpen(true)} | ||
iconType="indexOpen" | ||
aria-label={i18n.translate( | ||
'xpack.triggersActionsUI.components.addMessageVariables.addVariablePopoverButton', | ||
{ | ||
defaultMessage: 'Add variable', | ||
} | ||
)} | ||
/> | ||
} | ||
isOpen={isVariablesPopoverOpen} | ||
closePopover={() => setIsVariablesPopoverOpen(false)} | ||
panelPaddingSize="none" | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenuPanel className="messageVariablesPanel" items={getMessageVariables()} /> | ||
</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
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
Oops, something went wrong.