You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WIP to work on Discover's state management, it's scattered around the code base (saved search, appState, dataState via observables), cleaning, and centralizing stuff, not intended to be merged for now. This PR would be an intermediate step to clean up the current way centralized state is being handled. Its focus is to get a clearer structure, better separation from UI, removing of hook dependencies making it hard to debug the code. So refactoring without regressions, which makes it easier to further migrate to e.g. redux-toolkit
Parts of this PR
Extending discover_state.ts, which was originally just used to access and sync appState with the URL. the new extended DiscoverStateContainer consists of 4 main parts (appState, savedSearch, dataState, internalState)
Remove the useSavedSearch hook with it's endless hook dependencies
Consolidation of the usage of searchSource and savedSearch. Despite searchSource being part of savedSearch, we were using those variables in parallel. Now savedSearch is part of DiscoverStateContainer, and this is used to get searchSource when needed
Before this PR the state container was initialized twice, now there's just a single instance
SearchSource is not used as intended. Now there's a parent searchSource, that's also persisted in the savedSearch saved object, and for fetching the document, histogram, the number of hits, volatile search sources children are created and additional parameters are applied.
It adds a logger (addLog) function, that can be enabled using the browser's console, making it easier to debug state changes ... also for other use cases of course. By entering window?.ELASTIC_DISCOVER_LOGGER=true in the browser's console, logging messages are displayed in the console like this: This was very useful to debug, it was also helpful to add it in the root plugin of Discover for functional testing.
There's now an "Unsaved changes" badge displayed, like in Dashboard when changes are applied to a new or persisted saved search.
DiscoverStateContainer
exportinterfaceDiscoverStateContainer{/** * App state, the _a part of the URL - This is btw a redux like state */appStateContainer: ReduxLikeStateContainer<AppState>;/** * New, to access savedSearch related functionality (also for searchSource) **/savedSearchContainer/** * New, data fetching related state migrated from `use_saved_search.ts` **/dataStateContainer/** * Internal state that's used at several places in the UI */internalState: InternalStateContainer;
...
somemorestufffromtheoldcontainer
...
/** * functionality triggered from UI **/actions: {resetSavedSearch: (id: string)=>void;onOpenSavedSearch: (newSavedSearchId: string)=>void;onUpdateQuery: (payload: {dateRange: TimeRange;query?: Query|AggregateQuery},isUpdate?: boolean)=>void;updateSavedQueryId: (newSavedQueryId: string|undefined)=>void;/** * Pause the auto refresh interval without pushing an entry to history */pauseAutoRefreshInterval: ()=>Promise<void>;fetch: (reset?: boolean)=>void;}/** * And even more functions **/}
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.
Feature:DiscoverDiscover ApplicationTeam:DataDiscoveryDiscover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL.WIPWork in progress
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WIP to work on Discover's state management, it's scattered around the code base (saved search, appState, dataState via observables), cleaning, and centralizing stuff, not intended to be merged for now. This PR would be an intermediate step to clean up the current way centralized state is being handled. Its focus is to get a clearer structure, better separation from UI, removing of hook dependencies making it hard to debug the code. So refactoring without regressions, which makes it easier to further migrate to e.g.
redux-toolkit
Parts of this PR
discover_state.ts
, which was originally just used to access and sync appState with the URL. the new extendedDiscoverStateContainer
consists of 4 main parts (appState, savedSearch, dataState, internalState)useSavedSearch
hook with it's endless hook dependenciessearchSource
andsavedSearch
. DespitesearchSource
being part ofsavedSearch
, we were using those variables in parallel. Now savedSearch is part ofDiscoverStateContainer
, and this is used to getsearchSource
when neededaddLog
) function, that can be enabled using the browser's console, making it easier to debug state changes ... also for other use cases of course. By enteringwindow?.ELASTIC_DISCOVER_LOGGER=true
in the browser's console, logging messages are displayed in the console like this:This was very useful to debug, it was also helpful to add it in the root plugin of Discover for functional testing.
DiscoverStateContainer
Checklist
For maintainers