-
Notifications
You must be signed in to change notification settings - Fork 919
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
[discover] Query editor UI clean up #7896
Changes from all commits
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 @@ | ||
fix: | ||
- Query editor UI clean up ([#7896](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7896)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
|
||
import { EuiButtonIcon, EuiLink, EuiPopover, EuiPopoverTitle, EuiText } from '@elastic/eui'; | ||
|
||
import React from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { IDataPluginServices } from '../../../types'; | ||
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; | ||
|
||
export const DefaultLanguageReference = () => { | ||
const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>(); | ||
const [isLanguageReferenceOpen, setIsLanguageReferenceOpen] = React.useState(false); | ||
abbyhu2000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const osdDQLDocs = opensearchDashboards.services.docLinks?.links.opensearchDashboards.dql.base; | ||
Check warning on line 18 in src/plugins/data/public/query/query_string/language_service/default_language_reference.tsx Codecov / codecov/patchsrc/plugins/data/public/query/query_string/language_service/default_language_reference.tsx#L16-L18
|
||
const dqlFullName = ( | ||
<FormattedMessage | ||
Check warning on line 20 in src/plugins/data/public/query/query_string/language_service/default_language_reference.tsx Codecov / codecov/patchsrc/plugins/data/public/query/query_string/language_service/default_language_reference.tsx#L20
|
||
id="data.query.queryBar.dqlFullLanguageName" | ||
defaultMessage="OpenSearch Dashboards Query 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. is this worth to make it a optional property of the language config?
|
||
/> | ||
); | ||
|
||
const button = ( | ||
<div> | ||
Check warning on line 27 in src/plugins/data/public/query/query_string/language_service/default_language_reference.tsx Codecov / codecov/patchsrc/plugins/data/public/query/query_string/language_service/default_language_reference.tsx#L27
|
||
<EuiButtonIcon | ||
iconType={'iInCircle'} | ||
aria-label={i18n.translate('discover.queryControls.languageReference', { | ||
abbyhu2000 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaultMessage: `Language Reference`, | ||
})} | ||
onClick={() => setIsLanguageReferenceOpen(!isLanguageReferenceOpen)} | ||
Check warning on line 33 in src/plugins/data/public/query/query_string/language_service/default_language_reference.tsx Codecov / codecov/patchsrc/plugins/data/public/query/query_string/language_service/default_language_reference.tsx#L33
|
||
/> | ||
</div> | ||
); | ||
|
||
return ( | ||
Check warning on line 38 in src/plugins/data/public/query/query_string/language_service/default_language_reference.tsx Codecov / codecov/patchsrc/plugins/data/public/query/query_string/language_service/default_language_reference.tsx#L38
|
||
<EuiPopover | ||
id="languageReferencePopover" | ||
button={button} | ||
isOpen={isLanguageReferenceOpen} | ||
closePopover={() => setIsLanguageReferenceOpen(false)} | ||
Check warning on line 43 in src/plugins/data/public/query/query_string/language_service/default_language_reference.tsx Codecov / codecov/patchsrc/plugins/data/public/query/query_string/language_service/default_language_reference.tsx#L43
|
||
panelPaddingSize="s" | ||
anchorPosition="downLeft" | ||
anchorClassName="euiFormControlLayout__append" | ||
> | ||
<EuiPopoverTitle> | ||
<FormattedMessage | ||
id="data.query.queryBar.syntaxOptionsTitle" | ||
defaultMessage="Syntax options" | ||
/> | ||
</EuiPopoverTitle> | ||
<div style={{ width: '350px' }}> | ||
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. could you make this a class? 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. Do we still need to make this a class after i added a public function call to the language service class?
|
||
<EuiText size="s"> | ||
<p> | ||
<FormattedMessage | ||
id="data.query.queryBar.syntaxOptionsDescription" | ||
defaultMessage="The {docsLink} (DQL) offers a simplified query syntax and support for scripted fields." | ||
values={{ | ||
docsLink: ( | ||
<EuiLink href={osdDQLDocs} target="_blank"> | ||
{dqlFullName} | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
</p> | ||
</EuiText> | ||
</div> | ||
</EuiPopover> | ||
); | ||
}; | ||
|
||
export const createDefaultLanguageReference = () => { | ||
return <DefaultLanguageReference />; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { | |
UiEnhancements, | ||
} from '../../../ui'; | ||
import { DataStorage, setOverrides as setFieldOverrides } from '../../../../common'; | ||
import { createDefaultLanguageReference } from './default_language_reference'; | ||
|
||
export class LanguageService { | ||
private languages: Map<string, LanguageConfig> = new Map(); | ||
|
@@ -27,22 +28,27 @@ export class LanguageService { | |
this.queryEditorExtensionMap = {}; | ||
} | ||
|
||
public createDefaultQueryEditor() { | ||
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. i think the goal here is that the language service exposes public methods. So this was the intent instead,, that developers can add a new language an just call
if they wanted to use the default editor for their 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. added a public function call within the language service:
|
||
return createEditor(SingleLineInput, SingleLineInput, DQLBody); | ||
} | ||
|
||
public __enhance = (enhancements: UiEnhancements) => { | ||
if (enhancements.queryEditorExtension) { | ||
this.queryEditorExtensionMap[enhancements.queryEditorExtension.id] = | ||
enhancements.queryEditorExtension; | ||
} | ||
}; | ||
|
||
public createDefaultLanguageReference = () => { | ||
return createDefaultLanguageReference(); | ||
}; | ||
|
||
/** | ||
* Registers default handlers for index patterns and indices. | ||
*/ | ||
private registerDefaultLanguages() { | ||
const defaultEditor = createEditor(SingleLineInput, SingleLineInput, DQLBody); | ||
const defaultEditor = createEditor( | ||
SingleLineInput, | ||
SingleLineInput, | ||
[this.createDefaultLanguageReference()], | ||
DQLBody | ||
); | ||
this.registerLanguage(getDQLLanguageConfig(this.defaultSearchInterceptor, defaultEditor)); | ||
this.registerLanguage(getLuceneLanguageConfig(this.defaultSearchInterceptor, defaultEditor)); | ||
} | ||
|
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.
how come we don't register this with the DQL language config:
https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts
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.
It did get registered within the DQL language config. Within the language service, when we call createEditor, we pass in the default language reference, and eventually this editor get passed into the DQL language config.