-
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.
[Logs UI] Logs ui context menu (#69915)
- Loading branch information
Alejandro Fernández
committed
Jun 25, 2020
1 parent
10a3c33
commit 23a0b10
Showing
3 changed files
with
143 additions
and
131 deletions.
There are no files selected for viewing
120 changes: 0 additions & 120 deletions
120
x-pack/plugins/infra/public/components/logging/log_text_stream/log_entry_actions_column.tsx
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
x-pack/plugins/infra/public/components/logging/log_text_stream/log_entry_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,94 @@ | ||
/* | ||
* 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, { useMemo } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiButtonIcon, EuiPopover, EuiContextMenuPanel, EuiContextMenuItem } from '@elastic/eui'; | ||
|
||
import { euiStyled } from '../../../../../observability/public'; | ||
import { LogEntryColumnContent } from './log_entry_column'; | ||
|
||
interface LogEntryContextMenuItem { | ||
label: string; | ||
onClick: () => void; | ||
} | ||
|
||
interface LogEntryContextMenuProps { | ||
'aria-label'?: string; | ||
isOpen: boolean; | ||
onOpen: () => void; | ||
onClose: () => void; | ||
items: LogEntryContextMenuItem[]; | ||
} | ||
|
||
const DEFAULT_MENU_LABEL = i18n.translate( | ||
'xpack.infra.logEntryItemView.logEntryActionsMenuToolTip', | ||
{ | ||
defaultMessage: 'View actions for line', | ||
} | ||
); | ||
|
||
export const LogEntryContextMenu: React.FC<LogEntryContextMenuProps> = ({ | ||
'aria-label': ariaLabel, | ||
isOpen, | ||
onOpen, | ||
onClose, | ||
items, | ||
}) => { | ||
const closeMenuAndCall = useMemo(() => { | ||
return (callback: LogEntryContextMenuItem['onClick']) => { | ||
return () => { | ||
onClose(); | ||
callback(); | ||
}; | ||
}; | ||
}, [onClose]); | ||
|
||
const button = ( | ||
<ButtonWrapper> | ||
<EuiButtonIcon | ||
aria-label={ariaLabel || DEFAULT_MENU_LABEL} | ||
color="ghost" | ||
iconType="boxesHorizontal" | ||
onClick={onOpen} | ||
/> | ||
</ButtonWrapper> | ||
); | ||
|
||
const wrappedItems = useMemo(() => { | ||
return items.map((item, i) => ( | ||
<EuiContextMenuItem key={i} onClick={closeMenuAndCall(item.onClick)}> | ||
{item.label} | ||
</EuiContextMenuItem> | ||
)); | ||
}, [items, closeMenuAndCall]); | ||
|
||
return ( | ||
<LogEntryContextMenuContent> | ||
<AbsoluteWrapper> | ||
<EuiPopover closePopover={onClose} isOpen={isOpen} button={button} ownFocus={true}> | ||
<EuiContextMenuPanel items={wrappedItems} /> | ||
</EuiPopover> | ||
</AbsoluteWrapper> | ||
</LogEntryContextMenuContent> | ||
); | ||
}; | ||
|
||
const LogEntryContextMenuContent = euiStyled(LogEntryColumnContent)` | ||
overflow: hidden; | ||
user-select: none; | ||
`; | ||
|
||
const AbsoluteWrapper = euiStyled.div` | ||
position: absolute; | ||
`; | ||
|
||
const ButtonWrapper = euiStyled.div` | ||
background: ${(props) => props.theme.eui.euiColorPrimary}; | ||
border-radius: 50%; | ||
padding: 4px; | ||
transform: translateY(-6px); | ||
`; |
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