Skip to content

Commit

Permalink
fix: add stateful query bar hook
Browse files Browse the repository at this point in the history
  • Loading branch information
logeekal committed Jul 12, 2023
1 parent 876843d commit 10aa878
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { useMemo } from 'react';
import { useKibana } from '../lib/kibana';

export const useGetStatefulQueryBar = () => {
const {
services: {
navigation: {
ui: { createTopNavWithCustomContext },
},
unifiedSearch,
customDataService,
},
} = useKibana();

const {
ui: { getCustomSearchBar },
} = unifiedSearch;

const CustomSearchBar = useMemo(
() =>
getCustomSearchBar({
data: customDataService,
}),
[customDataService, getCustomSearchBar]
);

const CustomStatefulTopNavKqlQueryBar = useMemo(() => {
const customUnifiedSearch = {
...unifiedSearch,
ui: {
...unifiedSearch.ui,
SearchBar: CustomSearchBar,
AggregateQuerySearchBar: CustomSearchBar,
},
};

return createTopNavWithCustomContext(customUnifiedSearch);
}, [CustomSearchBar, createTopNavWithCustomContext, unifiedSearch]);

return {
CustomStatefulTopNavKqlQueryBar,
};
};

0 comments on commit 10aa878

Please sign in to comment.