diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid.scss b/src/plugins/discover/public/components/discover_grid/discover_grid.scss index a80f2cd6b5534..4de2d9e8dadee 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid.scss +++ b/src/plugins/discover/public/components/discover_grid/discover_grid.scss @@ -40,6 +40,30 @@ } .dscDiscoverGrid__cellPopover { + min-height: 140px; + max-width: 900px !important; + + &.dscDiscoverGrid__cellPopover--withJson { + resize: horizontal; + min-width: 516px; + width: 516px; + } + + &:not(.dscDiscoverGrid__cellPopover--withJson) { + resize: both; + min-width: 300px; + width: 400px; + max-height: 390px !important; + } + + & > div { + height: 100%; + } +} + +.dscDiscoverGrid__cellPopoverValueContainer { + height: 100%; + // Fixes https://github.com/elastic/kibana/issues/145216 in Chrome .lines-content.monaco-editor-background { overflow: unset !important; 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 2537bc6be16ee..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,6 +30,7 @@ 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 { DiscoverGridSettings } from './types'; @@ -599,6 +600,7 @@ export const DiscoverGrid = ({ onColumnResize={onResize} pagination={paginationObj} renderCellValue={renderCellValue} + renderCellPopover={DiscoverGridCellPopover} ref={dataGridRef} rowCount={rowCount} schemaDetectors={schemaDetectors} diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.test.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.test.tsx new file mode 100644 index 0000000000000..94b44b257b0e5 --- /dev/null +++ b/src/plugins/discover/public/components/discover_grid/discover_grid_cell_popover.test.tsx @@ -0,0 +1,53 @@ +/* + * 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 from 'react'; +import { mount } from 'enzyme'; +import { DiscoverGridCellPopover } from './discover_grid_cell_popover'; + +describe('Discover grid cell popover rendering', function () { + const CellValue = ({ schema }: { schema: string }) => { + return
{schema}
; + }; + + it('renders correctly', () => { + const setMock = jest.fn(); + const component = mount( + {'test'}} + setCellPopoverProps={setMock} + > + + + ); + expect(component.html()).toMatchInlineSnapshot( + `"
string
"` + ); + expect(setMock).toHaveBeenCalledWith({ + panelClassName: 'dscDiscoverGrid__cellPopover', + }); + }); + + it('renders correctly for json view', () => { + const setMock = jest.fn(); + const component = mount( + {'test'}} + setCellPopoverProps={setMock} + > + + + ); + expect(component.html()).toMatchInlineSnapshot( + `"
kibana-json
"` + ); + expect(setMock).toHaveBeenCalledWith({ + panelClassName: 'dscDiscoverGrid__cellPopover dscDiscoverGrid__cellPopover--withJson', + }); + }); +}); 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_value.test.tsx b/src/plugins/discover/public/components/discover_grid/get_render_cell_value.test.tsx index 6307d221fa394..df58a4bda7331 100644 --- a/src/plugins/discover/public/components/discover_grid/get_render_cell_value.test.tsx +++ b/src/plugins/discover/public/components/discover_grid/get_render_cell_value.test.tsx @@ -120,7 +120,7 @@ describe('Discover grid cell rendering', function () { /> ); expect(component.html()).toMatchInlineSnapshot( - `"
100
"` + `"
100
"` ); }); @@ -146,7 +146,7 @@ describe('Discover grid cell rendering', function () { /> ); expect(component.html()).toMatchInlineSnapshot( - `"
100
"` + `"
100
"` ); findTestSubject(component, 'docTableClosePopover').simulate('click'); expect(closePopoverMockFn).toHaveBeenCalledTimes(1); @@ -248,7 +248,7 @@ describe('Discover grid cell rendering', function () { ); expect(component).toMatchInlineSnapshot(` - + @@ -480,7 +491,7 @@ describe('Discover grid cell rendering', function () { ); expect(component).toMatchInlineSnapshot(` - + @@ -644,7 +666,7 @@ describe('Discover grid cell rendering', function () { ); expect(component).toMatchInlineSnapshot(` - + @@ -865,16 +898,18 @@ describe('Discover grid cell rendering', function () { responsive={false} > - + + /> + {closeButton} - - + + ); @@ -214,20 +216,22 @@ function renderPopoverContent({ return ( - + + + {closeButton}