Skip to content

Commit

Permalink
[Discover-next] Support data sources for query assist (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#6972)

* disable query assist for non-default datasource

Signed-off-by: Joshua Li <joshuali925@gmail.com>

* disable query assist input when loading

Signed-off-by: Joshua Li <joshuali925@gmail.com>

* support MDS for query assist

Signed-off-by: Joshua Li <joshuali925@gmail.com>

* add unit tests for agents

Signed-off-by: Joshua Li <joshuali925@gmail.com>

* Revert "add unit tests for agents"

This reverts commit 983514e.
The test configs are not yet setup in query_enhancements plugins.

Signed-off-by: Joshua Li <joshuali925@gmail.com>

---------

Signed-off-by: Joshua Li <joshuali925@gmail.com>
(cherry picked from commit 328e08e)
  • Loading branch information
joshuali925 committed Jun 14, 2024
1 parent 08a81e0 commit 5b2ad95
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
if (!shouldRenderSearchBarExtensions() || !queryEditorHeaderRef.current) return;
return (
<SearchBarExtensions
configs={props.queryEnhancements?.get(queryLanguage!)?.searchBar?.extensions}
configs={queryUiEnhancement?.extensions}
portalContainer={queryEditorHeaderRef.current}
indexPatterns={props.indexPatterns}
dataSource={props.dataSource}
/>
);
}
Expand Down Expand Up @@ -293,9 +294,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
}

function shouldRenderSearchBarExtensions(): boolean {
return Boolean(
queryLanguage && props.queryEnhancements?.get(queryLanguage)?.searchBar?.extensions?.length
);
return Boolean(queryUiEnhancement?.extensions?.length);
}

function renderUpdateButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export function createSearchBar({
showSaveQuery={props.showSaveQuery}
screenTitle={props.screenTitle}
indexPatterns={props.indexPatterns}
dataSource={props.dataSource}
indicateNoData={props.indicateNoData}
timeHistory={data.query.timefilter.history}
dateRangeFrom={timeRange.from}
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/data/public/ui/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import classNames from 'classnames';
import { compact, get, isEqual } from 'lodash';
import React, { Component } from 'react';
import ResizeObserver from 'resize-observer-polyfill';
import { DataSource } from '../..';
import {
OpenSearchDashboardsReactContextValue,
withOpenSearchDashboards,
Expand All @@ -59,6 +60,7 @@ interface SearchBarInjectedDeps {

export interface SearchBarOwnProps {
indexPatterns?: IIndexPattern[];
dataSource?: DataSource;
isLoading?: boolean;
customSubmitButton?: React.ReactNode;
screenTitle?: string;
Expand Down Expand Up @@ -494,6 +496,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
screenTitle={this.props.screenTitle}
onSubmit={this.onQueryBarSubmit}
indexPatterns={this.props.indexPatterns}
dataSource={this.props.dataSource}
isLoading={this.props.isLoading}
prepend={this.props.showFilterBar ? savedQueryManagement : undefined}
showDatePicker={this.props.showDatePicker}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EuiErrorBoundary } from '@elastic/eui';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import ReactDOM from 'react-dom';
import { IIndexPattern } from '../../../common';
import { DataSource } from '../../data_sources/datasource';

interface SearchBarExtensionProps {
config: SearchBarExtensionConfig;
Expand All @@ -19,6 +20,10 @@ export interface SearchBarExtensionDependencies {
* Currently selected index patterns.
*/
indexPatterns?: Array<IIndexPattern | string>;
/**
* Currently selected data source.
*/
dataSource?: DataSource;
}

export interface SearchBarExtensionConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getTopNavLinks } from '../../components/top_nav/get_top_nav_links';
import { useDiscoverContext } from '../context';
import { getRootBreadcrumbs } from '../../helpers/breadcrumbs';
import { opensearchFilters, connectStorageToQueryState } from '../../../../../data/public';
import { useDataSource } from '../utils/use_datasource';

export interface TopNavProps {
opts: {
Expand All @@ -24,6 +25,7 @@ export interface TopNavProps {

export const TopNav = ({ opts }: TopNavProps) => {
const { services } = useOpenSearchDashboards<DiscoverViewServices>();
const dataSource = useDataSource(services);
const { inspectorAdapters, savedSearch, indexPattern } = useDiscoverContext();
const [indexPatterns, setIndexPatterns] = useState<IndexPattern[] | undefined>(undefined);

Expand Down Expand Up @@ -89,6 +91,7 @@ export const TopNav = ({ opts }: TopNavProps) => {
useDefaultBehaviors
setMenuMountPoint={opts.setHeaderActionMenu}
indexPatterns={indexPattern ? [indexPattern] : indexPatterns}
dataSource={dataSource}
onQuerySubmit={opts.onQuerySubmit}
/>
);
Expand Down

0 comments on commit 5b2ad95

Please sign in to comment.