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

Fix template queries loading and update getSampleQuery interface #8848

Merged
merged 6 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions changelogs/fragments/8848.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix template queries loading and update getSampleQuery interface ([#8848](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8848))
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ export interface DatasetTypeConfig {
/**
* Returns a list of sample queries for this dataset type
*/
getSampleQueries?: (dataset: Dataset, language: string) => any;
getSampleQueries?: (dataset?: Dataset, language?: string) => Promise<any> | any;
jowg-amazon marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 3 additions & 1 deletion src/plugins/data/public/ui/filter_bar/filter_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
import { FilterEditor } from './filter_editor';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { SavedQueryManagementComponent } from '../saved_query_management';
import { SavedQuery, SavedQueryService } from '../../query';
import { QueryStringManager, SavedQuery, SavedQueryService } from '../../query';
import { SavedQueryMeta } from '../saved_query_form';
import { getUseNewSavedQueriesUI } from '../../services';

Expand All @@ -79,6 +79,7 @@ interface Props {
useSaveQueryMenu: boolean;
isQueryEditorControl: boolean;
saveQuery: (savedQueryMeta: SavedQueryMeta, saveAsNew?: boolean) => Promise<void>;
queryStringManager: QueryStringManager;
}
const maxFilterWidth = 600;

Expand Down Expand Up @@ -310,6 +311,7 @@ const FilterOptionsUI = (props: Props) => {
key={'savedQueryManagement'}
useNewSavedQueryUI={getUseNewSavedQueriesUI()}
saveQuery={props.saveQuery}
queryStringManager={props.queryStringManager}
/>,
]}
data-test-subj="save-query-panel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
EuiFlyoutBody,
EuiFlyoutFooter,
EuiFlyoutHeader,
EuiLoadingSpinner,
EuiSearchBar,
EuiSearchBarProps,
EuiSpacer,
Expand All @@ -23,14 +24,16 @@
} from '@elastic/eui';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { i18n } from '@osd/i18n';
import { SavedQuery, SavedQueryService } from '../../query';
import { QueryStringManager, SavedQuery, SavedQueryService } from '../../query';
import { SavedQueryCard } from './saved_query_card';
import { Query } from '../../../common';

export interface OpenSavedQueryFlyoutProps {
savedQueryService: SavedQueryService;
onClose: () => void;
onQueryOpen: (query: SavedQuery) => void;
handleQueryDelete: (query: SavedQuery) => Promise<void>;
queryStringManager: QueryStringManager;
}

interface SavedQuerySearchableItem {
Expand All @@ -47,6 +50,7 @@
onClose,
onQueryOpen,
handleQueryDelete,
queryStringManager,
}: OpenSavedQueryFlyoutProps) {
const [selectedTabId, setSelectedTabId] = useState<string>('mutable-saved-queries');
const [savedQueries, setSavedQueries] = useState<SavedQuery[]>([]);
Expand All @@ -59,18 +63,32 @@
const [languageFilterOptions, setLanguageFilterOptions] = useState<string[]>([]);
const [selectedQuery, setSelectedQuery] = useState<SavedQuery | undefined>(undefined);
const [searchQuery, setSearchQuery] = useState(EuiSearchBar.Query.MATCH_ALL);
const [isLoading, setIsLoading] = useState(false);
const currentTabIdRef = useRef(selectedTabId);

Check warning on line 67 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L66-L67

Added lines #L66 - L67 were not covered by tests
jowg-amazon marked this conversation as resolved.
Show resolved Hide resolved

const fetchAllSavedQueriesForSelectedTab = useCallback(async () => {
const allQueries = await savedQueryService.getAllSavedQueries();
const templateQueriesPresent = allQueries.some((q) => q.attributes.isTemplate);
const queriesForSelectedTab = allQueries.filter(
(q) =>
(selectedTabId === 'mutable-saved-queries' && !q.attributes.isTemplate) ||
(selectedTabId === 'template-saved-queries' && q.attributes.isTemplate)
);
setSavedQueries(queriesForSelectedTab);
setHasTemplateQueries(templateQueriesPresent);
}, [savedQueryService, selectedTabId, setSavedQueries]);
setIsLoading(true);

Check warning on line 70 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L70

Added line #L70 was not covered by tests
if (queryStringManager.getQuery()?.dataset?.type === 'SECURITY_LAKE') {
jowg-amazon marked this conversation as resolved.
Show resolved Hide resolved
setHasTemplateQueries(true);

Check warning on line 72 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L72

Added line #L72 was not covered by tests
}
if (currentTabIdRef.current === 'mutable-saved-queries') {
Copy link
Member

@kavilla kavilla Nov 13, 2024

Choose a reason for hiding this comment

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

apologies i believe i missed the original design PR for template queries.

Key Issues with Current Approach:

  • Saved Query Purpose Change
    • Historically, saved queries stored exactly what users typed
    • Used for cross-application consistency
    • one major use case: Create query in Discover, apply same query in Dashboards against many saved searches and visualizations
  • Cross-Plugin Impact
    • Potential unexpected behavior in Dashboards when using templated queries
    • Need to verify behavior after dataset type selection
    • Other plugins may not be aware of template functionality
  • Suggested Alternative Structure
    • Make saved queries and saved query templates separate entities
    • Create new saved object type: "saved query template"
    • Keep existing saved query behavior intact
    • Share UI components between both types

This maintains backwards compatibility while cleanly separating template functionality from core saved query behavior.

that said might be a little too late. but have we verified existing saved query impact? as of today with this new ui toggled on? do we need to add a saved object migration for saved queries? could we verify the impact to other plugins for example the dashboards plugin?

const allQueries = await savedQueryService.getAllSavedQueries();
const mutableSavedQueries = allQueries.filter((q) => !q.attributes.isTemplate);

Check warning on line 76 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L75-L76

Added lines #L75 - L76 were not covered by tests
if (currentTabIdRef.current === 'mutable-saved-queries') {
setSavedQueries(mutableSavedQueries);

Check warning on line 78 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L78

Added line #L78 was not covered by tests
}
} else if (currentTabIdRef.current === 'template-saved-queries') {
Comment on lines +88 to +94
Copy link
Member

Choose a reason for hiding this comment

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

nit: Can we use enums or constants for the tabs and not raw strings?

const query = queryStringManager.getQuery();

Check warning on line 81 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L81

Added line #L81 was not covered by tests
if (query?.dataset?.type) {
const templateQueries = await queryStringManager

Check warning on line 83 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L83

Added line #L83 was not covered by tests
.getDatasetService()
?.getType(query.dataset.type)
?.getSampleQueries?.();
if (Array.isArray(templateQueries)) setSavedQueries(templateQueries);
}
}
setIsLoading(false);

Check warning on line 90 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L90

Added line #L90 was not covered by tests
}, [savedQueryService, currentTabIdRef, setSavedQueries, queryStringManager]);

