-
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] Add container for data state (migrated from useSavedSearch hook) #148614
Conversation
@elasticmachine merge upstream |
* Skip initial fetch when discover:searchOnPageLoad is disabled. | ||
*/ | ||
if (initialFetchStatus === FetchStatus.UNINITIALIZED) { | ||
fetch$ = fetch$.pipe(skip(1)); | ||
} |
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.
Removed and made more implicit, not to skip a fetch in the given condition, but to fetch when it's needed and not to initially fetch when discover:searchOnPageLoad is disabled
? columns.map((field) => ({ field, include_unmapped: 'true' })) | ||
: [{ field: '*', include_unmapped: 'true' }]; |
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.
Without this change, the CSV export broke.
Why? [{ field: '*', include_unmapped: 'true' }]
is necessary to export all the fields given useFieldsApi is true
(Which is the default)
Bevor the refactoring of this PR this was added by the code executed in the hook. So it was added before , and at a different part of the code, which made it hard to track & debug
This is now slightly better, more decoupled, independent from previous searchSource mutations
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
@elasticmachine merge upstream |
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.
A few minor requests and a couple of items to discuss before I give this my 👍
src/plugins/discover/public/application/main/components/field_stats_table/field_stats_table.tsx
Show resolved
Hide resolved
src/plugins/discover/public/application/main/services/discover_data_state_container.test.ts
Show resolved
Hide resolved
/** | ||
* Observable triggering fetching data from ES | ||
*/ | ||
refetch$: DataRefetch$; |
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.
Why is a Subject
being used? Is something happening that couldn't be expressed in terms of a function?
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.
We have several observables that can trigger a fetch, and this is one of them:
kibana/src/plugins/discover/public/application/main/utils/get_fetch_observable.ts
Line 40 in 2202d1d
refetch$, |
don't think we can change this so easily, but there's already a fetch
function exported that's using the observable internally:
kibana/src/plugins/discover/public/application/main/services/discover_data_state_container.ts
Line 89 in 08325ee
fetch: () => void; |
I think just this function could be used in the UI. so the Subject would be a internal implementation detail
/** | ||
* Start subscribing to other observables that trigger data fetches | ||
*/ | ||
subscribe: () => () => void; |
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.
Why is this called externally? Is there a reason to instantiate this object without subscribing?
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.
yes, we currently initialize the discover state container twice, also legacy behavior I'll change in a follow up, it was part of the POC:
first:
const { appState } = getDiscoverStateContainer({ |
second:
kibana/src/plugins/discover/public/application/main/hooks/use_discover_state.ts
Lines 50 to 54 in 2b3a5d2
const stateContainer = useMemo(() => { | |
const container = getDiscoverStateContainer({ | |
history, | |
savedSearch, | |
services, |
furthermore it makes sense, since we are subscribing to more store / services / container to orchestrate subscribing.
src/plugins/discover/public/application/main/services/discover_data_state_container.ts
Outdated
Show resolved
Hide resolved
/** | ||
* Observable emitting when a next fetch is triggered | ||
*/ | ||
fetch$: DataFetch$; |
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.
Its difficult to tell the difference between fetch$
and refetch$
based on name, type, and description. As best I can tell refetch$
is called by external consumers but not fetch$
, and external consumers might subscribe to fetch$
but probably not refetch$
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 agree, fetch$ was just recently exposed for the histogram, so not exposing refetch$ (but just a fetch
function which is more implicit) might make this clearer
update: can't do this, because we need refetch$ here:
Line 147 in 2b3a5d2
const refetch = stateContainer?.dataState.refetch$.subscribe(() => { |
So I think improving the description would be the way to go ... or naming
refetch$
-> startFetch$
, triggerFetch$
open for suggestions 🙇
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.
Changes look good to me and work well.
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @kertal |
Summary
This PR migrates the hook responsible for data fetching in Discover main (
use_saved_search.ts
) to be part ofDiscoverStateContainer
asDataStateContainer
.Testing
There shall be no regression, everything should work like before
Reviewing
The majority of files were changed because import paths changed. Sadly GitHub doesn't diff the main change:
The logic of
kibana/src/plugins/discover/public/application/main/hooks/use_saved_search.ts
Line 95 in 08d8555
was migrated to
kibana/src/plugins/discover/public/application/main/services/discover_data_state_container.ts
Line 118 in 2202d1d
This is part of #142131 and code was extracted of the POC #140765. There will be follow up cleanups once the next part of the POC are migrated.
Checklist