-
Notifications
You must be signed in to change notification settings - Fork 918
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
Created language manager inside query string service #7756
Changes from all commits
56ddcc6
9176247
e00e200
04e0dc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- Created language manager inside query string service ([#7756](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7756)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { createEditor, DQLBody, QueryEditorExtensionConfig, SingleLineInput } from '../../../ui'; | ||
import { ConfigSchema } from '../../../../config'; | ||
import { DataStorage, setOverrides as setFieldOverrides } from '../../../../common'; | ||
|
||
export interface DataSettings { | ||
userQueryLanguage: string; | ||
|
@@ -22,21 +21,49 @@ | |
}; | ||
} | ||
|
||
export class Settings { | ||
export class LanguageManager { | ||
private isEnabled = false; | ||
private enabledQueryEnhancementsUpdated$ = new BehaviorSubject<boolean>(this.isEnabled); | ||
private enhancedAppNames: string[] = []; | ||
private queryEnhancements: Map<string, QueryEnhancement>; | ||
private queryEditorExtensionMap: Record<string, QueryEditorExtensionConfig>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be apart of the query enhancement |
||
|
||
constructor( | ||
private readonly config: ConfigSchema['enhancements'], | ||
private readonly search: ISearchStart, | ||
private readonly storage: DataStorage, | ||
private readonly queryEnhancements: Map<string, QueryEnhancement>, | ||
private readonly queryEditorExtensionMap: Record<string, QueryEditorExtensionConfig> | ||
private readonly storage: DataStorage | ||
) { | ||
this.isEnabled = true; | ||
this.setUserQueryEnhancementsEnabled(this.isEnabled); | ||
this.enhancedAppNames = this.isEnabled ? this.config.supportedAppNames : []; | ||
this.queryEnhancements = new Map(); | ||
this.queryEditorExtensionMap = {}; | ||
Check warning on line 39 in src/plugins/data/public/query/query_string/language_manager/language_manager.ts Codecov / codecov/patchsrc/plugins/data/public/query/query_string/language_manager/language_manager.ts#L38-L39
|
||
} | ||
|
||
public createDefaultQueryEditor() { | ||
return createEditor(SingleLineInput, SingleLineInput, DQLBody); | ||
} | ||
|
||
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 +85,6 @@ | |
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,18 +102,8 @@ | |
} | ||
|
||
setUserQueryLanguage(language: string) { | ||
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.setUiOverridesByUserQueryLanguage(language); | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -129,10 +134,10 @@ | |
setUiOverridesByUserQueryLanguage(language: string) { | ||
const queryEnhancement = this.queryEnhancements.get(language); | ||
if (queryEnhancement) { | ||
const { fields = {}, showDocLinks } = queryEnhancement; | ||
this.setUiOverrides({ fields, showDocLinks }); | ||
const { fields = {} } = queryEnhancement; | ||
this.setUiOverrides({ fields }); | ||
} else { | ||
this.setUiOverrides({ fields: undefined, showDocLinks: undefined }); | ||
this.setUiOverrides({ fields: undefined }); | ||
} | ||
} | ||
|
||
|
@@ -167,20 +172,4 @@ | |
} | ||
} | ||
|
||
interface Deps { | ||
config: ConfigSchema['enhancements']; | ||
search: ISearchStart; | ||
storage: DataStorage; | ||
queryEnhancements: Map<string, QueryEnhancement>; | ||
queryEditorExtensionMap: Record<string, QueryEditorExtensionConfig>; | ||
} | ||
|
||
export function createSettings({ | ||
config, | ||
search, | ||
storage, | ||
queryEnhancements, | ||
queryEditorExtensionMap, | ||
}: Deps) { | ||
return new Settings(config, search, storage, queryEnhancements, queryEditorExtensionMap); | ||
} | ||
export type LanguageContract = PublicMethodsOf<LanguageManager>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ | |
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 @@ | |
{ fieldFormats, indexPatterns }: SearchServiceStartDependencies | ||
): ISearchStart { | ||
const search = ((request, options) => { | ||
const queryString = getQueryService().queryString; | ||
const selectedLanguage = getQueryService().queryString.getQuery().language; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can use the constant you create on |
||
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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,7 @@ | |
* under the License. | ||
*/ | ||
|
||
export { | ||
UiEnhancements, | ||
IUiStart, | ||
IUiSetup, | ||
createSettings, | ||
Settings, | ||
DataSettings, | ||
} from './types'; | ||
export { UiEnhancements, IUiStart, IUiSetup } from './types'; | ||
export { IndexPatternSelectProps } from './index_pattern_select'; | ||
export { FilterLabel } from './filter_bar'; | ||
export { QueryStringInput, QueryStringInputProps } from './query_string_input'; | ||
|
@@ -46,6 +39,10 @@ export { | |
QueryEditorExtensions, | ||
QueryEditorExtensionDependencies, | ||
QueryEditorExtensionConfig, | ||
createEditor, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do we intend to use this? (sorry if it's explained later in PR). |
||
DefaultInput, | ||
DQLBody, | ||
SingleLineInput, | ||
} from './query_editor'; | ||
export { SearchBar, SearchBarProps, StatefulSearchBarProps } from './search_bar'; | ||
export { SuggestionsComponent } from './typeahead'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this can be removed