diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx index c27b0bf278a59..ebb6a9bdde489 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/delete_button.tsx @@ -12,20 +12,18 @@ import React, { useState } from 'react'; import { CoreStart } from 'kibana/public'; import { toMountPoint } from '../../../../../../../../src/plugins/kibana_react/public'; import { SearchSessionsMgmtAPI } from '../../lib/api'; -import { TableText } from '../'; -import { OnActionClick, OnActionComplete, OnActionDismiss } from './types'; +import { IClickActionDescriptor } from '../'; +import { OnActionDismiss } from './types'; +import { UISession } from '../../types'; interface DeleteButtonProps { - id: string; - name: string; api: SearchSessionsMgmtAPI; - onActionComplete: OnActionComplete; - overlays: CoreStart['overlays']; - onActionClick: OnActionClick; + searchSession: UISession; } const DeleteConfirm = (props: DeleteButtonProps & { onActionDismiss: OnActionDismiss }) => { - const { id, name, api, onActionComplete, onActionDismiss } = props; + const { searchSession, api, onActionDismiss } = props; + const { name, id } = searchSession; const [isLoading, setIsLoading] = useState(false); const title = i18n.translate('xpack.data.mgmt.searchSessions.cancelModal.title', { @@ -51,7 +49,6 @@ const DeleteConfirm = (props: DeleteButtonProps & { onActionDismiss: OnActionDis onConfirm={async () => { setIsLoading(true); await api.sendCancel(id); - onActionComplete(); onActionDismiss(); }} confirmButtonText={confirm} @@ -65,24 +62,21 @@ const DeleteConfirm = (props: DeleteButtonProps & { onActionDismiss: OnActionDis ); }; -export const DeleteButton = (props: DeleteButtonProps) => { - const { overlays, onActionClick } = props; - - return ( - <> - { - onActionClick(); - const ref = overlays.openModal( - toMountPoint( ref?.close()} {...props} />) - ); - }} - > - - - - ); -}; +export const createDeleteActionDescriptor = ( + api: SearchSessionsMgmtAPI, + uiSession: UISession, + core: CoreStart +): IClickActionDescriptor => ({ + iconType: 'crossInACircleFilled', + label: ( + + ), + onClick: async () => { + const ref = core.overlays.openModal( + toMountPoint( + ref?.close()} searchSession={uiSession} api={api} /> + ) + ); + await ref.onClose; + }, +}); diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/extend_button.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/extend_button.tsx index d5750e58d0179..47878972403e2 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/extend_button.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/extend_button.tsx @@ -9,29 +9,25 @@ import { EuiConfirmModal } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import React, { useState } from 'react'; -import { Duration } from 'moment'; import moment from 'moment'; import { CoreStart } from 'kibana/public'; import { toMountPoint } from '../../../../../../../../src/plugins/kibana_react/public'; import { SearchSessionsMgmtAPI } from '../../lib/api'; -import { TableText } from '../'; -import { OnActionClick, OnActionComplete, OnActionDismiss } from './types'; +import { IClickActionDescriptor } from '../'; +import { OnActionDismiss } from './types'; +import { UISession } from '../../types'; +import extendSessionIcon from '../../icons/extend_session.svg'; interface ExtendButtonProps { - id: string; - name: string; - expires: string | null; - extendBy: Duration; + searchSession: UISession; api: SearchSessionsMgmtAPI; - overlays: CoreStart['overlays']; - onActionClick: OnActionClick; - onActionComplete: OnActionComplete; } const ExtendConfirm = ({ ...props }: ExtendButtonProps & { onActionDismiss: OnActionDismiss }) => { - const { id, name, expires, api, extendBy, onActionComplete, onActionDismiss } = props; + const { searchSession, api, onActionDismiss } = props; + const { id, name, expires } = searchSession; const [isLoading, setIsLoading] = useState(false); - const extendByDuration = moment.duration(extendBy); + const extendByDuration = moment.duration(api.getExtendByDuration()); const newExpiration = moment(expires).add(extendByDuration); @@ -61,7 +57,6 @@ const ExtendConfirm = ({ ...props }: ExtendButtonProps & { onActionDismiss: OnAc await api.sendExtend(id, `${newExpiration.toISOString()}`); setIsLoading(false); onActionDismiss(); - onActionComplete(); }} confirmButtonText={confirm} confirmButtonDisabled={isLoading} @@ -74,24 +69,21 @@ const ExtendConfirm = ({ ...props }: ExtendButtonProps & { onActionDismiss: OnAc ); }; -export const ExtendButton = (props: ExtendButtonProps) => { - const { overlays, onActionClick } = props; - - return ( - <> - { - onActionClick(); - const ref = overlays.openModal( - toMountPoint( ref?.close()} {...props} />) - ); - }} - > - - - - ); -}; +export const createExtendActionDescriptor = ( + api: SearchSessionsMgmtAPI, + uiSession: UISession, + core: CoreStart +): IClickActionDescriptor => ({ + iconType: extendSessionIcon, + label: ( + + ), + onClick: async () => { + const ref = core.overlays.openModal( + toMountPoint( + ref?.close()} searchSession={uiSession} api={api} /> + ) + ); + await ref.onClose; + }, +}); diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx index f95ca1c653c92..c3860fe3e276b 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/get_action.tsx @@ -5,93 +5,31 @@ * 2.0. */ -import React from 'react'; import { CoreStart } from 'kibana/public'; import { IClickActionDescriptor } from '../'; -import extendSessionIcon from '../../icons/extend_session.svg'; import { SearchSessionsMgmtAPI } from '../../lib/api'; import { UISession } from '../../types'; -import { DeleteButton } from './delete_button'; -import { ExtendButton } from './extend_button'; -import { InspectButton } from './inspect_button'; -import { ACTION, OnActionClick, OnActionComplete } from './types'; -import { RenameButton } from './rename_button'; +import { createDeleteActionDescriptor } from './delete_button'; +import { createExtendActionDescriptor } from './extend_button'; +import { createInspectActionDescriptor } from './inspect_button'; +import { ACTION } from './types'; +import { createRenameActionDescriptor } from './rename_button'; export const getAction = ( api: SearchSessionsMgmtAPI, actionType: string, uiSession: UISession, - core: CoreStart, - onActionClick: OnActionClick, - onActionComplete: OnActionComplete + core: CoreStart ): IClickActionDescriptor | null => { - const { id, name, expires } = uiSession; - const { overlays, uiSettings } = core; switch (actionType) { case ACTION.INSPECT: - return { - iconType: 'document', - textColor: 'default', - label: ( - - ), - }; - + return createInspectActionDescriptor(api, uiSession, core); case ACTION.DELETE: - return { - iconType: 'crossInACircleFilled', - textColor: 'default', - label: ( - - ), - }; - + return createDeleteActionDescriptor(api, uiSession, core); case ACTION.EXTEND: - return { - iconType: extendSessionIcon, - textColor: 'default', - label: ( - - ), - }; - + return createExtendActionDescriptor(api, uiSession, core); case ACTION.RENAME: - return { - iconType: 'pencil', - textColor: 'default', - label: ( - - ), - }; - + return createRenameActionDescriptor(api, uiSession, core); default: // eslint-disable-next-line no-console console.error(`Unknown action: ${actionType}`); diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/inspect_button.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/inspect_button.tsx index 54c0c10ee6cc5..05382f3eb36ca 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/inspect_button.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/inspect_button.tsx @@ -10,20 +10,18 @@ import { FormattedMessage } from '@kbn/i18n/react'; import React, { Fragment } from 'react'; import { CoreStart } from 'kibana/public'; import { UISession } from '../../types'; -import { TableText } from '..'; +import { IClickActionDescriptor } from '..'; import { CodeEditor, createKibanaReactContext, toMountPoint, } from '../../../../../../../../src/plugins/kibana_react/public'; import './inspect_button.scss'; -import { OnActionClick } from './types'; +import { SearchSessionsMgmtAPI } from '../../lib/api'; interface InspectFlyoutProps { searchSession: UISession; - overlays: CoreStart['overlays']; uiSettings: CoreStart['uiSettings']; - onActionClick: OnActionClick; } const InspectFlyout = ({ uiSettings, searchSession }: InspectFlyoutProps) => { @@ -84,24 +82,23 @@ const InspectFlyout = ({ uiSettings, searchSession }: InspectFlyoutProps) => { ); }; -export const InspectButton = (props: InspectFlyoutProps) => { - const { overlays, onActionClick } = props; - return ( - - { - onActionClick(); - const flyout = ; - overlays.openFlyout(toMountPoint(flyout)); - }} - > - - - - ); -}; +export const createInspectActionDescriptor = ( + api: SearchSessionsMgmtAPI, + uiSession: UISession, + core: CoreStart +): IClickActionDescriptor => ({ + iconType: 'document', + label: ( + + ), + onClick: async () => { + const flyout = ; + const overlay = core.overlays.openFlyout(toMountPoint(flyout)); + await overlay.onClose; + }, +}); diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx index 8b1037250eeeb..dbacb6d094391 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/popover_actions.tsx @@ -9,11 +9,7 @@ import { EuiButtonIcon, EuiContextMenu, EuiContextMenuPanelDescriptor, - EuiFlexGroup, - EuiFlexItem, - EuiIcon, EuiPopover, - EuiTextProps, EuiToolTip, } from '@elastic/eui'; import { @@ -22,20 +18,12 @@ import { } from '@elastic/eui/src/components/context_menu/context_menu'; import { i18n } from '@kbn/i18n'; import { CoreStart } from 'kibana/public'; -import React, { ReactElement, useState } from 'react'; -import { TableText } from '../'; +import React, { useState } from 'react'; import { SearchSessionsMgmtAPI } from '../../lib/api'; import { UISession } from '../../types'; import { getAction } from './get_action'; import { ACTION, OnActionComplete } from './types'; -// interfaces -interface PopoverActionProps { - textColor?: EuiTextProps['color']; - iconType: string; - children: string | ReactElement; -} - interface PopoverActionItemsProps { session: UISession; api: SearchSessionsMgmtAPI; @@ -43,18 +31,6 @@ interface PopoverActionItemsProps { core: CoreStart; } -// helper -const PopoverAction = ({ textColor, iconType, children, ...props }: PopoverActionProps) => ( - - - - - - {children} - - -); - export const PopoverActionsMenu = ({ api, onActionComplete, @@ -71,10 +47,6 @@ export const PopoverActionsMenu = ({ setPopover(false); }; - const onActionClick = () => { - closePopover(); - }; - const renderPopoverButton = () => ( { - const actionDef = getAction(api, actionType, session, core, onActionClick, onActionComplete); + const actionDef = getAction(api, actionType, session, core); if (actionDef) { - const { label, textColor, iconType } = actionDef; + const { label, iconType, onClick } = actionDef; // add a line above the delete action (when there are multiple) // NOTE: Delete action MUST be the final action[] item @@ -109,16 +81,15 @@ export const PopoverActionsMenu = ({ ...itemSet, { key: `action-${actionType}`, - name: ( - - {label} - - ), - }, + name: label, + icon: iconType, + 'data-test-subj': `sessionManagementPopoverAction-${actionType}`, + onClick: async () => { + closePopover(); + await onClick(); + onActionComplete(); + }, + } as EuiContextMenuPanelItemDescriptorEntry, ]; } return itemSet; @@ -126,20 +97,16 @@ export const PopoverActionsMenu = ({ const panels: EuiContextMenuPanelDescriptor[] = [{ id: 0, items }]; - return ( - <> - {actions.length ? ( - - - - ) : null} - - ); + return actions.length ? ( + + + + ) : null; }; diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/rename_button.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/rename_button.tsx index 6fa0d0d443d71..99639e86c123d 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/rename_button.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/rename_button.tsx @@ -22,24 +22,22 @@ import { FormattedMessage } from '@kbn/i18n/react'; import React, { useState } from 'react'; import { CoreStart } from 'kibana/public'; import { SearchSessionsMgmtAPI } from '../../lib/api'; -import { TableText } from '../'; +import { IClickActionDescriptor } from '../'; import { toMountPoint } from '../../../../../../../../src/plugins/kibana_react/public'; -import { OnActionClick, OnActionComplete, OnActionDismiss } from './types'; +import { OnActionDismiss } from './types'; +import { UISession } from '../../types'; interface RenameButtonProps { - id: string; - name: string; + searchSession: UISession; api: SearchSessionsMgmtAPI; - overlays: CoreStart['overlays']; - onActionComplete: OnActionComplete; - onActionClick: OnActionClick; } const RenameDialog = ({ onActionDismiss, ...props }: RenameButtonProps & { onActionDismiss: OnActionDismiss }) => { - const { id, name: originalName, api, onActionComplete } = props; + const { api, searchSession } = props; + const { id, name: originalName } = searchSession; const [isLoading, setIsLoading] = useState(false); const [newName, setNewName] = useState(originalName); @@ -92,7 +90,6 @@ const RenameDialog = ({ await api.sendRename(id, newName); setIsLoading(false); onActionDismiss(); - onActionComplete(); }} fill isLoading={isLoading} @@ -104,24 +101,21 @@ const RenameDialog = ({ ); }; -export const RenameButton = (props: RenameButtonProps) => { - const { overlays, onActionClick } = props; - - const onClick = () => { - onActionClick(); - const ref = overlays.openModal( - toMountPoint( ref?.close()} {...props} />) +export const createRenameActionDescriptor = ( + api: SearchSessionsMgmtAPI, + uiSession: UISession, + core: CoreStart +): IClickActionDescriptor => ({ + iconType: 'pencil', + label: ( + + ), + onClick: async () => { + const ref = core.overlays.openModal( + toMountPoint( + ref?.close()} api={api} searchSession={uiSession} /> + ) ); - }; - - return ( - <> - - - - - ); -}; + await ref.onClose; + }, +}); diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts index ec0c281d0a4fe..c808f8469cccf 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/actions/types.ts @@ -6,7 +6,6 @@ */ export type OnActionComplete = () => void; -export type OnActionClick = () => void; export type OnActionDismiss = () => void; export enum ACTION { diff --git a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/index.tsx b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/index.tsx index ce92ec5944408..f57ad73c3c760 100644 --- a/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/index.tsx +++ b/x-pack/plugins/data_enhanced/public/search/sessions_mgmt/components/index.tsx @@ -20,9 +20,9 @@ export const TableText = ({ children, ...props }: EuiTextProps) => { }; export interface IClickActionDescriptor { - label: string | React.ReactElement; + label: React.ReactNode; iconType: 'trash' | 'cancel' | typeof extendSessionIcon; - textColor: EuiTextProps['color']; + onClick: () => Promise | void; } export interface IHrefActionDescriptor {