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] Add document comparison mode #166577

Merged
merged 73 commits into from
Apr 10, 2024

Conversation

davismcphee
Copy link
Contributor

@davismcphee davismcphee commented Sep 18, 2023

Summary

This PR adds a new document comparison mode to Discover and Unified Data Table:
diff

Flaky test runner x50: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5590.

Resolves #93567.

Checklist

For maintainers

@davismcphee davismcphee added Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Data, DataViews) labels Sep 18, 2023
@davismcphee davismcphee self-assigned this Sep 18, 2023
@andreadelrio
Copy link
Contributor

andreadelrio commented Feb 7, 2024

@davismcphee this is looking amazing! I'm sending you a first round of design-related comments and ideas I would like us to consider:

  1. Highlight the "Selected" button more by using the success notification badge.
Frame 10
  1. Use buttons in the style of the ones we have for the document table data grid. The buttons would be: Show diff, Diff settings, Exit comparison mode.

  2. Have a text indicating the mode we're in and the number of documents under comparison (i.e. Comparing 3 documents). This would follow the same format we have planned for the 1,245 documents text in the main view.

  3. Add a pinFilled icon to the header of the first column.

Frame 7
  1. Use a toggle button for the Show diff toggle. See screenshot below for the on styling.

  2. Use a different background color for the pinned column. Maybe subdued?

Frame 8
  1. Have a consolidated Diff settings menu (see below). Where each badge shows a tooltip explaining what Advanced mode means.
Frame 9
  1. Are we planning on having the option to disable the zebra stripping?

@davismcphee davismcphee force-pushed the discover-doc-compare branch 2 times, most recently from 175d1f6 to 6304bab Compare March 25, 2024 00:53
@davismcphee
Copy link
Contributor Author

/ci

@amyjtechwriter amyjtechwriter self-requested a review March 26, 2024 14:03
@davismcphee
Copy link
Contributor Author

/ci

Copy link
Contributor Author

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback! I've made some changes based on the suggestions and updated mockups.

What should we do with smart fields?

I think we should treat this as a known bug and address it when we integrate smart fields as a native Discover feature, similar to what we're planning for the field statistics tab. But I can definitely create a separate issue to track it so we don't forget.

From what I understand we pick documents by their id when rendering columns for comparison, right? The thing is that documents can have same ids but come from different indices. We had such bug in DocViewer in the past.

The comparison mode is based on our existing selected documents logic, which depends on the generated ID in DataTableRecord to guarantee uniqueness. The only place we use the raw document ID is for displaying in the comparison table headers (so we could technically see a duplicate ID in the headers, although I think the chances of that happening are quite low, and the functionality will still work as expected):

/**
* Returning a generated id of a given ES document, since `_id` can be the same
* when using different indices and shard routing
*/
export const getDocId = (doc: EsHitRecord & { _routing?: string }) => {
const routing = doc._routing ? doc._routing : '';
return [doc._index, doc._id, routing].join('::');
};

Copy link
Contributor

@amyjtechwriter amyjtechwriter left a comment

Choose a reason for hiding this comment

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

LGTM, labels and docs side. Hopefully I have answered all the comments tagged in but if I've missed anything please let me know!

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.

Looking great!

I like the separate "Compare" button! The new highlight on both buttons seem a bit distracting though.

I also tested a case when user selects documents for comparison, then changes the time range and those documents are gone. We could probably improve UI by showing a message that documents are not available anymore or something like it.

Currently, when 1 of 2 documents is gone after refetch:
Screenshot 2024-04-08 at 11 09 53

When 2 out of 2 documents are gone:
Screenshot 2024-04-08 at 11 09 45

setSelectedDocs,
setIsCompareActive,
}: CompareDocumentsProps) => {
const [showDiff, setShowDiff] = useLocalStorage(getStorageKey(consumer, 'ShowDiff'), true);
Copy link
Contributor

Choose a reason for hiding this comment

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

If user toggles "Show diff" off, exits the comparison mode, then next time they press "Compare" button, should not it get enabled again? Otherwise why to go to comparison mode if it's off.

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 think we should keep this in local storage to be consistent with the other settings. In most cases users probably won't have a reason to disable diffing, but there are some legitimate use cases such as just wanting to view multiple documents in a vertical format similar to the doc viewer, or wanting to retain the original colours when viewing documents that use the colour field formatter instead of having them overwritten by the diff colours. This way they can exist comparison mode, select more documents, and return to comparison mode without having to keep disabling "Show diff".

No diff:
no_diff

Diff:
diff

@andreadelrio
Copy link
Contributor

I like the separate "Compare" button! The new highlight on both buttons seem a bit distracting though.

@davismcphee I agree with Julia. I think with the new dedicated Compare button we can get rid of the success color in the buttons. This will also help us achieve consistency with the rest of the buttons.

Copy link
Contributor

@andreadelrio andreadelrio left a comment

Choose a reason for hiding this comment

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

@davismcphee Thanks for implementing the changes to this menu. Adding some comments below.

image

I think leaving the Basic/Advanced options enabled when Show diff is set to off looks a bit odd. We could consider disabling them when Show diff is set to off and adding a tooltip explaining why such as "You need to enable Show diff".

Same goes for the Show diff decorations toggle. If Show diff is set to off, this toggle should be disabled.

Copy link
Contributor Author

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

@jughosta @andreadelrio thanks both for the feedback!

I updated both of the button badges back to the original colour now:
badges

I also updated the settings menu to disable the diff mode entries and decorations switch, and added a tooltip, when "Show diff" is off:
disabled

I also tested a case when user selects documents for comparison, then changes the time range and those documents are gone. We could probably improve UI by showing a message that documents are not available anymore or something like it.

@jughosta good catch! Rather than showing a message when the documents are no longer available, I instead made it so the columns remain visible in the comparison table until the user exists comparison mode: 8c5bcaa. I feel like this is a bit more friendly to users so they don't accidentally lose the documents they're comparing if they trigger a refetch or have auto refresh enabled. WDYT?

setSelectedDocs,
setIsCompareActive,
}: CompareDocumentsProps) => {
const [showDiff, setShowDiff] = useLocalStorage(getStorageKey(consumer, 'ShowDiff'), true);
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 think we should keep this in local storage to be consistent with the other settings. In most cases users probably won't have a reason to disable diffing, but there are some legitimate use cases such as just wanting to view multiple documents in a vertical format similar to the doc viewer, or wanting to retain the original colours when viewing documents that use the colour field formatter instead of having them overwritten by the diff colours. This way they can exist comparison mode, select more documents, and return to comparison mode without having to keep disabling "Show diff".

No diff:
no_diff

Diff:
diff

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.

Great work, Davis! My favourite feature now! 👍 🎉
And thanks, @kertal, for proposing it!

Copy link
Contributor

@andreadelrio andreadelrio left a comment

Choose a reason for hiding this comment

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

Superb job on this Davis! I'm approving now but I would like to confirm with @amyjtechwriter whether the text in the new tooltip looks good to her.

image

@amyjtechwriter
Copy link
Contributor

Hey hey, we can keep "You need to enable Show Diff" or if you think it's just as clear we could just use "Enable Show diff". I don't have a super strong preference here, so I think go with the one you like best :)

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Such a great feature, so much great fine tuning! Really great work 🥳 Let's 🚢 !

Great work, Davis! My favourite feature now! 👍 🎉
And thanks, @kertal, for proposing it!

Thx to @andreadelrio for the mockups in 2021 built by just a very basic description in the issue we resolve. Something like this is so important showing a potential useful concept in action. One can write a lot of good description how something should work, but an animated mock is always better 👍

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #94 / dashboard app - group 2 dashboard filtering adding a filter that excludes all data "before all" hook for "filters on pie charts"

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cloudSecurityPosture 416 432 +16
discover 778 788 +10
lens 1385 1401 +16
logsExplorer 710 726 +16
securitySolution 5301 5316 +15
slo 673 689 +16
total +89

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 78 83 +5

Async chunks

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

id before after diff
cloudSecurityPosture 402.1KB 449.7KB +47.6KB
discover 592.3KB 636.7KB +44.3KB
securitySolution 17.0MB 17.1MB +60.7KB
slo 611.0KB 660.9KB +49.9KB
total +202.6KB

Page load bundle

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

id before after diff
cloudSecurityPosture 15.9KB 16.0KB +69.0B
Unknown metric groups

API count

id before after diff
@kbn/unified-data-table 144 151 +7

async chunk count

id before after diff
cloudSecurityPosture 5 6 +1
discover 21 22 +1
securitySolution 66 67 +1
slo 25 26 +1
total +4

ESLint disabled line counts

id before after diff
@kbn/unified-data-table 8 10 +2

Total ESLint disabled count

id before after diff
@kbn/unified-data-table 8 10 +2

History

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

cc @andreadelrio @davismcphee

@davismcphee
Copy link
Contributor Author

Thanks all for helping bring this over the finish line! It seems like we're good with the current tooltip text, so I'm going to merge this now 🙂

@davismcphee davismcphee merged commit 339379e into elastic:main Apr 10, 2024
17 checks passed
@davismcphee davismcphee deleted the discover-doc-compare branch April 10, 2024 19:49
@kibanamachine kibanamachine added v8.14.0 backport:skip This commit does not require backporting labels Apr 10, 2024
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 Feature:Discover Discover Application Feature:UnifiedDataTable release_note:feature Makes this part of the condensed release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Data, DataViews) v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UnifiedDataTable] Add document/field diffing
8 participants