-
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] [Unified Data Table] Improve absolute column width handling #190288
Conversation
/ci |
… least one auto width column by default
… width column is removed
1ea3a8c
to
2603c14
Compare
/ci |
/ci |
true | ||
); | ||
expect(findTestSubject(component, 'gridEditFieldButton').exists()).toBe(true); | ||
renderDataTable({ columns: ['message'], onFieldEdited: jest.fn() }); |
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 needed to rewrite these tests in RTL because Enzyme doesn't properly clean up portals after tests (used for the column header popovers), causing my new tests below to fail.
/ci |
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
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.
Nice! Thanks for implementing the column width reset!
@@ -9,13 +9,13 @@ | |||
import type { DiscoverGridSettings } from '@kbn/saved-search-plugin/common'; | |||
|
|||
export const onResizeGridColumn = ( | |||
colSettings: { columnId: string; width: number }, | |||
colSettings: { columnId: string; width?: number }, |
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.
nit to make it more explicit that the width is not missing rather needs to be reset.
We could also leave a comment explaining the logic.
colSettings: { columnId: string; width?: number }, | |
colSettings: { columnId: string; width: number | undefined }, |
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.
Agreed 👍 Updated here and added comments explaining why it can be undefined
: 9844535
// When columns are modified, reset the last column to auto width if only absolute | ||
// width columns remain, to ensure the columns fill the available grid space | ||
const prevColumns = useRef<string[]>(); | ||
|
||
useEffect(() => { | ||
if (isEqual(prevColumns.current, visibleColumns)) { | ||
return; | ||
} | ||
|
||
prevColumns.current = visibleColumns; | ||
|
||
const hasAutoWidthColumn = visibleColumns.some( | ||
(colId) => euiGridColumns.find((col) => col.id === colId)?.initialWidth == null | ||
); | ||
|
||
if (!hasAutoWidthColumn) { | ||
onResize?.({ columnId: visibleColumns[visibleColumns.length - 1] }); | ||
} | ||
}, [euiGridColumns, onResize, visibleColumns]); | ||
|
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 wanted to save a search with all fixed width columns. But once saved/reloaded, the last column got reset and "Unsaved changes" badge appeared. Is it because of this code?
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.
Yeah, this turned out to be a pretty naive implementation. I tested it more thoroughly and ran into several edge cases where it would fail. I updated to a more robust approach here, which also allows consumers to have more control over the behaviour: 7b3583e. I'll need to update tests tomorrow for the new approach.
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.
Tests updated: 4cf2b41
@@ -179,7 +180,7 @@ function DiscoverDocumentsComponent({ | |||
[stateContainer] | |||
); | |||
|
|||
const onResizeDataGrid = useCallback( | |||
const onResizeDataGrid = useCallback<NonNullable<UnifiedDataTableProps['onResize']>>( |
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 also checked Dashboard page and it does not seem to offer resetting a column width. Should it?
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.
That was because the saved search embeddable didn't support onResize
or grid
modifications, but I added support for it now: 7b3583e.
…olumn resizing to surrounding docs and saved search panels
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.
CSP posture changes LGTM!
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.
Works great, thanks! 👍
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.
Thank you for making the changes in security solution as well. Works wonderfully!
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Public APIs missing comments
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @davismcphee |
Summary
This PR improves the handling of columns with absolute widths in Discover, including the following enhancements:
absolute_width.mp4
Resolves #189817.
Related #188550.
Checklist
For maintainers