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

[Hotfix] Clear saved query crashes kibana on Discover in some cases #63554

Merged
merged 3 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,9 @@ function discoverController(
if (newSavedQueryId) {
setAppState({ savedQuery: newSavedQueryId });
} else {
//reset filters and query string, remove savedQuery from state
// remove savedQueryId from state
const state = {
...appStateContainer.getState(),
Copy link
Contributor Author

@Dosant Dosant Apr 15, 2020

Choose a reason for hiding this comment

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

This what was causing a "loop". Since as a hot fix I just moved localStorage.get('kibana.userQueryLanguage') into search_bar logic, this additional logic is not needed anymore.
query and filters are anyway synced outside of this

If I'd leave this code as is - the loop still will be fixed just by other changes. See the commit: 12c9c56

query: getDefaultQuery(
localStorage.get('kibana.userQueryLanguage') || config.get('search:queryLanguage')
),
filters: [],
};
delete state.savedQuery;
appStateContainer.set(state);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/data/public/ui/search_bar/create_search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
const onQuerySubmitRef = useRef(props.onQuerySubmit);
const defaultQuery = {
query: '',
language: core.uiSettings.get('search:queryLanguage'),
language:
storage.get('kibana.userQueryLanguage') || core.uiSettings.get('search:queryLanguage'),
};
const [query, setQuery] = useState<Query>(props.query || defaultQuery);

Expand Down Expand Up @@ -161,7 +162,7 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
setQuery,
savedQueryId: props.savedQueryId,
notifications: core.notifications,
uiSettings: core.uiSettings,
defaultLanguage: defaultQuery.language,
});

// Fire onQuerySubmit on query or timerange change
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/public/ui/search_bar/lib/use_saved_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ interface UseSavedQueriesProps {
queryService: DataPublicPluginStart['query'];
setQuery: Function;
notifications: CoreStart['notifications'];
uiSettings: CoreStart['uiSettings'];
savedQueryId?: string;
defaultLanguage: string;
}

interface UseSavedQueriesReturn {
Expand All @@ -41,7 +41,7 @@ interface UseSavedQueriesReturn {

export const useSavedQuery = (props: UseSavedQueriesProps): UseSavedQueriesReturn => {
// Handle saved queries
const defaultLanguage = props.uiSettings.get('search:queryLanguage');
const defaultLanguage = props.defaultLanguage;
const [savedQuery, setSavedQuery] = useState<SavedQuery | undefined>();

// Effect is used to convert a saved query id into an object
Expand Down