Skip to content

Comments

[Unified Histogram] [Discover] Unified Histogram solutions cleanup#146352

Merged
davismcphee merged 23 commits intoelastic:mainfrom
davismcphee:unified-histogram-manual-fetch
Jan 18, 2023
Merged

[Unified Histogram] [Discover] Unified Histogram solutions cleanup#146352
davismcphee merged 23 commits intoelastic:mainfrom
davismcphee:unified-histogram-manual-fetch

Conversation

@davismcphee
Copy link
Contributor

@davismcphee davismcphee commented Nov 27, 2022

Summary

This PR includes a number of updates to Unified Histogram to prepare for sharing with solutions, as well as updating its usage in Discover:

Unified Histogram:

  • Adds a disableAutoFetching prop, similar to Unified Field List, to disable automatic Unified Histogram refetching based on prop changes.
  • Accepts an input$ observable prop that can be used to control manual refetches.
  • Removes refetchId used internally and replaces it with an observables based approach to simplify refetch logic.
  • Introduces a use_stable_callback utility hook to create callback functions with stable identities which simplifies useCallback logic — should be replaced with useEvent or whatever the React team comes up with to solve this specific issue when available: RFC: useEvent reactjs/rfcs#220.
  • Eliminates debouncing logic in Unified Histogram since it was hacky — manual refetching should be used instead if debouncing is needed.
  • Accepts query, filters, and timeRange props to remove dependencies on specific services.
  • Updates use_request_params to export getTimeRange and updateTimeRange functions for easier absolute time range handling.
  • Exposes some Lens embeddable props to allow further customizing Unified Histogram behaviour.

Discover:

  • Exports a fetch$ observable from use_saved_search to allow listening for when data fetches should be triggered.
  • Uses new manual refetching support in Unified Histogram to simplify refetching logic.
  • Passes query, filters, and timeRange props to Unified Histogram.

Checklist

For maintainers

@davismcphee davismcphee added Feature:Discover Discover Application enhancement New value added to drive a business result release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// v8.7.0 labels Nov 27, 2022
@davismcphee davismcphee self-assigned this Nov 27, 2022
@davismcphee davismcphee force-pushed the unified-histogram-manual-fetch branch 3 times, most recently from 374df21 to 7e62e31 Compare December 12, 2022 01:00
@davismcphee davismcphee force-pushed the unified-histogram-manual-fetch branch 2 times, most recently from 9755251 to ff9af0b Compare December 16, 2022 03:35
@davismcphee davismcphee force-pushed the unified-histogram-manual-fetch branch from 8eb9760 to 0057c9d Compare January 6, 2023 01:00
@davismcphee davismcphee force-pushed the unified-histogram-manual-fetch branch from 7cbc16c to bfcd21a Compare January 9, 2023 16:22
@davismcphee davismcphee added the Feature:UnifiedHistogram Issues related to the Unified Histogram plugin label Jan 9, 2023
@davismcphee davismcphee changed the title [Discover] Unified Histogram solutions cleanup [Unified Histogram] [Discover] Unified Histogram solutions cleanup Jan 9, 2023
@davismcphee davismcphee marked this pull request as ready for review January 9, 2023 19:19
@davismcphee davismcphee requested a review from a team as a code owner January 9, 2023 19:19
@elasticmachine
Copy link
Contributor

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

@kertal kertal self-requested a review January 13, 2023 14:04
Comment on lines 179 to 191
[
data,
initialFetchStatus,
inspectorAdapters.requests,
main$,
refetch$,
searchSessionManager,
searchSource,
initialFetchStatus,
});
services.toastNotifications,
setAutoRefreshDone,
timefilter,
]
);
Copy link
Member

Choose a reason for hiding this comment

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

those deps will soon be gone, just saying ... with the whole file saved from a hook ... #148614

