diff --git a/src/plugins/dashboard/public/application/utils/create_dashboard_container.tsx b/src/plugins/dashboard/public/application/utils/create_dashboard_container.tsx index 1c5b06f54e57..acf1147b8c15 100644 --- a/src/plugins/dashboard/public/application/utils/create_dashboard_container.tsx +++ b/src/plugins/dashboard/public/application/utils/create_dashboard_container.tsx @@ -282,7 +282,12 @@ const getEmptyScreenProps = ( getFactory: embeddable.getEmbeddableFactory, notifications, overlays, - SavedObjectFinder: getSavedObjectFinder(savedObjects, uiSettings), + SavedObjectFinder: getSavedObjectFinder( + savedObjects, + uiSettings, + services.data, + services.application + ), }); } } else { diff --git a/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx b/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx index 32bfef083518..5c98bb55099a 100644 --- a/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx +++ b/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx @@ -174,7 +174,12 @@ export const getNavActions = ( getFactory: embeddable.getEmbeddableFactory, notifications, overlays, - SavedObjectFinder: getSavedObjectFinder(savedObjects, uiSettings), + SavedObjectFinder: getSavedObjectFinder( + savedObjects, + uiSettings, + services.data, + services.application + ), }); } }; diff --git a/src/plugins/dashboard/public/plugin.tsx b/src/plugins/dashboard/public/plugin.tsx index 5d6ad78ca0b7..c7951a955fde 100644 --- a/src/plugins/dashboard/public/plugin.tsx +++ b/src/plugins/dashboard/public/plugin.tsx @@ -567,7 +567,12 @@ export class DashboardPlugin embeddable, } = plugins; - const SavedObjectFinder = getSavedObjectFinder(core.savedObjects, core.uiSettings); + const SavedObjectFinder = getSavedObjectFinder( + core.savedObjects, + core.uiSettings, + plugins.data, + core.application + ); const changeViewAction = new ReplacePanelAction( core, diff --git a/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts b/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts index d13125b9d479..39dc49f22fce 100644 --- a/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts +++ b/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts @@ -24,5 +24,6 @@ export const getDQLLanguageConfig = ( }, showDocLinks: true, editorSupportedAppNames: ['discover'], + supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer'], }; }; diff --git a/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts b/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts index f63e0a8b42c6..742747d037e9 100644 --- a/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts +++ b/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts @@ -24,5 +24,6 @@ export const getLuceneLanguageConfig = ( }, showDocLinks: true, editorSupportedAppNames: ['discover'], + supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer'], }; }; diff --git a/src/plugins/data/public/query/query_string/language_service/types.ts b/src/plugins/data/public/query/query_string/language_service/types.ts index c351cc597917..e82e12f95ec9 100644 --- a/src/plugins/data/public/query/query_string/language_service/types.ts +++ b/src/plugins/data/public/query/query_string/language_service/types.ts @@ -50,4 +50,5 @@ export interface LanguageConfig { }; showDocLinks?: boolean; editorSupportedAppNames?: string[]; + supportedAppNames?: string[]; } diff --git a/src/plugins/discover/public/application/components/top_nav/open_search_panel.tsx b/src/plugins/discover/public/application/components/top_nav/open_search_panel.tsx index 1bc4da9a08cf..6bb3a54e71f7 100644 --- a/src/plugins/discover/public/application/components/top_nav/open_search_panel.tsx +++ b/src/plugins/discover/public/application/components/top_nav/open_search_panel.tsx @@ -57,6 +57,7 @@ export function OpenSearchPanel({ onClose, makeUrl }: Props) { services: { core: { uiSettings, savedObjects, application }, addBasePath, + data, }, } = useOpenSearchDashboards(); @@ -87,6 +88,7 @@ export function OpenSearchPanel({ onClose, makeUrl }: Props) { name: i18n.translate('discover.savedSearch.savedObjectName', { defaultMessage: 'Saved search', }), + includeFields: ['kibanaSavedObjectMeta'], }, ]} onChoose={(id) => { @@ -95,6 +97,8 @@ export function OpenSearchPanel({ onClose, makeUrl }: Props) { }} uiSettings={uiSettings} savedObjects={savedObjects} + application={application} + data={data} /> diff --git a/src/plugins/discover/public/embeddable/search_embeddable_factory.tsx b/src/plugins/discover/public/embeddable/search_embeddable_factory.tsx index 8d99b87fbeb2..65db9faaff24 100644 --- a/src/plugins/discover/public/embeddable/search_embeddable_factory.tsx +++ b/src/plugins/discover/public/embeddable/search_embeddable_factory.tsx @@ -55,6 +55,7 @@ export class SearchEmbeddableFactory }), type: 'search', getIconForSavedObject: () => 'search', + includeFields: ['kibanaSavedObjectMeta'], }; constructor(private getStartServices: () => Promise) {} diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index a0f907043ec4..4ff348a512fc 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -194,7 +194,12 @@ export class EmbeddablePublicPlugin implements Plugin ); diff --git a/src/plugins/query_enhancements/public/plugin.tsx b/src/plugins/query_enhancements/public/plugin.tsx index 5247bb794c96..b6578e1e8fc3 100644 --- a/src/plugins/query_enhancements/public/plugin.tsx +++ b/src/plugins/query_enhancements/public/plugin.tsx @@ -80,6 +80,7 @@ export class QueryEnhancementsPlugin showDocLinks: false, editor: enhancedPPLQueryEditor, editorSupportedAppNames: ['discover'], + supportedAppNames: ['discover', 'data-explorer'], }; queryString.getLanguageService().registerLanguage(pplLanguageConfig); @@ -98,6 +99,7 @@ export class QueryEnhancementsPlugin showDocLinks: false, editor: enhancedSQLQueryEditor, editorSupportedAppNames: ['discover'], + supportedAppNames: ['discover', 'data-explorer'], }; queryString.getLanguageService().registerLanguage(sqlLanguageConfig); diff --git a/src/plugins/saved_objects/public/finder/saved_object_finder.tsx b/src/plugins/saved_objects/public/finder/saved_object_finder.tsx index 5c7f3f1ae031..3857d8e2bb38 100644 --- a/src/plugins/saved_objects/public/finder/saved_object_finder.tsx +++ b/src/plugins/saved_objects/public/finder/saved_object_finder.tsx @@ -58,9 +58,12 @@ import { CoreStart, IUiSettingsClient, SavedObjectsStart, + ApplicationStart, } from 'src/core/public'; import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources'; +import { DataPublicPluginStart } from 'src/plugins/data/public'; +import { first } from 'rxjs/operators'; import { getIndexPatternTitle } from '../../../data/common/index_patterns/utils'; import { LISTING_LIMIT_SETTING } from '../../common'; @@ -76,6 +79,7 @@ export interface SavedObjectMetaData { interface FinderAttributes { title?: string; type: string; + kibanaSavedObjectMeta?: string; } interface SavedObjectFinderState { @@ -122,6 +126,8 @@ export type SavedObjectFinderProps = SavedObjectFinderFixedPage | SavedObjectFin export type SavedObjectFinderUiProps = { savedObjects: CoreStart['savedObjects']; uiSettings: CoreStart['uiSettings']; + data: DataPublicPluginStart; + application: CoreStart['application']; } & SavedObjectFinderProps; class SavedObjectFinderUi extends React.Component< @@ -137,10 +143,17 @@ class SavedObjectFinderUi extends React.Component< showFilter: PropTypes.bool, }; + public async getCurrentAppId() { + const appId = await this.props.application.currentAppId$.pipe(first()).toPromise(); + return appId; + } + + readonly languageService = this.props.data.query.queryString.getLanguageService(); private isComponentMounted: boolean = false; private debouncedFetch = _.debounce(async (query: string) => { const metaDataMap = this.getSavedObjectMetaDataMap(); + const currentAppId = await this.getCurrentAppId(); const fields = Object.values(metaDataMap) .map((metaData) => metaData.includeFields || []) @@ -162,7 +175,7 @@ class SavedObjectFinderUi extends React.Component< return await client.get('data-source', id); }; - const savedObjects = await Promise.all( + let savedObjects = await Promise.all( resp.savedObjects.map(async (obj) => { if (obj.type === 'index-pattern') { const result = { ...obj }; @@ -178,6 +191,25 @@ class SavedObjectFinderUi extends React.Component< }) ); + // Filter search objects whose language are not supported by the current Application + savedObjects = savedObjects.filter((obj) => { + if (obj.type === 'search') { + if (obj.attributes?.kibanaSavedObjectMeta) { + const sourceObject = JSON.parse(obj.attributes?.kibanaSavedObjectMeta?.searchSourceJSON); + const languageId = sourceObject.query.language; + + const languageProperties = this.languageService.getLanguage(languageId); + + if (languageProperties?.supportedAppNames.includes(currentAppId)) { + return true; + } else { + return false; + } + } + } + return true; + }); + resp.savedObjects = savedObjects.filter((savedObject) => { const metaData = metaDataMap[savedObject.type]; if (metaData.showSavedObject) { @@ -571,9 +603,20 @@ class SavedObjectFinderUi extends React.Component< } } -const getSavedObjectFinder = (savedObject: SavedObjectsStart, uiSettings: IUiSettingsClient) => { +const getSavedObjectFinder = ( + savedObject: SavedObjectsStart, + uiSettings: IUiSettingsClient, + data: DataPublicPluginStart, + application: ApplicationStart +) => { return (props: SavedObjectFinderProps) => ( - + ); }; diff --git a/src/plugins/visualizations/public/plugin.ts b/src/plugins/visualizations/public/plugin.ts index bd255b82c6af..911ff931881c 100644 --- a/src/plugins/visualizations/public/plugin.ts +++ b/src/plugins/visualizations/public/plugin.ts @@ -64,6 +64,7 @@ import { setEmbeddable, setNotifications, setDocLinks, + setDataStart, } from './services'; import { VISUALIZE_EMBEDDABLE_TYPE, @@ -192,6 +193,7 @@ export class VisualizationsPlugin chrome: core.chrome, overlays: core.overlays, }); + setDataStart(data); setSavedAugmentVisLoader(savedAugmentVisLoader); setI18n(core.i18n); setTypes(types); diff --git a/src/plugins/visualizations/public/services.ts b/src/plugins/visualizations/public/services.ts index 62266ff2ba53..7d517759ea20 100644 --- a/src/plugins/visualizations/public/services.ts +++ b/src/plugins/visualizations/public/services.ts @@ -119,3 +119,5 @@ export const [getSavedAugmentVisLoader, setSavedAugmentVisLoader] = createGetter >('savedAugmentVisLoader'); export const [getDocLinks, setDocLinks] = createGetterSetter('docLinks'); + +export const [getDataStart, setDataStart] = createGetterSetter('DataStart'); diff --git a/src/plugins/visualizations/public/wizard/new_vis_modal.tsx b/src/plugins/visualizations/public/wizard/new_vis_modal.tsx index b02ba449dec1..00a2253ea3ee 100644 --- a/src/plugins/visualizations/public/wizard/new_vis_modal.tsx +++ b/src/plugins/visualizations/public/wizard/new_vis_modal.tsx @@ -34,6 +34,7 @@ import { EuiModal } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { METRIC_TYPE, UiStatsMetricType } from '@osd/analytics'; +import { DataPublicPluginStart } from 'src/plugins/data/public'; import { ApplicationStart, IUiSettingsClient, SavedObjectsStart } from '../../../../core/public'; import { SearchSelection } from './search_selection'; import { TypeSelection } from './type_selection'; @@ -55,6 +56,7 @@ interface TypeSelectionProps { outsideVisualizeApp?: boolean; stateTransfer?: EmbeddableStateTransfer; originatingApp?: string; + data: DataPublicPluginStart; } interface TypeSelectionState { @@ -112,6 +114,8 @@ class NewVisModal extends React.Component ) : ( diff --git a/src/plugins/visualizations/public/wizard/search_selection/search_selection.tsx b/src/plugins/visualizations/public/wizard/search_selection/search_selection.tsx index 9f98f7520103..2a0ce51a6d8e 100644 --- a/src/plugins/visualizations/public/wizard/search_selection/search_selection.tsx +++ b/src/plugins/visualizations/public/wizard/search_selection/search_selection.tsx @@ -32,7 +32,8 @@ import { EuiModalBody, EuiModalHeader, EuiModalHeaderTitle } from '@elastic/eui' import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; import React from 'react'; -import { IUiSettingsClient, SavedObjectsStart } from '../../../../../core/public'; +import { DataPublicPluginStart } from 'src/plugins/data/public'; +import { ApplicationStart, IUiSettingsClient, SavedObjectsStart } from '../../../../../core/public'; import { SavedObjectFinderUi } from '../../../../saved_objects/public'; import { VisType } from '../../vis_types'; @@ -42,6 +43,8 @@ interface SearchSelectionProps { visType: VisType; uiSettings: IUiSettingsClient; savedObjects: SavedObjectsStart; + data: DataPublicPluginStart; + application: ApplicationStart; } export class SearchSelection extends React.Component { @@ -85,6 +88,7 @@ export class SearchSelection extends React.Component { defaultMessage: 'Saved search', } ), + includeFields: ['kibanaSavedObjectMeta'], }, { type: 'index-pattern', @@ -100,6 +104,8 @@ export class SearchSelection extends React.Component { fixedPageSize={this.fixedPageSize} uiSettings={this.props.uiSettings} savedObjects={this.props.savedObjects} + application={this.props.application} + data={this.props.data} /> diff --git a/src/plugins/visualizations/public/wizard/show_new_vis.tsx b/src/plugins/visualizations/public/wizard/show_new_vis.tsx index a9dad7f026b6..5bd83d9bd3c7 100644 --- a/src/plugins/visualizations/public/wizard/show_new_vis.tsx +++ b/src/plugins/visualizations/public/wizard/show_new_vis.tsx @@ -41,6 +41,7 @@ import { getUsageCollector, getApplication, getEmbeddable, + getDataStart, } from '../services'; export interface ShowNewVisModalParams { @@ -90,6 +91,7 @@ export function showNewVisModal({ savedObjects={getSavedObjects()} usageCollection={getUsageCollector()} application={getApplication()} + data={getDataStart()} /> );