const updatePageIndex = useCallback((index: number) => {
pager.current.goToPageIndex(index);
Expand Down Expand Up @@ -179,7 +197,13 @@
onChange={onChange}
/>
<EuiSpacer />
{queriesOnCurrentPage.length > 0 ? (
{isLoading ? (
<EuiFlexGroup justifyContent="center" alignItems="center" style={{ height: '200px' }}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: why are we hardcoding height here?

Copy link
Member

Choose a reason for hiding this comment

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

+1

<EuiFlexItem grow={false}>
<EuiLoadingSpinner size="xl" />
</EuiFlexItem>
</EuiFlexGroup>
) : queriesOnCurrentPage.length > 0 ? (
queriesOnCurrentPage.map((query) => (
<SavedQueryCard
key={query.id}
Expand All @@ -205,7 +229,7 @@
/>
)}
<EuiSpacer />
{queriesOnCurrentPage.length > 0 && (
{!isLoading && queriesOnCurrentPage.length > 0 && (
<EuiTablePagination
itemsPerPageOptions={[5, 10, 20]}
itemsPerPage={itemsPerPage}
Expand Down Expand Up @@ -252,6 +276,7 @@
initialSelectedTab={tabs[0]}
onTabClick={(tab) => {
setSelectedTabId(tab.id);
currentTabIdRef.current = tab.id;

Check warning on line 279 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L279

Added line #L279 was not covered by tests
}}
/>
</EuiFlyoutBody>
Expand All @@ -268,7 +293,19 @@
fill
onClick={() => {
if (selectedQuery) {
onQueryOpen(selectedQuery);
if (
// Template queries are not associated with data sources. Apply data source from current query
selectedQuery.attributes.isTemplate
) {
const updatedQuery: Query = {

Check warning on line 300 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L300

Added line #L300 was not covered by tests
...queryStringManager?.getQuery(),
query: selectedQuery.attributes.query.query,
language: selectedQuery.attributes.query.language,
};
queryStringManager.setQuery(updatedQuery);

Check warning on line 305 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L305

Added line #L305 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious, why does this use setQuery over onQueryOpen?

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to this line (link), we wanted to preserve the data source info in the URL state when the saved query isn't associated with a data source. onQueryOpen clears the selected data source.

Copy link
Member

Choose a reason for hiding this comment

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

This is the line that concerns me a little and want to know more about why we need this. What are we trying to do here?

There are 2 states at play here. Query manager state and the local searchbar state. onQueryOpen updates the search bar state and not the query state because the act of opening a saved query today does not update the query state until the user has decided to fire the query (similar to how you dont want typing the query to update query state until you are ready to fire the query)

Updating the query manager state here for templates changes this behaviour for users when it comes to templates, because now it means that template queries DO change the query state even if the user has not been given the opportunity to confirm that thats the query that they want to run.

This change will not affect datasources that dont run the query by default, but for indices and index patterns, this means that opening a saved query template runs the query automatically while non templates do not.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ashwin-pc That's good to know. Given that context, it sounds like the way forward would involve retrieving the dataset from the query state when the saved query doesn't have a dataset (i.e., when the saved query is a template, or when the saved query is not associated with a dataset), and applying it to the saved query before calling onQueryOpen. Does that sound appropriate?
E.g.,

onClick={() => {
                if (selectedQuery) {
                  if (
                    // Template queries are not associated with data sources. Apply data source from current query
                    selectedQuery.attributes.isTemplate ||
                    // Associating a saved query with a data source is optional. If no data source is present, apply the current source.
                    !selectedQuery.attributes.query.dataset?.dataSource
                  ) {
                    selectedQuery.attributes.query.dataset = queryStringManager?.getQuery().dataset;
                  }
                  onQueryOpen(selectedQuery);
                  onClose();
                }
              }}

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this PR has been merged, I'll adjust this in a follow-up PR.

} else {
onQueryOpen(selectedQuery);

Check warning on line 307 in src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx#L307

Added line #L307 was not covered by tests
}
onClose();
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
import { i18n } from '@osd/i18n';
import React, { useCallback, useEffect, useState, Fragment, useRef } from 'react';
import { sortBy } from 'lodash';
import { SavedQuery, SavedQueryService } from '../..';
import { QueryStringManager, SavedQuery, SavedQueryService } from '../..';
import { SavedQueryListItem } from './saved_query_list_item';
import {
toMountPoint,
Expand All @@ -70,6 +70,7 @@ interface Props {
onClearSavedQuery: () => void;
closeMenuPopover: () => void;
saveQuery: (savedQueryMeta: SavedQueryMeta, saveAsNew?: boolean) => Promise<void>;
queryStringManager: QueryStringManager;
}

export function SavedQueryManagementComponent({
Expand All @@ -83,6 +84,7 @@ export function SavedQueryManagementComponent({
closeMenuPopover,
useNewSavedQueryUI,
saveQuery,
queryStringManager,
}: Props) {
const [savedQueries, setSavedQueries] = useState([] as SavedQuery[]);
const [count, setTotalCount] = useState(0);
Expand Down Expand Up @@ -256,6 +258,7 @@ export function SavedQueryManagementComponent({
onClose={() => openSavedQueryFlyout?.close().then()}
onQueryOpen={onLoad}
handleQueryDelete={handleDelete}
queryStringManager={queryStringManager}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Instead of prop drilling queryStringManager throughout, savedQueryService should ideally have been responsible for templates too.

/>
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
isRefreshPaused={refreshInterval.pause}
filters={filters}
query={query}
queryStringManager={data.query.queryString}
onFiltersUpdated={defaultFiltersUpdated(data.query)}
onRefreshChange={defaultOnRefreshChange(data.query)}
savedQuery={savedQuery}
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/data/public/ui/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ import {
withOpenSearchDashboards,
} from '../../../../opensearch_dashboards_react/public';
import { Filter, IIndexPattern, Query, TimeRange, UI_SETTINGS } from '../../../common';
import { SavedQuery, SavedQueryAttributes, TimeHistoryContract, QueryStatus } from '../../query';
import {
SavedQuery,
SavedQueryAttributes,
TimeHistoryContract,
QueryStatus,
QueryStringManager,
} from '../../query';
import { IDataPluginServices } from '../../types';
import { FilterBar } from '../filter_bar/filter_bar';
import { QueryEditorTopRow } from '../query_editor';
Expand Down Expand Up @@ -95,6 +101,7 @@ export interface SearchBarOwnProps {
onRefresh?: (payload: { dateRange: TimeRange }) => void;
indicateNoData?: boolean;
queryStatus?: QueryStatus;
queryStringManager: QueryStringManager;
}

export type SearchBarProps = SearchBarOwnProps & SearchBarInjectedDeps;
Expand Down Expand Up @@ -467,6 +474,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
useSaveQueryMenu={useSaveQueryMenu}
isQueryEditorControl={isQueryEditorControl}
saveQuery={this.onSave}
queryStringManager={this.props.queryStringManager}
Copy link
Member

Choose a reason for hiding this comment

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

the query string manager being pass in which will impact the state of the components in search bar which is also utilized by other plugins besides the Discover plugin (like dashboards and visualizations) so i would watch out and generally avoid touching this file.

this already was able to access the query string manager like this:

https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/plugins/data/public/ui/search_bar/search_bar.tsx#L123

this should be available in similar locations within this ui

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for calling that out. I'll revert line 205 in create_search_bar.tsx.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this PR has been merged, I'll adjust this in a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed in #8864

/>
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
// }

const [savedQueries, setSavedQueries] = useState<SavedQuery[]>([]);
const [sampleQueries, setSampleQueries] = useState<any>([]);

Check warning on line 177 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L177

Added line #L177 was not covered by tests
jowg-amazon marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
const fetchSavedQueries = async () => {
Expand All @@ -186,6 +187,39 @@
fetchSavedQueries();
}, [setSavedQueries, query, savedQuery]);

useEffect(() => {

Check warning on line 190 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L190

Added line #L190 was not covered by tests
// Samples for the language
const newSampleQueries: any = [];

Check warning on line 192 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L192

Added line #L192 was not covered by tests
if (query?.language) {
const languageSampleQueries = queryString.getLanguageService()?.getLanguage(query.language)

Check warning on line 194 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L194

Added line #L194 was not covered by tests
?.sampleQueries;
if (Array.isArray(languageSampleQueries)) {
newSampleQueries.push(...languageSampleQueries);

Check warning on line 197 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L197

Added line #L197 was not covered by tests
}
}

// Samples for the dataset type
if (query?.dataset?.type) {
const datasetType = queryString.getDatasetService()?.getType(query.dataset.type);

Check warning on line 203 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L203

Added line #L203 was not covered by tests
if (datasetType?.getSampleQueries) {
const sampleQueriesResponse = datasetType.getSampleQueries(query.dataset, query.language);

Check warning on line 205 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L205

Added line #L205 was not covered by tests
if (Array.isArray(sampleQueriesResponse)) {
setSampleQueries([...sampleQueriesResponse, ...newSampleQueries]);

Check warning on line 207 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L207

Added line #L207 was not covered by tests
Comment on lines +206 to +207
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit, could create a helper function for setting sample queries that gets used in both places to prevent divergence

Copy link
Member

Choose a reason for hiding this comment

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

+1 having the savedQueryService take care of this would be ideal. Sample queries and templates are an extension of that

} else if (sampleQueriesResponse instanceof Promise) {
sampleQueriesResponse

Check warning on line 209 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L209

Added line #L209 was not covered by tests
.then((datasetSampleQueries: any) => {
if (Array.isArray(datasetSampleQueries)) {
setSampleQueries([...datasetSampleQueries, ...newSampleQueries]);

Check warning on line 212 in src/plugins/discover/public/application/components/no_results/no_results.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/components/no_results/no_results.tsx#L212

Added line #L212 was not covered by tests
}
})
.catch((error: any) => {
// noop
Copy link
Member

Choose a reason for hiding this comment

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

Lets atleast log this?

});
}
}
}
}, [queryString, query]);

const tabs = useMemo(() => {
const buildSampleQueryBlock = (sampleTitle: string, sampleQuery: string) => {
return (
Expand All @@ -197,25 +231,6 @@
</>
);
};

const sampleQueries = [];

// Samples for the dataset type
if (query?.dataset?.type) {
const datasetSampleQueries = queryString
.getDatasetService()
?.getType(query.dataset.type)
?.getSampleQueries?.(query.dataset, query.language);
if (Array.isArray(datasetSampleQueries)) sampleQueries.push(...datasetSampleQueries);
}

// Samples for the language
if (query?.language) {
const languageSampleQueries = queryString.getLanguageService()?.getLanguage(query.language)
?.sampleQueries;
if (Array.isArray(languageSampleQueries)) sampleQueries.push(...languageSampleQueries);
}

return [
...(sampleQueries.length > 0
? [
Expand All @@ -229,7 +244,7 @@
<EuiSpacer size="s" />
{sampleQueries
.slice(0, 5)
.map((sampleQuery) =>
.map((sampleQuery: any) =>
jowg-amazon marked this conversation as resolved.
Show resolved Hide resolved
buildSampleQueryBlock(sampleQuery.title, sampleQuery.query)
)}
</EuiPanel>
Expand All @@ -256,7 +271,7 @@
]
: []),
];
}, [queryString, query, savedQueries]);
}, [savedQueries, sampleQueries]);

return (
<I18nProvider>
Expand Down
Loading