* Accepts a callback and returns a function with a stable identity
* that will always call the latest version of the callback when invoked
*/
export const useStableCallback = <T extends (...args: any[]) => any>(fn: T | undefined) => {
Copy link
Member

Choose a reason for hiding this comment

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

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's actually where I went looking for an implementation originally, but unfortunately had to fall back on a custom one. Definitely a useful pattern, although I wonder how useful an addition it would be if the React team intends to implement an official version in the near future -- or so they say 😄

Comment on lines +90 to +91
disableTriggers,
disabledActions,
Copy link
Member

Choose a reason for hiding this comment

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

to understand it correctly, we offer disableTriggers + disableActions just for alignment, but don't set custom values ... I'm interested, what's the user case to set them?

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 change was more in anticipation of future needs from other consumers. The main use case would be to disable adding/removing filters from the legend, disable time range scrubbing, etc. for cases where filters or the time range might not be modifiable. These actions also integrate with the search service by default which might not be used in some situations.

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.

Code LGMT, nice cleanups under the hood! Tested a-la-carte and didn't manage to break it.
Now this PR is also linked on the react repo page
Bildschirmfoto 2023-01-13 um 16 09 33
Since I guess you're famous now, I'm looking for this meet in greet near Disneyworld even more!

@kertal
Copy link
Member

kertal commented Jan 16, 2023

@elasticmachine merge upstream

@jughosta
Copy link
Contributor

When testing noticed that after switching data views, the time selection becomes weird (both via chart and via the time picker):

Jan-16-2023 11-13-29

@davismcphee
Copy link
Contributor Author

davismcphee commented Jan 18, 2023

@jughosta Great catch! That was a really tricky one -- since use_query_subscriber depends on the session.state$ observable to update the time range, searchSessionManager.getNextSearchSessionId() must be called before the histogram is refetched in order for the time range to get updated. But changing the data view causes the fetch$ observable subscription to resubscribe in use_discover_histogram, which changes the execution order between it and the fetch$ subscription in use_saved_search (which used to call searchSessionManager.getNextSearchSessionId()), resulting in the time range being outdated. 🤯

I added a functional for this one now so hopefully we don't run into a similar issue in the future. Commit here: 27b8f47.

@davismcphee davismcphee force-pushed the unified-histogram-manual-fetch branch from 19cc297 to 27b8f47 Compare January 18, 2023 04:24
@kibana-ci
Copy link

💚 Build Succeeded

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
unifiedHistogram 15 16 +1

Async chunks

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

id before after diff
discover 395.9KB 396.8KB +928.0B
unifiedHistogram 33.8KB 33.5KB -309.0B
total +619.0B

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
unifiedHistogram 0 1 +1

Page load bundle

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

id before after diff
unifiedHistogram 4.7KB 4.6KB -56.0B
Unknown metric groups

API count

id before after diff
unifiedHistogram 52 63 +11

ESLint disabled line counts

id before after diff
discover 40 39 -1
unifiedHistogram 2 1 -1
total -2

Total ESLint disabled count

id before after diff
discover 41 40 -1
unifiedHistogram 2 1 -1
total -2

History

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

cc @davismcphee

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.

Thanks! LGTM 👍

@davismcphee davismcphee merged commit 96d6b89 into elastic:main Jan 18, 2023
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Jan 18, 2023
@davismcphee davismcphee deleted the unified-histogram-manual-fetch branch January 18, 2023 13:56
wayneseymour pushed a commit to wayneseymour/kibana that referenced this pull request Jan 19, 2023
…lastic#146352)

## Summary

This PR includes a number of updates to Unified Histogram to prepare for
sharing with solutions, as well as updating its usage in Discover:

Unified Histogram:
- Adds a `disableAutoFetching` prop, similar to Unified Field List, to
disable automatic Unified Histogram refetching based on prop changes.
- Accepts an `input$` observable prop that can be used to control manual
refetches.
- Removes `refetchId` used internally and replaces it with an
observables based approach to simplify refetch logic.
- Introduces a `use_stable_callback` utility hook to create callback
functions with stable identities which simplifies `useCallback` logic —
should be replaced with `useEvent` or whatever the React team comes up
with to solve this specific issue when available:
reactjs/rfcs#220.
- Eliminates debouncing logic in Unified Histogram since it was hacky —
manual refetching should be used instead if debouncing is needed.
- Accepts `query`, `filters`, and `timeRange` props to remove
dependencies on specific services.
- Updates `use_request_params` to export `getTimeRange` and
`updateTimeRange` functions for easier absolute time range handling.
- Exposes some Lens embeddable props to allow further customizing
Unified Histogram behaviour.

Discover:
- Exports a `fetch$` observable from `use_saved_search` to allow
listening for when data fetches should be triggered.
- Uses new manual refetching support in Unified Histogram to simplify
refetching logic.
- Passes `query`, `filters`, and `timeRange` props to Unified Histogram.

### Checklist

- [ ] ~Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)~
- [ ]
~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials~
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] ~Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard
accessibility](https://webaim.org/techniques/keyboard/))~
- [ ] ~Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))~
- [ ] ~If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~
- [ ] ~This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))~
- [ ] ~This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)~

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting enhancement New value added to drive a business result Feature:Discover Discover Application Feature:UnifiedHistogram Issues related to the Unified Histogram plugin release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// v8.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants