-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 and added styles to…
… allow to handle bigger list of messageVariables
- Loading branch information
1 parent
3457dde
commit d8a2331
Showing
8 changed files
with
209 additions
and
353 deletions.
There are no files selected for viewing
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 { | ||
max-height: 400px; | ||
overflow-y: scroll; | ||
} |
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.builtinActionTypes.pagerDutyAction.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.builtinActionTypes.pagerDutyAction.addVariablePopoverButton5', | ||
{ | ||
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
Oops, something went wrong.