From f424b16222d06fb9fb912c745c379015cad36dc7 Mon Sep 17 00:00:00 2001 From: abbyhu2000 Date: Mon, 19 Aug 2024 19:56:59 +0000 Subject: [PATCH] progress Signed-off-by: abbyhu2000 --- .../data/public/antlr/dql/code_completion.ts | 6 +- src/plugins/data/public/plugin.ts | 5 +- .../data/public/query/query_service.ts | 16 +++- .../language_manager/language_manager.ts} | 89 +++++++++---------- .../query_string/query_string_manager.ts | 12 ++- .../data/public/search/search_service.ts | 8 +- .../dataset_navigator/dataset_navigator.tsx | 9 +- .../ui/query_editor/language_selector.tsx | 15 ++-- .../ui/query_editor/no_data_popover.tsx | 4 +- .../public/ui/query_editor/query_editor.tsx | 11 ++- .../ui/query_editor/query_editor_top_row.tsx | 15 ++-- .../ui/search_bar/create_search_bar.tsx | 4 - .../data/public/ui/search_bar/search_bar.tsx | 24 ++--- src/plugins/data/public/ui/settings/index.ts | 6 -- src/plugins/data/public/ui/settings/mocks.ts | 18 ---- src/plugins/data/public/ui/types.ts | 7 -- src/plugins/data/public/ui/ui_service.ts | 31 +------ .../public/components/sidebar/index.tsx | 18 ++-- yarn.lock | 31 +------ 19 files changed, 132 insertions(+), 197 deletions(-) rename src/plugins/data/public/{ui/settings/settings.ts => query/query_string/language_manager/language_manager.ts} (75%) delete mode 100644 src/plugins/data/public/ui/settings/index.ts delete mode 100644 src/plugins/data/public/ui/settings/mocks.ts diff --git a/src/plugins/data/public/antlr/dql/code_completion.ts b/src/plugins/data/public/antlr/dql/code_completion.ts index 076fae33b9a2..3ed9373ed310 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.ts @@ -13,7 +13,7 @@ import { getTokenPosition } from '../shared/cursor'; import { IndexPattern, IndexPatternField } from '../../index_patterns'; import { QuerySuggestionGetFnArgs } from '../../autocomplete'; import { DQLParserVisitor } from './.generated/DQLParserVisitor'; -import { getUiService } from '../../services'; +import { getQueryService } from '../../services'; const findCursorIndex = ( tokenStream: TokenStream, @@ -132,7 +132,9 @@ export const getSuggestions = async ({ if ( !services || !services.appName || - !getUiService().Settings.supportsEnhancementsEnabled(services.appName) || + !getQueryService() + .queryString.getLanguageManager() + .supportsEnhancementsEnabled(services.appName) || !indexPattern ) { return []; diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 09bdd96d58e2..9f7cd0c2590e 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -119,7 +119,7 @@ export class DataPublicPlugin constructor(initializerContext: PluginInitializerContext) { this.searchService = new SearchService(initializerContext); this.uiService = new UiService(initializerContext); - this.queryService = new QueryService(); + this.queryService = new QueryService(initializerContext); this.fieldFormatsService = new FieldFormatsService(); this.autocomplete = new AutocompleteService(initializerContext); this.storage = createStorage({ engine: window.localStorage, prefix: 'opensearch_dashboards.' }); @@ -176,7 +176,8 @@ export class DataPublicPlugin query: queryService, __enhance: (enhancements: DataPublicPluginEnhancements) => { if (enhancements.search) searchService.__enhance(enhancements.search); - if (enhancements.ui) uiService.__enhance(enhancements.ui); + if (enhancements.ui) + queryService.queryString.getLanguageManager().__enhance(enhancements.ui); }, }; } diff --git a/src/plugins/data/public/query/query_service.ts b/src/plugins/data/public/query/query_service.ts index 17a7773567f3..845b55331074 100644 --- a/src/plugins/data/public/query/query_service.ts +++ b/src/plugins/data/public/query/query_service.ts @@ -29,7 +29,11 @@ */ import { share } from 'rxjs/operators'; -import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public'; +import { + IUiSettingsClient, + PluginInitializerContext, + SavedObjectsClientContract, +} from 'src/core/public'; import { FilterManager } from './filter_manager'; import { createAddToQueryLog } from './lib'; import { TimefilterService, TimefilterSetup } from './timefilter'; @@ -44,7 +48,9 @@ import { IndexPatternsService, } from '../../common'; import { getUiSettings } from '../services'; -import { IndexPattern } from '..'; +import { IndexPattern, ISearchStart } from '..'; +import { ConfigSchema } from '../../config'; +import { SearchService } from '../search/search_service'; /** * Query Service @@ -71,6 +77,8 @@ export class QueryService { state$!: ReturnType; + constructor(private initializerContext: PluginInitializerContext) {} + public setup({ storage, uiSettings }: QueryServiceSetupDependencies) { this.filterManager = new FilterManager(uiSettings); @@ -80,7 +88,9 @@ export class QueryService { storage, }); - this.queryStringManager = new QueryStringManager(storage, uiSettings); + const { enhancements: supportedAppNames } = this.initializerContext.config.get(); + + this.queryStringManager = new QueryStringManager(storage, uiSettings, supportedAppNames); this.dataSetManager = new DataSetManager(uiSettings); this.state$ = createQueryStateObservable({ diff --git a/src/plugins/data/public/ui/settings/settings.ts b/src/plugins/data/public/query/query_string/language_manager/language_manager.ts similarity index 75% rename from src/plugins/data/public/ui/settings/settings.ts rename to src/plugins/data/public/query/query_string/language_manager/language_manager.ts index 7fc758712ad2..1d7cf0671411 100644 --- a/src/plugins/data/public/ui/settings/settings.ts +++ b/src/plugins/data/public/query/query_string/language_manager/language_manager.ts @@ -4,11 +4,10 @@ */ import { BehaviorSubject } from 'rxjs'; -import { DataStorage, setOverrides as setFieldOverrides } from '../../../common'; -import { ConfigSchema } from '../../../config'; -import { ISearchStart } from '../../search'; -import { QueryEditorExtensionConfig } from '../query_editor/query_editor_extensions'; -import { QueryEnhancement } from '../types'; +import { QueryEnhancement, UiEnhancements } from '../../../ui/types'; +import { QueryEditorExtensionConfig } from '../../../ui'; +import { ConfigSchema } from '../../../../config'; +import { DataStorage, setOverrides as setFieldOverrides } from '../../../../common'; export interface DataSettings { userQueryLanguage: string; @@ -22,21 +21,45 @@ export interface DataSettings { }; } -export class Settings { +export class LanguageManager { private isEnabled = false; private enabledQueryEnhancementsUpdated$ = new BehaviorSubject(this.isEnabled); private enhancedAppNames: string[] = []; + private queryEnhancements: Map; + private queryEditorExtensionMap: Record; constructor( private readonly config: ConfigSchema['enhancements'], - private readonly search: ISearchStart, - private readonly storage: DataStorage, - private readonly queryEnhancements: Map, - private readonly queryEditorExtensionMap: Record + private readonly storage: DataStorage ) { this.isEnabled = true; this.setUserQueryEnhancementsEnabled(this.isEnabled); this.enhancedAppNames = this.isEnabled ? this.config.supportedAppNames : []; + this.queryEnhancements = new Map(); + this.queryEditorExtensionMap = {}; + } + + public __enhance = (enhancements: UiEnhancements) => { + if (!enhancements) return; + if (enhancements.query && enhancements.query.language) { + this.queryEnhancements.set(enhancements.query.language, enhancements.query); + } + if (enhancements.queryEditorExtension) { + this.queryEditorExtensionMap[enhancements.queryEditorExtension.id] = + enhancements.queryEditorExtension; + } + }; + + public getAllQueryEnhancements() { + return this.queryEnhancements; + } + + public getQueryEnhancements(language: string) { + return this.queryEnhancements.get(language); + } + + public getQueryEditorExtensionMap() { + return this.queryEditorExtensionMap; } supportsEnhancementsEnabled(appName: string) { @@ -58,18 +81,6 @@ export class Settings { return true; } - getAllQueryEnhancements() { - return this.queryEnhancements; - } - - getQueryEnhancements(language: string) { - return this.queryEnhancements.get(language); - } - - getQueryEditorExtensionMap() { - return this.queryEditorExtensionMap; - } - getUserQueryLanguageBlocklist() { return this.storage.get('userQueryLanguageBlocklist') || []; } @@ -87,16 +98,16 @@ export class Settings { } setUserQueryLanguage(language: string) { - if (language !== this.getUserQueryLanguage()) { - this.search.df.clear(); - } + // if (language !== this.getUserQueryLanguage()) { + // this.search.df.clear(); + // } this.storage.set('userQueryLanguage', language); const queryEnhancement = this.queryEnhancements.get(language); - this.search.__enhance({ - searchInterceptor: queryEnhancement - ? queryEnhancement.search - : this.search.getDefaultSearchInterceptor(), - }); + // this.search.__enhance({ + // searchInterceptor: queryEnhancement + // ? queryEnhancement.search + // : this.search.getDefaultSearchInterceptor(), + // }); this.setUiOverridesByUserQueryLanguage(language); return true; @@ -167,20 +178,4 @@ export class Settings { } } -interface Deps { - config: ConfigSchema['enhancements']; - search: ISearchStart; - storage: DataStorage; - queryEnhancements: Map; - queryEditorExtensionMap: Record; -} - -export function createSettings({ - config, - search, - storage, - queryEnhancements, - queryEditorExtensionMap, -}: Deps) { - return new Settings(config, search, storage, queryEnhancements, queryEditorExtensionMap); -} +export type LanguageContract = PublicMethodsOf; diff --git a/src/plugins/data/public/query/query_string/query_string_manager.ts b/src/plugins/data/public/query/query_string/query_string_manager.ts index 98a348b58254..c8d989e12440 100644 --- a/src/plugins/data/public/query/query_string/query_string_manager.ts +++ b/src/plugins/data/public/query/query_string/query_string_manager.ts @@ -33,17 +33,23 @@ import { skip } from 'rxjs/operators'; import { CoreStart } from 'opensearch-dashboards/public'; import { DataStorage, Query, SimpleDataSet, TimeRange, UI_SETTINGS } from '../../../common'; import { createHistory, QueryHistory } from './query_history'; +import { LanguageManager } from './language_manager/language_manager'; +import { ConfigSchema } from '../../../config'; +import { SearchService } from '../../search/search_service'; export class QueryStringManager { private query$: BehaviorSubject; private queryHistory: QueryHistory; + public languageManager: LanguageManager; constructor( private readonly storage: DataStorage, - private readonly uiSettings: CoreStart['uiSettings'] + private readonly uiSettings: CoreStart['uiSettings'], + private readonly supportedAppNames: ConfigSchema['enhancements'] ) { this.query$ = new BehaviorSubject(this.getDefaultQuery()); this.queryHistory = createHistory({ storage }); + this.languageManager = new LanguageManager(this.supportedAppNames, this.storage); } private getDefaultQueryString() { @@ -121,6 +127,10 @@ export class QueryStringManager { public changeQueryHistory(listener: (reqs: any[]) => void) { return this.queryHistory.change(listener); } + + public getLanguageManager() { + return this.languageManager; + } } export type QueryStringContract = PublicMethodsOf; diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 5516b4abc79d..ea2c985d8493 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -64,7 +64,7 @@ import { createDataFrameCache, dataFrameToSpec, } from '../../common/data_frames'; -import { getQueryService, getUiService } from '../services'; +import { getQueryService } from '../services'; import { UI_SETTINGS } from '../../common'; /** @internal */ @@ -135,10 +135,10 @@ export class SearchService implements Plugin { { fieldFormats, indexPatterns }: SearchServiceStartDependencies ): ISearchStart { const search = ((request, options) => { + const queryString = getQueryService().queryString; const selectedLanguage = getQueryService().queryString.getQuery().language; - const uiService = getUiService(); - const enhancement = uiService.Settings.getQueryEnhancements(selectedLanguage); - uiService.Settings.setUiOverridesByUserQueryLanguage(selectedLanguage); + const enhancement = queryString.getLanguageManager().getQueryEnhancements(selectedLanguage); + queryString.getLanguageManager().setUiOverridesByUserQueryLanguage(selectedLanguage); const isEnhancedEnabled = uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED); if (enhancement) { diff --git a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx index 4912abd92614..c8cbca9660fb 100644 --- a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx +++ b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx @@ -61,6 +61,7 @@ export const DataSetNavigator: React.FC = ({ }) => { const searchService = getSearchService(); const queryService = getQueryService(); + const languageManager = queryService.queryString.getLanguageManager(); const uiService = getUiService(); const indexPatternsService = getIndexPatterns(); const notifications = getNotifications(); @@ -107,14 +108,14 @@ export const DataSetNavigator: React.FC = ({ const selectedDataSet = ds ?? selectedDataSetState; if (!selectedDataSet || !selectedDataSet.id) return; - const language = uiService.Settings.getUserQueryLanguage(); - const queryEnhancements = uiService.Settings.getQueryEnhancements(language); + const language = languageManager.getUserQueryLanguage(); + const queryEnhancements = languageManager.getQueryEnhancements(language); const initialInput = queryEnhancements?.searchBar?.queryStringInput?.initialValue; const query = initialInput ? initialInput.replace('', selectedDataSet.title!) : ''; - uiService.Settings.setUserQueryString(query); + languageManager.setUserQueryString(query); queryService.queryString.setQuery({ query, language }); queryService.dataSetManager.setDataSet(selectedDataSet); @@ -143,7 +144,7 @@ export const DataSetNavigator: React.FC = ({ closePopover(); }, - [queryService, setSelectedDataSetState, selectedDataSetState, uiService.Settings] + [queryService, setSelectedDataSetState, selectedDataSetState, languageManager] ); useEffect(() => { diff --git a/src/plugins/data/public/ui/query_editor/language_selector.tsx b/src/plugins/data/public/ui/query_editor/language_selector.tsx index 455540d28df2..18a967c1f7c5 100644 --- a/src/plugins/data/public/ui/query_editor/language_selector.tsx +++ b/src/plugins/data/public/ui/query_editor/language_selector.tsx @@ -12,7 +12,7 @@ import { } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import React, { useState } from 'react'; -import { getUiService } from '../../services'; +import { getQueryService } from '../../services'; export interface QueryLanguageSelectorProps { language: string; @@ -53,17 +53,16 @@ export const QueryLanguageSelector = (props: QueryLanguageSelectorProps) => { }, ]; - const uiService = getUiService(); + const queryService = getQueryService(); + const languageManager = queryService.queryString.getLanguageManager(); - const queryEnhancements = uiService.Settings.getAllQueryEnhancements(); + const queryEnhancements = languageManager.getAllQueryEnhancements(); queryEnhancements.forEach((enhancement) => { if ( (enhancement.supportedAppNames && props.appName && !enhancement.supportedAppNames.includes(props.appName)) || - uiService.Settings.getUserQueryLanguageBlocklist().includes( - enhancement.language.toLowerCase() - ) + languageManager.getUserQueryLanguageBlocklist().includes(enhancement.language.toLowerCase()) ) return; languageOptions.unshift(mapExternalLanguageToOptions(enhancement.language)); @@ -78,10 +77,10 @@ export const QueryLanguageSelector = (props: QueryLanguageSelectorProps) => { const handleLanguageChange = (newLanguage: string) => { props.onSelectLanguage(newLanguage); - uiService.Settings.setUserQueryLanguage(newLanguage); + languageManager.setUserQueryLanguage(newLanguage); }; - uiService.Settings.setUserQueryLanguage(props.language); + languageManager.setUserQueryLanguage(props.language); const languageOptionsMenu = languageOptions .sort((a, b) => { diff --git a/src/plugins/data/public/ui/query_editor/no_data_popover.tsx b/src/plugins/data/public/ui/query_editor/no_data_popover.tsx index 49490e258bf5..fb8e30ad180b 100644 --- a/src/plugins/data/public/ui/query_editor/no_data_popover.tsx +++ b/src/plugins/data/public/ui/query_editor/no_data_popover.tsx @@ -6,8 +6,8 @@ import { ReactElement, useEffect, useState } from 'react'; import React from 'react'; import { EuiButtonEmpty, EuiText, EuiTourStep } from '@elastic/eui'; -import { IStorageWrapper } from 'src/plugins/opensearch_dashboards_utils/public'; import { i18n } from '@osd/i18n'; +import { DataStorage } from 'src/plugins/data/common'; const NO_DATA_POPOVER_STORAGE_KEY = 'data.noDataPopover'; @@ -17,7 +17,7 @@ export function NoDataPopover({ children, }: { showNoDataPopover?: boolean; - storage: IStorageWrapper; + storage: DataStorage; children: ReactElement; }) { const [noDataPopoverDismissed, setNoDataPopoverDismissed] = useState(() => diff --git a/src/plugins/data/public/ui/query_editor/query_editor.tsx b/src/plugins/data/public/ui/query_editor/query_editor.tsx index 2238abbc5b1b..b7f0430f8164 100644 --- a/src/plugins/data/public/ui/query_editor/query_editor.tsx +++ b/src/plugins/data/public/ui/query_editor/query_editor.tsx @@ -8,19 +8,18 @@ import classNames from 'classnames'; import { isEqual } from 'lodash'; import React, { Component, createRef, RefObject } from 'react'; import { monaco } from '@osd/monaco'; -import { Settings } from '..'; import { IDataPluginServices, IFieldType, IIndexPattern, Query, TimeRange } from '../..'; import { OpenSearchDashboardsReactContextValue } from '../../../../opensearch_dashboards_react/public'; import { QuerySuggestion } from '../../autocomplete'; import { fromUser, getQueryLog, PersistedLog, toUser } from '../../query'; import { SuggestionsListSize } from '../typeahead/suggestions_component'; -import { DataSettings } from '../types'; import { QueryLanguageSelector } from './language_selector'; import { QueryEditorExtensions } from './query_editor_extensions'; import { QueryEditorBtnCollapse } from './query_editor_btn_collapse'; import { SimpleDataSet } from '../../../common'; import { createDQLEditor, createDefaultEditor } from './editors'; import { getQueryService, getIndexPatterns } from '../../services'; +import { DataSettings } from '..'; const LANGUAGE_ID_SQL = 'SQL'; monaco.languages.register({ id: LANGUAGE_ID_SQL }); @@ -32,7 +31,6 @@ export interface QueryEditorProps { dataSet?: SimpleDataSet; query: Query; dataSetContainerRef?: React.RefCallback; - settings: Settings; disableAutoFocus?: boolean; screenTitle?: string; queryActions?: any; @@ -99,13 +97,14 @@ export default class QueryEditorUI extends Component { public inputRef: monaco.editor.IStandaloneCodeEditor | null = null; private queryService = getQueryService(); + private languageManager = this.queryService.queryString.getLanguageManager(); private persistedLog: PersistedLog | undefined; private abortController?: AbortController; private services = this.props.opensearchDashboards.services; private headerRef: RefObject = createRef(); private bannerRef: RefObject = createRef(); - private extensionMap = this.props.settings?.getQueryEditorExtensionMap(); + private extensionMap = this.languageManager.getQueryEditorExtensionMap(); private getQueryString = () => { if (!this.props.query.query) { @@ -198,14 +197,14 @@ export default class QueryEditorUI extends Component { language, }; - const enhancement = this.props.settings.getQueryEnhancements(newQuery.language); + const enhancement = this.languageManager.getQueryEnhancements(newQuery.language); const fields = enhancement?.fields; const newSettings: DataSettings = { userQueryLanguage: newQuery.language, userQueryString: newQuery.query, ...(fields && { uiOverrides: { fields } }), }; - this.props.settings?.updateSettings(newSettings); + this.languageManager.updateSettings(newSettings); const dateRangeEnhancement = enhancement?.searchBar?.dateRange; const dateRange = dateRangeEnhancement diff --git a/src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx b/src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx index 4621944ecce3..de22f76e4c67 100644 --- a/src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx +++ b/src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx @@ -23,7 +23,6 @@ import { } from '../../../../opensearch_dashboards_react/public'; import { UI_SETTINGS } from '../../../common'; import { getQueryLog, PersistedLog } from '../../query'; -import { Settings } from '../types'; import { NoDataPopover } from './no_data_popover'; import QueryEditorUI from './query_editor'; import { useDataSetManager } from '../search_bar/lib/use_dataset_manager'; @@ -34,7 +33,6 @@ const QueryEditor = withOpenSearchDashboards(QueryEditorUI); export interface QueryEditorTopRowProps { query?: Query; dataSetContainerRef?: React.RefCallback; - settings?: Settings; onSubmit: (payload: { dateRange: TimeRange; query?: Query }) => void; onChange: (payload: { dateRange: TimeRange; query?: Query }) => void; onRefresh?: (payload: { dateRange: TimeRange }) => void; @@ -71,7 +69,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { storage, appName, data: { - query: { dataSetManager: dataSetManager }, + query: { dataSetManager: dataSetManager, queryString }, }, } = opensearchDashboards.services; const { dataSet } = useDataSetManager({ dataSetManager: dataSetManager! }); @@ -79,8 +77,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { const queryLanguage = props.query && props.query.language; const queryUiEnhancement = (queryLanguage && - props.settings && - props.settings.getQueryEnhancements(queryLanguage)?.searchBar) || + queryString.getLanguageManager().getQueryEnhancements(queryLanguage)?.searchBar) || null; const parsedQuery = !queryUiEnhancement || isValidQuery(props.query) @@ -196,9 +193,8 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { } function getQueryStringInitialValue(language: string) { - const { settings } = props; - const input = settings?.getQueryEnhancements(language)?.searchBar?.queryStringInput - ?.initialValue; + const input = queryString.getLanguageManager().getQueryEnhancements(language)?.searchBar + ?.queryStringInput?.initialValue; if (!input) return ''; @@ -215,7 +211,6 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { queryActions={props.prepend} query={parsedQuery} dataSetContainerRef={props.dataSetContainerRef} - settings={props.settings!} screenTitle={props.screenTitle} onChange={onQueryChange} onChangeQueryEditorFocus={onChangeQueryEditorFocus} @@ -255,7 +250,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { } function shouldRenderQueryEditor(): boolean { - return Boolean(props.showQueryEditor && props.settings && props.query && storage); + return Boolean(props.showQueryEditor && props.query && storage); } function renderUpdateButton() { diff --git a/src/plugins/data/public/ui/search_bar/create_search_bar.tsx b/src/plugins/data/public/ui/search_bar/create_search_bar.tsx index 675f6cdc5791..3a3d2e1871a2 100644 --- a/src/plugins/data/public/ui/search_bar/create_search_bar.tsx +++ b/src/plugins/data/public/ui/search_bar/create_search_bar.tsx @@ -40,13 +40,11 @@ import { useSavedQuery } from './lib/use_saved_query'; import { DataPublicPluginStart } from '../../types'; import { DataStorage, Filter, Query, TimeRange } from '../../../common'; import { useQueryStringManager } from './lib/use_query_string_manager'; -import { Settings } from '../types'; interface StatefulSearchBarDeps { core: CoreStart; data: Omit; storage: DataStorage; - settings: Settings; setDataSetContainerRef: (ref: HTMLDivElement | null) => void; } @@ -136,7 +134,6 @@ export function createSearchBar({ core, storage, data, - settings, setDataSetContainerRef, }: StatefulSearchBarDeps) { // App name should come from the core application service. @@ -217,7 +214,6 @@ export function createSearchBar({ isRefreshPaused={refreshInterval.pause} filters={filters} query={query} - settings={settings} dataSetContainerRef={dataSetContainerRef} onFiltersUpdated={defaultFiltersUpdated(data.query)} onRefreshChange={defaultOnRefreshChange(data.query)} diff --git a/src/plugins/data/public/ui/search_bar/search_bar.tsx b/src/plugins/data/public/ui/search_bar/search_bar.tsx index fd8ff3dc21c1..34beeb508f0e 100644 --- a/src/plugins/data/public/ui/search_bar/search_bar.tsx +++ b/src/plugins/data/public/ui/search_bar/search_bar.tsx @@ -44,7 +44,6 @@ import { FilterBar } from '../filter_bar/filter_bar'; import { QueryEditorTopRow } from '../query_editor'; import QueryBarTopRow from '../query_string_input/query_bar_top_row'; import { SavedQueryMeta, SaveQueryForm } from '../saved_query_form'; -import { Settings } from '../types'; import { FilterOptions } from '../filter_bar/filter_options'; interface SearchBarInjectedDeps { @@ -78,7 +77,6 @@ export interface SearchBarOwnProps { datePickerRef?: React.RefObject; // Query bar - should be in SearchBarInjectedDeps query?: Query; - settings?: Settings; dataSetContainerRef?: React.RefCallback; // Show when user has privileges to save showSaveQuery?: boolean; @@ -208,7 +206,9 @@ class SearchBarUI extends Component { }; private supportsEnhancements() { - return this.props.settings?.supportsEnhancementsEnabled(this.services.appName); + return this.queryStringService + .getLanguageManager() + .supportsEnhancementsEnabled(this.services.appName); } private shouldRenderQueryEditor(isEnhancementsEnabledOverride: boolean) { @@ -238,8 +238,9 @@ class SearchBarUI extends Component { (!this.useNewHeader || this.props.filters.length > 0) && this.props.indexPatterns && compact(this.props.indexPatterns).length > 0 && - (this.props.settings?.getQueryEnhancements(this.state.query?.language!)?.searchBar - ?.showFilterBar ?? + (this.queryStringService + .getLanguageManager() + .getQueryEnhancements(this.state.query?.language!)?.searchBar?.showFilterBar ?? true) ); } @@ -418,10 +419,14 @@ class SearchBarUI extends Component { this.supportsEnhancements() && this.services.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED); - this.props.settings?.setUserQueryLanguageBlocklist( - this.services.uiSettings.get(UI_SETTINGS.SEARCH_QUERY_LANGUAGE_BLOCKLIST) - ); - this.props.settings?.setUserQueryEnhancementsEnabled(isEnhancementsEnabledOverride); + this.queryStringService + .getLanguageManager() + .setUserQueryLanguageBlocklist( + this.services.uiSettings.get(UI_SETTINGS.SEARCH_QUERY_LANGUAGE_BLOCKLIST) + ); + this.queryStringService + .getLanguageManager() + .setUserQueryEnhancementsEnabled(isEnhancementsEnabledOverride); const searchBarMenu = (useSaveQueryMenu: boolean = false) => { return ( @@ -513,7 +518,6 @@ class SearchBarUI extends Component { ; SearchBar: React.ComponentType; SuggestionsComponent: React.ComponentType; - /** - * @experimental - Subject to change - */ - Settings: Settings; dataSetContainer$: Observable; } diff --git a/src/plugins/data/public/ui/ui_service.ts b/src/plugins/data/public/ui/ui_service.ts index 1802e3b79320..8be08227aaac 100644 --- a/src/plugins/data/public/ui/ui_service.ts +++ b/src/plugins/data/public/ui/ui_service.ts @@ -9,11 +9,9 @@ import { ConfigSchema } from '../../config'; import { DataPublicPluginStart } from '../types'; import { createDataSetNavigator } from './dataset_navigator'; import { createIndexPatternSelect } from './index_pattern_select'; -import { QueryEditorExtensionConfig } from './query_editor'; import { createSearchBar } from './search_bar/create_search_bar'; -import { createSettings } from './settings'; import { SuggestionsComponent } from './typeahead'; -import { IUiSetup, IUiStart, QueryEnhancement, UiEnhancements } from './types'; +import { IUiSetup, IUiStart } from './types'; import { DataStorage } from '../../common'; /** @internal */ @@ -28,8 +26,6 @@ export interface UiServiceStartDependencies { export class UiService implements Plugin { enhancementsConfig: ConfigSchema['enhancements']; - private queryEnhancements: Map = new Map(); - private queryEditorExtensionMap: Record = {}; private dataSetContainer$ = new BehaviorSubject(null); constructor(initializerContext: PluginInitializerContext) { @@ -38,30 +34,9 @@ export class UiService implements Plugin { this.enhancementsConfig = enhancements; } - public setup(core: CoreSetup, {}: UiServiceSetupDependencies): IUiSetup { - return { - __enhance: (enhancements?: UiEnhancements) => { - if (!enhancements) return; - if (enhancements.query && enhancements.query.language) { - this.queryEnhancements.set(enhancements.query.language, enhancements.query); - } - if (enhancements.queryEditorExtension) { - this.queryEditorExtensionMap[enhancements.queryEditorExtension.id] = - enhancements.queryEditorExtension; - } - }, - }; - } + public setup(core: CoreSetup, {}: UiServiceSetupDependencies): any {} public start(core: CoreStart, { dataServices, storage }: UiServiceStartDependencies): IUiStart { - const Settings = createSettings({ - config: this.enhancementsConfig, - search: dataServices.search, - storage, - queryEnhancements: this.queryEnhancements, - queryEditorExtensionMap: this.queryEditorExtensionMap, - }); - const setDataSetContainerRef = (ref: HTMLDivElement | null) => { this.dataSetContainer$.next(ref); }; @@ -70,7 +45,6 @@ export class UiService implements Plugin { core, data: dataServices, storage, - settings: Settings, setDataSetContainerRef, }); @@ -83,7 +57,6 @@ export class UiService implements Plugin { ), SearchBar, SuggestionsComponent, - Settings, dataSetContainer$: this.dataSetContainer$, }; } diff --git a/src/plugins/data_explorer/public/components/sidebar/index.tsx b/src/plugins/data_explorer/public/components/sidebar/index.tsx index 616be16e9f56..e1303fcf9bb5 100644 --- a/src/plugins/data_explorer/public/components/sidebar/index.tsx +++ b/src/plugins/data_explorer/public/components/sidebar/index.tsx @@ -24,7 +24,12 @@ export const Sidebar: FC = ({ children }) => { const { services: { - data: { indexPatterns, dataSources, ui }, + data: { + indexPatterns, + dataSources, + ui, + query: { queryString }, + }, notifications: { toasts }, application, }, @@ -33,16 +38,17 @@ export const Sidebar: FC = ({ children }) => { const { DataSetNavigator } = ui; useEffect(() => { - const subscriptions = ui.Settings.getEnabledQueryEnhancementsUpdated$().subscribe( - (enabledQueryEnhancements) => { + const subscriptions = queryString + .getLanguageManager() + .getEnabledQueryEnhancementsUpdated$() + .subscribe((enabledQueryEnhancements) => { setIsEnhancementsEnabled(enabledQueryEnhancements); - } - ); + }); return () => { subscriptions.unsubscribe(); }; - }, [ui.Settings]); + }, [queryString]); const setContainerRef = useCallback((uiContainerRef) => { uiContainerRef.appendChild(containerRef.current); diff --git a/yarn.lock b/yarn.lock index e3cacd0f1623..a8d9af23c63e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15986,7 +15986,7 @@ string-similarity@^4.0.1: resolved "https://registry.yarnpkg.com/string-similarity/-/string-similarity-4.0.4.tgz#42d01ab0b34660ea8a018da8f56a3309bb8b2a5b" integrity sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ== -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -16021,15 +16021,6 @@ string-width@^3.0.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -16108,7 +16099,7 @@ stringify-entities@^3.0.1: character-entities-legacy "^1.0.0" xtend "^4.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -16150,13 +16141,6 @@ strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -18300,7 +18284,7 @@ workerpool@6.2.1: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -18326,15 +18310,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"