diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid.tsx index 9285bdab045a5..2a9c29cf40b75 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid.tsx @@ -30,9 +30,9 @@ import { DataViewFieldEditorStart } from '@kbn/data-view-field-editor-plugin/pub import { DocViewFilterFn } from '../../services/doc_views/doc_views_types'; import { getSchemaDetectors } from './discover_grid_schema'; import { DiscoverGridFlyout } from './discover_grid_flyout'; +import { DiscoverGridCellPopover } from './discover_grid_cell_popover'; import { DiscoverGridContext } from './discover_grid_context'; import { getRenderCellValueFn } from './get_render_cell_value'; -import { getRenderCellPopoverFn } from './get_render_cell_popover'; import { DiscoverGridSettings } from './types'; import { getEuiGridColumns, @@ -379,8 +379,6 @@ export const DiscoverGrid = ({ [dataView, displayedRows, useNewFieldsApi, shouldShowFieldHandler, services.uiSettings] ); - const renderCellPopover = useMemo(() => getRenderCellPopoverFn(), []); - /** * Render variables */ @@ -602,7 +600,7 @@ export const DiscoverGrid = ({ onColumnResize={onResize} pagination={paginationObj} renderCellValue={renderCellValue} - renderCellPopover={renderCellPopover} + renderCellPopover={DiscoverGridCellPopover} ref={dataGridRef} rowCount={rowCount} schemaDetectors={schemaDetectors} diff --git a/src/plugins/discover/public/components/discover_grid/get_render_cell_popover.test.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.test.tsx similarity index 87% rename from src/plugins/discover/public/components/discover_grid/get_render_cell_popover.test.tsx rename to src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.test.tsx index 6f7f336c1577c..94b44b257b0e5 100644 --- a/src/plugins/discover/public/components/discover_grid/get_render_cell_popover.test.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.test.tsx @@ -8,13 +8,9 @@ import React from 'react'; import { mount } from 'enzyme'; -import { getRenderCellPopoverFn } from './get_render_cell_popover'; -import { EuiDataGridCellPopoverElementProps } from '@elastic/eui'; +import { DiscoverGridCellPopover } from './discover_grid_cell_popover'; describe('Discover grid cell popover rendering', function () { - const DiscoverGridCellPopover = getRenderCellPopoverFn() as React.FC< - Pick - >; const CellValue = ({ schema }: { schema: string }) => { return
{schema}
; }; diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.tsx new file mode 100644 index 0000000000000..4d37cfe793715 --- /dev/null +++ b/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.tsx @@ -0,0 +1,39 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React, { useEffect } from 'react'; +import { css } from '@emotion/react'; +import classnames from 'classnames'; +import { EuiDataGridCellPopoverElementProps, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; + +const containerStyles = css` + height: 100%; +`; + +export const DiscoverGridCellPopover: React.FC< + Pick +> = ({ cellActions, setCellPopoverProps, children }) => { + useEffect(() => { + setCellPopoverProps({ + panelClassName: classnames('dscDiscoverGrid__cellPopover', { + 'dscDiscoverGrid__cellPopover--withJson': + children && + typeof children === 'object' && + 'props' in children && + children.props?.schema === 'kibana-json', + }), + }); + }, [setCellPopoverProps, children]); + + return ( + + {children} + {cellActions} + + ); +}; diff --git a/src/plugins/discover/public/components/discover_grid/get_render_cell_popover.tsx b/src/plugins/discover/public/components/discover_grid/get_render_cell_popover.tsx deleted file mode 100644 index aa82223c8710c..0000000000000 --- a/src/plugins/discover/public/components/discover_grid/get_render_cell_popover.tsx +++ /dev/null @@ -1,39 +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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React, { useEffect } from 'react'; -import { css } from '@emotion/react'; -import classnames from 'classnames'; -import { EuiDataGridProps, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; - -const containerStyles = css` - height: 100%; -`; - -export const getRenderCellPopoverFn = - (): EuiDataGridProps['renderCellPopover'] => - ({ cellActions, setCellPopoverProps, children }) => { - useEffect(() => { - setCellPopoverProps({ - panelClassName: classnames('dscDiscoverGrid__cellPopover', { - 'dscDiscoverGrid__cellPopover--withJson': - children && - typeof children === 'object' && - 'props' in children && - children.props?.schema === 'kibana-json', - }), - }); - }, [setCellPopoverProps, children]); - - return ( - - {children} - {cellActions} - - ); - };