Skip to content

Commit

Permalink
rebase and address comments
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Jan 3, 2024
1 parent d8d2e5c commit 5bf8243
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: removed the following CSS
// when https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5628 is completed
.languageSwitcher {
max-width: 150px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ export function QueryLanguageSwitcher(props: Props) {
{
label: 'PPL',
},
{
label: 'SQL',
},
];
const [selectedLanguage, setSelectedLanguage] = useState([dataExplorerOptions[0]]);

const osdDQLDocs = useOpenSearchDashboards().services.docLinks?.links.opensearchDashboards.dql
.base;
Expand Down Expand Up @@ -109,20 +111,26 @@ export function QueryLanguageSwitcher(props: Props) {
);

const handleLanguageChange = (newLanguage: EuiComboBoxOptionOption[]) => {
if (['PPL', 'SQL'].includes(newLanguage[0].label)) {
application?.navigateToUrl('../observability-logs#/explorer');
return;

Check warning on line 116 in src/plugins/data/public/ui/query_string_input/language_switcher.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/query_string_input/language_switcher.tsx#L115-L116

Added lines #L115 - L116 were not covered by tests
}
const queryLanguage = newLanguage[0].label === 'DQL' ? 'kuery' : newLanguage[0].label;
props.onSelectLanguage(queryLanguage);

Check warning on line 119 in src/plugins/data/public/ui/query_string_input/language_switcher.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/query_string_input/language_switcher.tsx#L119

Added line #L119 was not covered by tests
setSelectedLanguage(newLanguage);
};

// The following is a temporary solution for adding PPL navigation, and should be replaced once final solution is determined.
// Follow-up issue: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5628
if (useObservable(currentApp$!, '') === 'data-explorer' && useNewQuerySelector) {
const selectedLanguage = {

Check warning on line 125 in src/plugins/data/public/ui/query_string_input/language_switcher.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/query_string_input/language_switcher.tsx#L125

Added line #L125 was not covered by tests
label: props.language === 'kuery' ? 'DQL' : props.language,
};
return (

Check warning on line 128 in src/plugins/data/public/ui/query_string_input/language_switcher.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/query_string_input/language_switcher.tsx#L128

Added line #L128 was not covered by tests
<EuiComboBox
className="languageSwitcher"
data-test-subj="languageSelect"
options={dataExplorerOptions}
selectedOptions={selectedLanguage}
selectedOptions={[selectedLanguage]}
onChange={handleLanguageChange}
singleSelection={{ asPlainText: true }}
isClearable={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ interface State {
selectionEnd: number | null;
indexPatterns: IIndexPattern[];
queryBarRect: DOMRect | undefined;
currentApp: string | undefined;
}

const KEY_CODES = {
Expand All @@ -120,7 +119,6 @@ export default class QueryStringInputUI extends Component<Props, State> {
selectionEnd: null,
indexPatterns: [],
queryBarRect: undefined,
currentApp: undefined,
};

public inputRef: HTMLTextAreaElement | null = null;
Expand Down Expand Up @@ -459,10 +457,6 @@ export default class QueryStringInputUI extends Component<Props, State> {
};

private onSelectLanguage = (language: string) => {
if (language === 'PPL') {
this.services.application?.navigateToUrl('../observability-logs#/explorer');
return;
}
// Send telemetry info every time the user opts in or out of kuery
// As a result it is important this function only ever gets called in the
// UI component's change handler.
Expand Down

0 comments on commit 5bf8243

Please sign in to comment.