Skip to content

Commit

Permalink
Fix Queries of Unsupported types appearing on Visualize & Vis Builder…
Browse files Browse the repository at this point in the history
… Search Bar (#8601) (#8656)

* Fix Queries of Unsupported types appearing on Visualize
* Fix PR comments
---------
(cherry picked from commit 84f925b)
Signed-off-by: Suchit Sahoo <suchsah@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
opensearch-trigger-bot[bot] authored Oct 18, 2024
1 parent d47ecc0 commit c05bdf6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
UiSettingsPublicToCommon,
} from './index_patterns';
import {
setApplication,
setFieldFormats,
setIndexPatterns,
setNotifications,
Expand Down Expand Up @@ -151,6 +152,7 @@ export class DataPublicPlugin
sessionStorage: this.sessionStorage,
defaultSearchInterceptor: searchService.getDefaultSearchInterceptor(),
application: core.application,
notifications: core.notifications,
});

uiActions.registerAction(
Expand Down Expand Up @@ -195,6 +197,7 @@ export class DataPublicPlugin
setNotifications(notifications);
setOverlays(overlays);
setUiSettings(uiSettings);
setApplication(application);

const fieldFormats = this.fieldFormatsService.start();
setFieldFormats(fieldFormats);
Expand Down Expand Up @@ -226,6 +229,7 @@ export class DataPublicPlugin
uiSettings,
indexPatterns,
application: core.application,
notifications,
});
setQueryService(query);

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class QueryService {
storage,
sessionStorage,
defaultSearchInterceptor,
notifications,
}: QueryServiceSetupDependencies): IQuerySetup {
this.filterManager = new FilterManager(uiSettings);

Expand All @@ -75,7 +76,8 @@ export class QueryService {
storage,
sessionStorage,
uiSettings,
defaultSearchInterceptor
defaultSearchInterceptor,
notifications
);

this.state$ = createQueryStateObservable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export const getDQLLanguageConfig = (
},
showDocLinks: true,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer', 'vis-builder', '*'],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export const getLuceneLanguageConfig = (
},
showDocLinks: true,
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer', 'vis-builder', '*'],
};
};
66 changes: 63 additions & 3 deletions src/plugins/data/public/query/query_string/query_string_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@

import { BehaviorSubject } from 'rxjs';
import { skip } from 'rxjs/operators';
import { CoreStart } from 'opensearch-dashboards/public';
import { isEqual } from 'lodash';
import { CoreStart, NotificationsSetup } from 'opensearch-dashboards/public';
import { debounce, isEqual } from 'lodash';
import { i18n } from '@osd/i18n';
import { Dataset, DataStorage, Query, TimeRange, UI_SETTINGS } from '../../../common';
import { createHistory, QueryHistory } from './query_history';
import { DatasetService, DatasetServiceContract } from './dataset_service';
import { LanguageService, LanguageServiceContract } from './language_service';
import { ISearchInterceptor } from '../../search';
import { getApplication } from '../../services';

export class QueryStringManager {
private query$: BehaviorSubject<Query>;
Expand All @@ -48,7 +50,8 @@ export class QueryStringManager {
private readonly storage: DataStorage,
private readonly sessionStorage: DataStorage,
private readonly uiSettings: CoreStart['uiSettings'],
private readonly defaultSearchInterceptor: ISearchInterceptor
private readonly defaultSearchInterceptor: ISearchInterceptor,
private readonly notifications: NotificationsSetup
) {
this.query$ = new BehaviorSubject<Query>(this.getDefaultQuery());
this.queryHistory = createHistory({ storage });
Expand Down Expand Up @@ -108,6 +111,40 @@ export class QueryStringManager {
};

public getQuery = (): Query => {
const currentAppId = this.getCurrentAppId();
const query = this.query$.getValue();

if (currentAppId) {
const currentLanguage = query.language;
if (
containsWildcardOrValue(
this.languageService.getLanguage(currentLanguage)?.supportedAppNames,
currentAppId
)
) {
return this.query$.getValue();
}

const defaultLanguage = this.uiSettings.get('search:queryLanguage');
const defaultLanguageTitle = this.languageService.getLanguage(defaultLanguage)?.title;

showWarning(this.notifications, {
title: i18n.translate('data.unSupportedLanguageTitle', {
defaultMessage: 'Unsupported Language Selected',
}),
text: i18n.translate('data.unSupportedLanguageBody', {
defaultMessage:
'Selected language {currentLanguage} is not supported. Defaulting to {defaultLanguage}.',
values: {
currentLanguage,
defaultLanguage: defaultLanguageTitle,
},
}),
});

const updatedQuery = this.getInitialQueryByLanguage(defaultLanguage);
this.setQuery(updatedQuery);
}
return this.query$.getValue();
};

Expand Down Expand Up @@ -194,6 +231,29 @@ export class QueryStringManager {
this.uiSettings.get(UI_SETTINGS.SEARCH_QUERY_LANGUAGE)
);
}

private getCurrentAppId = () => {
let appId;
try {
const application = getApplication();
if (application) {
application.currentAppId$.subscribe((val) => (appId = val)).unsubscribe();
}
} catch (err) {
// eslint-disable-next-line no-console
console.log('Application Not available.');
}

return appId;
};
}

const showWarning = (notifications: NotificationsSetup, { title, text }) => {
notifications.toasts.addWarning({ title, text, id: 'unsupported_language_selected' });
};

const containsWildcardOrValue = (arr: string[] | undefined, value: string) => {
return arr ? arr.includes('*') || arr.includes(value) : true;
};

export type QueryStringContract = PublicMethodsOf<QueryStringManager>;
4 changes: 4 additions & 0 deletions src/plugins/data/public/query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
ApplicationSetup,
ApplicationStart,
IUiSettingsClient,
NotificationsSetup,
NotificationsStart,
SavedObjectsClientContract,
} from 'opensearch-dashboards/public';
import { Observable } from 'rxjs';
Expand Down Expand Up @@ -44,6 +46,7 @@ export interface QueryServiceSetupDependencies {
sessionStorage: DataStorage;
defaultSearchInterceptor: ISearchInterceptor;
application: ApplicationSetup;
notifications: NotificationsSetup;
}

/** @internal */
Expand All @@ -53,4 +56,5 @@ export interface QueryServiceStartDependencies {
uiSettings: IUiSettingsClient;
indexPatterns: IndexPatternsService;
application: ApplicationStart;
notifications: NotificationsStart;
}
4 changes: 3 additions & 1 deletion src/plugins/data/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* under the License.
*/

import { NotificationsStart, CoreStart } from 'src/core/public';
import { NotificationsStart, CoreStart, ApplicationStart } from 'src/core/public';
import { FieldFormatsStart } from './field_formats';
import { createGetterSetter } from '../../opensearch_dashboards_utils/public';
import { IndexPatternsContract } from './index_patterns';
Expand Down Expand Up @@ -61,3 +61,5 @@ export const [getSearchService, setSearchService] = createGetterSetter<
>('Search');

export const [getUiService, setUiService] = createGetterSetter<DataPublicPluginStart['ui']>('Ui');

export const [getApplication, setApplication] = createGetterSetter<ApplicationStart>('Application');

0 comments on commit c05bdf6

Please sign in to comment.