Skip to content
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

Merged
merged 15 commits into from
Aug 20, 2024

Conversation

davismcphee
Copy link
Contributor

@davismcphee davismcphee commented Aug 12, 2024

Summary

This PR improves the handling of columns with absolute widths in Discover, including the following enhancements:

  • If there are no auto width columns in the profile default app state, set the last column to auto width so the default columns always fill the grid.
  • If there are no auto width columns remaining when removing a column from the grid, set the last column to auto width so the remaining columns fill the grid.
  • Add a "Reset width" button to the column header popovers to allow resetting absolute width columns back to auto width.
absolute_width.mp4

Resolves #189817.
Related #188550.

Checklist

For maintainers

@davismcphee davismcphee added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. Project:OneDiscover Enrich Discover with contextual awareness labels Aug 12, 2024
@davismcphee davismcphee self-assigned this Aug 12, 2024
@davismcphee
Copy link
Contributor Author

/ci

@davismcphee davismcphee force-pushed the empty-default-columns branch from 1ea3a8c to 2603c14 Compare August 12, 2024 22:17
@davismcphee
Copy link
Contributor Author

/ci

@davismcphee
Copy link
Contributor Author

/ci

true
);
expect(findTestSubject(component, 'gridEditFieldButton').exists()).toBe(true);
renderDataTable({ columns: ['message'], onFieldEdited: jest.fn() });
Copy link
Contributor Author

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.

@davismcphee
Copy link
Contributor Author

/ci

@davismcphee davismcphee changed the title [Discover] Hide default profile columns without values [Discover] [Unified Data Table] Improve absolute column width handling Aug 13, 2024
@davismcphee davismcphee added release_note:enhancement and removed release_note:skip Skip the PR/issue when compiling release notes labels Aug 13, 2024
@davismcphee davismcphee marked this pull request as ready for review August 14, 2024 01:33
@davismcphee davismcphee requested review from a team as code owners August 14, 2024 01:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Copy link
Contributor

@jughosta jughosta left a 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 },
Copy link
Contributor

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.

Suggested change
colSettings: { columnId: string; width?: number },
colSettings: { columnId: string; width: number | undefined },

Copy link
Contributor Author

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

Comment on lines 820 to 839
// 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]);

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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']>>(
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@opauloh opauloh left a 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!

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, thanks! 👍

Copy link
Contributor

@michaelolo24 michaelolo24 left a 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!

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/unified-data-table 94 108 +14

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 479.3KB 480.4KB +1.1KB
discover 844.1KB 843.6KB -524.0B
esqlDataGrid 129.1KB 129.4KB +345.0B
securitySolution 20.7MB 20.7MB +3.9KB
slo 915.5KB 915.9KB +345.0B
total +5.2KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
discover 47.7KB 47.7KB +7.0B
Unknown metric groups

API count

id before after diff
@kbn/unified-data-table 170 184 +14

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @davismcphee

@davismcphee davismcphee merged commit 349fdac into elastic:main Aug 20, 2024
40 checks passed
@davismcphee davismcphee deleted the empty-default-columns branch August 20, 2024 20:27
@davismcphee davismcphee linked an issue Nov 5, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Project:OneDiscover Enrich Discover with contextual awareness release_note:enhancement Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.16.0
Projects
None yet
7 participants