-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discover] Optimize popover size for grid cell expansion #152480
Draft
jughosta
wants to merge
12
commits into
elastic:main
Choose a base branch
from
jughosta:132309-grid-cell-popover
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9cdf026
[Discover] Resizable cell popover and larger JSON popover
jughosta 2dea2a3
[Discover] Some updates
jughosta 1447383
[Discover] Some updates
jughosta cc769f3
Merge remote-tracking branch 'upstream/main' into 132309-grid-cell-po…
jughosta 652b845
[Discover] Use eui api
jughosta cc69478
[Discover] Update styles
jughosta 5555c83
[Discover] Remove redundant class
jughosta 4afb920
[Discover] Update snapshots
jughosta ff5832c
[Discover] Add tests
jughosta 6776534
Merge branch 'main' into 132309-grid-cell-popover
kertal b9d945d
Merge remote-tracking branch 'upstream/main' into 132309-grid-cell-po…
jughosta 17cbe9b
[Discover] Change the signature
jughosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ import { getSchemaDetectors } from './discover_grid_schema'; | |
import { DiscoverGridFlyout } from './discover_grid_flyout'; | ||
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, | ||
|
@@ -380,6 +381,8 @@ export const DiscoverGrid = ({ | |
[dataView, displayedRows, useNewFieldsApi, shouldShowFieldHandler, services.uiSettings] | ||
); | ||
|
||
const renderCellPopover = useMemo(() => getRenderCellPopoverFn(), []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: it seems like it would be simpler to pass in something like a |
||
|
||
/** | ||
* Render variables | ||
*/ | ||
|
@@ -601,6 +604,7 @@ export const DiscoverGrid = ({ | |
onColumnResize={onResize} | ||
pagination={paginationObj} | ||
renderCellValue={renderCellValue} | ||
renderCellPopover={renderCellPopover} | ||
ref={dataGridRef} | ||
rowCount={rowCount} | ||
schemaDetectors={schemaDetectors} | ||
|
57 changes: 57 additions & 0 deletions
57
src/plugins/discover/public/components/discover_grid/get_render_cell_popover.test.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,57 @@ | ||
/* | ||
* 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 { getRenderCellPopoverFn } from './get_render_cell_popover'; | ||
import { EuiDataGridCellPopoverElementProps } from '@elastic/eui'; | ||
|
||
describe('Discover grid cell popover rendering', function () { | ||
const DiscoverGridCellPopover = getRenderCellPopoverFn() as React.FC< | ||
Pick<EuiDataGridCellPopoverElementProps, 'cellActions' | 'setCellPopoverProps'> | ||
>; | ||
const CellValue = ({ schema }: { schema: string }) => { | ||
return <div>{schema}</div>; | ||
}; | ||
|
||
it('renders correctly', () => { | ||
const setMock = jest.fn(); | ||
const component = mount( | ||
<DiscoverGridCellPopover | ||
cellActions={<button>{'test'}</button>} | ||
setCellPopoverProps={setMock} | ||
> | ||
<CellValue schema="string" /> | ||
</DiscoverGridCellPopover> | ||
); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"euiFlexGroup css-4b375e\\"><div class=\\"euiFlexItem css-9sbomz-euiFlexItem-grow-1\\"><div>string</div></div><div class=\\"euiFlexItem css-kpsrin-euiFlexItem-growZero\\"><button>test</button></div></div>"` | ||
); | ||
expect(setMock).toHaveBeenCalledWith({ | ||
panelClassName: 'dscDiscoverGrid__cellPopover', | ||
}); | ||
}); | ||
|
||
it('renders correctly for json view', () => { | ||
const setMock = jest.fn(); | ||
const component = mount( | ||
<DiscoverGridCellPopover | ||
cellActions={<button>{'test'}</button>} | ||
setCellPopoverProps={setMock} | ||
> | ||
<CellValue schema="kibana-json" /> | ||
</DiscoverGridCellPopover> | ||
); | ||
expect(component.html()).toMatchInlineSnapshot( | ||
`"<div class=\\"euiFlexGroup css-4b375e\\"><div class=\\"euiFlexItem css-9sbomz-euiFlexItem-grow-1\\"><div>kibana-json</div></div><div class=\\"euiFlexItem css-kpsrin-euiFlexItem-growZero\\"><button>test</button></div></div>"` | ||
); | ||
expect(setMock).toHaveBeenCalledWith({ | ||
panelClassName: 'dscDiscoverGrid__cellPopover dscDiscoverGrid__cellPopover--withJson', | ||
}); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
src/plugins/discover/public/components/discover_grid/get_render_cell_popover.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,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 { 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 ( | ||
<EuiFlexGroup responsive={false} direction="column" gutterSize="none" css={containerStyles}> | ||
<EuiFlexItem grow={true}>{children}</EuiFlexItem> | ||
<EuiFlexItem grow={false}>{cellActions}</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely think, even if we decide not to allow resizing, having the JSON view in a larger dimension makes much sense