-
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.
refactor processors editor item to multiple files
also refactored i18n into it's own file. would be good to come up with a pttaern for doing this more broadly.
- Loading branch information
1 parent
1419d3b
commit 634f9d0
Showing
5 changed files
with
183 additions
and
128 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...ts/pipeline_processors_editor/components/pipeline_processors_editor_item/context_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,84 @@ | ||
/* | ||
* 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, { FunctionComponent, useState } from 'react'; | ||
|
||
import { EuiContextMenuItem, EuiContextMenuPanel, EuiPopover, EuiButtonIcon } from '@elastic/eui'; | ||
|
||
import { editorItemMessages } from './messages'; | ||
|
||
interface Props { | ||
disabled: boolean; | ||
showAddOnFailure: boolean; | ||
onDuplicate: () => void; | ||
onDelete: () => void; | ||
onAddOnFailure: () => void; | ||
} | ||
|
||
export const ContextMenu: FunctionComponent<Props> = ({ | ||
showAddOnFailure, | ||
onDuplicate, | ||
onAddOnFailure, | ||
onDelete, | ||
disabled, | ||
}) => { | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
|
||
const contextMenuItems = [ | ||
<EuiContextMenuItem | ||
key="duplicate" | ||
icon="copy" | ||
onClick={() => { | ||
setIsOpen(false); | ||
onDuplicate(); | ||
}} | ||
> | ||
{editorItemMessages.duplicateButtonLabel} | ||
</EuiContextMenuItem>, | ||
showAddOnFailure ? undefined : ( | ||
<EuiContextMenuItem | ||
key="addOnFailure" | ||
icon="indexClose" | ||
onClick={() => { | ||
setIsOpen(false); | ||
onAddOnFailure(); | ||
}} | ||
> | ||
{editorItemMessages.addOnFailureButtonLabel} | ||
</EuiContextMenuItem> | ||
), | ||
<EuiContextMenuItem | ||
key="delete" | ||
icon="trash" | ||
color="danger" | ||
onClick={() => { | ||
setIsOpen(false); | ||
onDelete(); | ||
}} | ||
> | ||
{editorItemMessages.deleteButtonLabel} | ||
</EuiContextMenuItem>, | ||
].filter(Boolean) as JSX.Element[]; | ||
|
||
return ( | ||
<EuiPopover | ||
anchorPosition="leftCenter" | ||
panelPaddingSize="none" | ||
isOpen={isOpen} | ||
closePopover={() => setIsOpen(false)} | ||
button={ | ||
<EuiButtonIcon | ||
disabled={disabled} | ||
onClick={() => setIsOpen((v) => !v)} | ||
iconType="boxesHorizontal" | ||
aria-label={editorItemMessages.moreButtonAriaLabel} | ||
/> | ||
} | ||
> | ||
<EuiContextMenuPanel items={contextMenuItems} />; | ||
</EuiPopover> | ||
); | ||
}; |
58 changes: 58 additions & 0 deletions
58
...ponents/pipeline_processors_editor/components/pipeline_processors_editor_item/messages.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,58 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const editorItemMessages = { | ||
moveButtonLabel: i18n.translate('xpack.ingestPipelines.pipelineEditor.item.moveButtonLabel', { | ||
defaultMessage: 'Move this processor', | ||
}), | ||
editorButtonLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.item.editButtonAriaLabel', | ||
{ | ||
defaultMessage: 'Edit this processor', | ||
} | ||
), | ||
duplicateButtonLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.item.moreMenu.duplicateButtonLabel', | ||
{ | ||
defaultMessage: 'Duplicate this processor', | ||
} | ||
), | ||
addOnFailureButtonLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.item.moreMenu.addOnFailureHandlerButtonLabel', | ||
{ | ||
defaultMessage: 'Add on failure handler', | ||
} | ||
), | ||
cancelMoveButtonLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.item.cancelMoveButtonAriaLabel', | ||
{ | ||
defaultMessage: 'Cancel moving this processor', | ||
} | ||
), | ||
deleteButtonLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.item.moreMenu.deleteButtonLabel', | ||
{ | ||
defaultMessage: 'Delete', | ||
} | ||
), | ||
moreButtonAriaLabel: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.item.moreButtonAriaLabel', | ||
{ | ||
defaultMessage: 'Show more actions for this processor', | ||
} | ||
), | ||
processorTypeLabel: ({ type }: { type: string }) => | ||
i18n.translate('xpack.ingestPipelines.pipelineEditor.item.textInputAriaLabel', { | ||
defaultMessage: 'Provide a description for this {type} processor', | ||
values: { type }, | ||
}), | ||
descriptionPlaceholder: i18n.translate( | ||
'xpack.ingestPipelines.pipelineEditor.item.descriptionPlaceholder', | ||
{ defaultMessage: 'No description' } | ||
), | ||
}; |
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.