diff --git a/x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/lens_saved_objects_modal.tsx b/x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/lens_saved_objects_modal.tsx deleted file mode 100644 index 1fa23c01d68f5..0000000000000 --- a/x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/lens_saved_objects_modal.tsx +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - EuiModal, - EuiModalProps, - EuiModalBody, - EuiModalHeader, - EuiModalHeaderTitle, -} from '@elastic/eui'; -import { i18n } from '@kbn/i18n'; -import { FormattedMessage } from '@kbn/i18n/react'; -import React, { useMemo } from 'react'; - -import { - SavedObjectFinderUi, - SavedObjectFinderUiProps, -} from '../../../../../../../../src/plugins/saved_objects/public'; -import { useKibana } from '../../../../common/lib/kibana'; -import { ModalContainer } from './modal_container'; - -interface LensSavedObjectsModalProps { - onClose: EuiModalProps['onClose']; - onChoose: SavedObjectFinderUiProps['onChoose']; -} - -const LensSavedObjectsModalComponent: React.FC = ({ - onClose, - onChoose, -}) => { - const { savedObjects, uiSettings } = useKibana().services; - - const savedObjectMetaData = useMemo( - () => [ - { - type: 'lens', - getIconForSavedObject: () => 'lensApp', - name: i18n.translate( - 'xpack.cases.markdownEditor.plugins.lens.insertLensSavedObjectModal.searchSelection.savedObjectType.lens', - { - defaultMessage: 'Lens', - } - ), - includeFields: ['*'], - }, - ], - [] - ); - - return ( - - - - -

- -

-
-
- - - - } - savedObjectMetaData={savedObjectMetaData} - fixedPageSize={10} - uiSettings={uiSettings} - savedObjects={savedObjects} - /> - -
-
- ); -}; - -export const LensSavedObjectsModal = React.memo(LensSavedObjectsModalComponent); diff --git a/x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/plugin.tsx b/x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/plugin.tsx index 270489be2d0ab..d9451a3a37829 100644 --- a/x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/plugin.tsx +++ b/x-pack/plugins/cases/public/components/markdown_editor/plugins/lens/plugin.tsx @@ -22,23 +22,36 @@ import { EuiFlexGroup, EuiFormRow, EuiMarkdownAstNodePosition, + EuiBetaBadge, } from '@elastic/eui'; -import React, { useCallback, useContext, useMemo, useEffect, useState } from 'react'; +import React, { ReactNode, useCallback, useContext, useMemo, useEffect, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { useLocation } from 'react-router-dom'; +import styled from 'styled-components'; import type { TypedLensByValueInput } from '../../../../../../lens/public'; import { useKibana } from '../../../../common/lib/kibana'; import { LensMarkDownRenderer } from './processor'; import { DRAFT_COMMENT_STORAGE_ID, ID } from './constants'; import { CommentEditorContext } from '../../context'; -import { LensSavedObjectsModal } from './lens_saved_objects_modal'; import { ModalContainer } from './modal_container'; import type { EmbeddablePackageState, EmbeddableInput, } from '../../../../../../../../src/plugins/embeddable/public'; +import { + SavedObjectFinderUi, + SavedObjectFinderUiProps, +} from '../../../../../../../../src/plugins/saved_objects/public'; + +const BetaBadgeWrapper = styled.span` + display: inline-flex; + + .euiToolTipAnchor { + display: inline-flex; + } +`; type LensIncomingEmbeddablePackage = Omit & { input: Omit & { @@ -56,6 +69,56 @@ type LensEuiMarkdownEditorUiPlugin = EuiMarkdownEditorUiPlugin<{ attributes: TypedLensByValueInput['attributes']; }>; +interface LensSavedObjectsPickerProps { + children: ReactNode; + onChoose: SavedObjectFinderUiProps['onChoose']; +} + +const LensSavedObjectsPickerComponent: React.FC = ({ + children, + onChoose, +}) => { + const { savedObjects, uiSettings } = useKibana().services; + + const savedObjectMetaData = useMemo( + () => [ + { + type: 'lens', + getIconForSavedObject: () => 'lensApp', + name: i18n.translate( + 'xpack.cases.markdownEditor.plugins.lens.insertLensSavedObjectModal.searchSelection.savedObjectType.lens', + { + defaultMessage: 'Lens', + } + ), + includeFields: ['*'], + }, + ], + [] + ); + + return ( + + } + savedObjectMetaData={savedObjectMetaData} + fixedPageSize={10} + uiSettings={uiSettings} + savedObjects={savedObjects} + children={children} + /> + ); +}; + +export const LensSavedObjectsPicker = React.memo(LensSavedObjectsPickerComponent); + const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({ node, onCancel, @@ -73,7 +136,6 @@ const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({ }, }, } = useKibana().services; - const [currentAppId, setCurrentAppId] = useState(undefined); const [editMode, setEditMode] = useState(!!node); @@ -87,7 +149,6 @@ const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({ mode: 'relative', } ); - const [showLensSavedObjectsModal, setShowLensSavedObjectsModal] = useState(false); const commentEditorContext = useContext(CommentEditorContext); const markdownContext = useContext(EuiMarkdownContext); @@ -221,8 +282,6 @@ const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({ [handleEditInLensClick] ); - const handleCloseLensSOModal = useCallback(() => setShowLensSavedObjectsModal(false), []); - useEffect(() => { if (node?.attributes) { setLensEmbeddableAttributes(node.attributes); @@ -272,58 +331,50 @@ const LensEditorComponent: LensEuiMarkdownEditorUiPlugin['editor'] = ({ }, [embeddable, storage, timefilter, currentAppId]); return ( - <> - - - - {editMode ? ( - - ) : ( - - )} - - - - - - handleEditInLensClick()} - color="primary" - size="m" - iconType="lensApp" - fill - > + + + + + + {editMode ? ( - - - - setShowLensSavedObjectsModal(true)} - > + ) : ( - + )} + + + + + - {lensEmbeddableAttributes ? ( + + + + {lensEmbeddableAttributes ? ( + <> - + - - - handleEditInLensClick()} - > - - - + + handleEditInLensClick()} + > + + - ) : null} - - - - - {'Cancel'} - {editMode ? ( - - - - ) : null} - - {editMode ? ( - - ) : ( - - )} + + + + ) : ( + + + handleEditInLensClick()} + color="primary" + size="m" + iconType="lensApp" + fill + > + + + + + )} + + + {'Cancel'} + {editMode ? ( + + - - - {showLensSavedObjectsModal ? ( - - ) : null} - + ) : null} + + {editMode ? ( + + ) : ( + + )} + + + ); };