From e430a7f9fbf0e0aba15188d9470d0dee6727bf2a Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Thu, 5 Oct 2023 20:21:22 +0300 Subject: [PATCH] [ES|QL] Improves application messages (#168078) --- packages/kbn-es-query/src/es_query/es_aggregate_query.ts | 5 +++-- .../src/text_based_languages_editor.tsx | 2 +- .../public/dataview_picker/change_dataview.tsx | 6 ++++-- .../dataview_picker/text_languages_transition_modal.tsx | 4 ++-- .../public/query_string_input/query_bar_top_row.tsx | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/kbn-es-query/src/es_query/es_aggregate_query.ts b/packages/kbn-es-query/src/es_query/es_aggregate_query.ts index 76f7113f2a589..e6f8af0de02c3 100644 --- a/packages/kbn-es-query/src/es_query/es_aggregate_query.ts +++ b/packages/kbn-es-query/src/es_query/es_aggregate_query.ts @@ -28,8 +28,9 @@ export function getAggregateQueryMode(query: AggregateQuery): Language { return Object.keys(query)[0] as Language; } -export function getLanguageDisplayName(language: string): string { - return language === 'esql' ? 'es|ql' : language; +export function getLanguageDisplayName(language?: string): string { + const displayName = language && language === 'esql' ? 'es|ql' : language ?? 'es|ql'; + return displayName.toUpperCase(); } // retrieves the index pattern from the aggregate query for SQL diff --git a/packages/kbn-text-based-editor/src/text_based_languages_editor.tsx b/packages/kbn-text-based-editor/src/text_based_languages_editor.tsx index b84e459fd222d..f8dd803265523 100644 --- a/packages/kbn-text-based-editor/src/text_based_languages_editor.tsx +++ b/packages/kbn-text-based-editor/src/text_based_languages_editor.tsx @@ -580,7 +580,7 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({ {documentationSections && ( { if (textBasedLanguage) { - setTriggerLabel(getLanguageDisplayName(textBasedLanguage).toUpperCase()); + setTriggerLabel(getLanguageDisplayName(textBasedLanguage)); } else { setTriggerLabel(trigger.label); } @@ -244,7 +244,9 @@ export function ChangeDataView({ { defaultMessage: "Switching data views removes the current {textBasedLanguage} query. Save this search to ensure you don't lose work.", - values: { textBasedLanguage }, + values: { + textBasedLanguage: getLanguageDisplayName(textBasedLanguage), + }, } )} > diff --git a/src/plugins/unified_search/public/dataview_picker/text_languages_transition_modal.tsx b/src/plugins/unified_search/public/dataview_picker/text_languages_transition_modal.tsx index c59599907456b..0ff475d6a344c 100644 --- a/src/plugins/unified_search/public/dataview_picker/text_languages_transition_modal.tsx +++ b/src/plugins/unified_search/public/dataview_picker/text_languages_transition_modal.tsx @@ -8,7 +8,7 @@ import React, { useState, useCallback } from 'react'; import { i18n } from '@kbn/i18n'; - +import { getLanguageDisplayName } from '@kbn/es-query'; import { EuiModal, EuiModalBody, @@ -39,7 +39,7 @@ export default function TextBasedLanguagesTransitionModal({ setDismissModalChecked(e.target.checked); }, []); - const language = textBasedLanguage?.toUpperCase(); + const language = getLanguageDisplayName(textBasedLanguage); return ( setIsTextLangTransitionModalVisible(false)} style={{ width: 700 }}> diff --git a/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx b/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx index 0a20154b0d0b6..35a5770dfff41 100644 --- a/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx +++ b/src/plugins/unified_search/public/query_string_input/query_bar_top_row.tsx @@ -90,7 +90,7 @@ const getWrapperWithTooltip = ( position="top" content={i18n.translate('unifiedSearch.query.queryBar.textBasedNonTimestampWarning', { defaultMessage: - 'Date range selection for {language} queries requires the presence of an @timestamp field in the dataset.', + 'Date range selection for {language} queries requires an @timestamp field in the dataset.', values: { language: displayName }, })} >