-
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
Changes from 6 commits
94fbbb5
406528a
13c52f1
2603c14
0c656e4
ad227b5
9844535
7b3583e
641eee3
4cf2b41
5b8a656
6c32514
489c502
0857c7b
c655977
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ import type { ThemeServiceStart } from '@kbn/react-kibana-context-common'; | |
import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; | ||
import type { DocViewFilterFn } from '@kbn/unified-doc-viewer/types'; | ||
import { AdditionalFieldGroups } from '@kbn/unified-field-list'; | ||
import { isEqual } from 'lodash'; | ||
import { | ||
UnifiedDataTableSettings, | ||
ValueToStringConverter, | ||
|
@@ -163,7 +164,7 @@ export interface UnifiedDataTableProps { | |
/** | ||
* Function triggered when a column is resized by the user | ||
*/ | ||
onResize?: (colSettings: { columnId: string; width: number }) => void; | ||
onResize?: (colSettings: { columnId: string; width?: number }) => void; | ||
/** | ||
* Function to set all columns | ||
*/ | ||
|
@@ -778,6 +779,7 @@ export const UnifiedDataTable = ({ | |
showColumnTokens, | ||
headerRowHeightLines, | ||
customGridColumnsConfiguration, | ||
onResize, | ||
}), | ||
[ | ||
columnsMeta, | ||
|
@@ -792,6 +794,7 @@ export const UnifiedDataTable = ({ | |
isPlainRecord, | ||
isSortEnabled, | ||
onFilter, | ||
onResize, | ||
settings, | ||
showColumnTokens, | ||
toastNotifications, | ||
|
@@ -814,6 +817,26 @@ export const UnifiedDataTable = ({ | |
[visibleColumns, onSetColumns, shouldPrependTimeFieldColumn] | ||
); | ||
|
||
// 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Tests updated: 4cf2b41 |
||
/** | ||
* Sorting | ||
*/ | ||
|
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.