Skip to content

Commit b3e07f7

Browse files
committed
UI experience control by ui settings
Signed-off-by: Fen Qin <[email protected]>
1 parent e4e3c4c commit b3e07f7

File tree

4 files changed

+31
-46
lines changed

4 files changed

+31
-46
lines changed

common/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const PLUGIN_ID = 'searchRelevance';
77
export const PLUGIN_NAME = 'Search Relevance';
88
export const COMPARE_SEARCH_RESULTS_TITLE = 'Compare Search Results';
99

10+
export const SEARCH_RELEVANCE_WORKBENCH_UI_EXPERIENCE_ENABLED =
11+
'search-relevance:workbench_ui_enabled';
12+
1013
const SEARCH_RELEVANCE_WORKBENCH_BASE_PATH = '/api/relevancy';
1114
export const ServiceEndpoints = Object.freeze({
1215
// OpenSearch node APIs

public/application.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const renderApp = (
2929
dataSourceManagement,
3030
setActionMenu: setHeaderActionMenu,
3131
application,
32+
uiSettings,
3233
};
3334

3435
ReactDOM.render(

public/components/app.tsx

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
import { CoreStart, MountPoint, Toast, ReactChild } from '../../../../src/core/public';
2020
import { DataSourceManagementPluginSetup } from '../../../../src/plugins/data_source_management/public';
2121
import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public';
22-
import { PLUGIN_NAME, COMPARE_SEARCH_RESULTS_TITLE, ServiceEndpoints } from '../../common';
22+
import {
23+
PLUGIN_NAME,
24+
COMPARE_SEARCH_RESULTS_TITLE,
25+
ServiceEndpoints,
26+
SEARCH_RELEVANCE_WORKBENCH_UI_EXPERIENCE_ENABLED,
27+
} from '../../common';
2328
import { SearchRelevanceContextProvider } from '../contexts';
2429
import { Home as QueryCompareHome } from './query_compare/home';
2530
import { useOpenSearchDashboards } from '../../../../src/plugins/opensearch_dashboards_react/public';
@@ -61,7 +66,7 @@ interface SearchRelevanceAppDeps {
6166
dataSourceManagement: DataSourceManagementPluginSetup;
6267
setActionMenu: (menuMount: MountPoint | undefined) => void;
6368
application: CoreStart['application'];
64-
isNewExperienceEnabled?: boolean;
69+
uiSettings: CoreStart['uiSettings'];
6570
}
6671

6772
const SearchRelevancePage = ({ history }) => {
@@ -355,46 +360,12 @@ export const SearchRelevanceApp = ({
355360
setActionMenu,
356361
dataSourceManagement,
357362
application,
363+
uiSettings,
358364
}: SearchRelevanceAppDeps) => {
359365
// Move all useState declarations to the top
360-
const [isNewExperienceEnabled, setIsNewExperienceEnabled] = useState<boolean>(false);
361-
const [isLoading, setIsLoading] = useState<boolean>(true);
362366
const [toasts, setToasts] = useState<Toast[]>([]);
363367
const [toastRightSide, setToastRightSide] = useState<boolean>(true);
364368

365-
useEffect(() => {
366-
const fetchClusterSettings = async () => {
367-
try {
368-
const response = await http.get(ServiceEndpoints.GetClusterSettings);
369-
370-
// Check both persistent and defaults settings
371-
const persistentEnabled =
372-
response?.persistent?.plugins?.search_relevance?.workbench_enabled === 'true';
373-
const defaultsEnabled =
374-
response?.defaults?.plugins?.search_relevance?.workbench_enabled === 'true';
375-
376-
// Use persistent setting if available, otherwise use defaults
377-
const enabled = persistentEnabled || defaultsEnabled;
378-
setIsNewExperienceEnabled(enabled);
379-
} catch (error) {
380-
console.error('Error fetching cluster settings:', error);
381-
notifications.toasts.addError(error as Error, {
382-
title: 'Error fetching cluster settings',
383-
toastLifeTimeMs: 5000,
384-
});
385-
setIsNewExperienceEnabled(false);
386-
} finally {
387-
setIsLoading(false);
388-
}
389-
};
390-
391-
fetchClusterSettings();
392-
}, [http, notifications]);
393-
394-
if (isLoading) {
395-
return <EuiLoadingSpinner size="xl" />;
396-
}
397-
398369
const getNavGroupEnabled = chrome.navGroup.getNavGroupEnabled();
399370

400371
const parentBreadCrumbs = getNavGroupEnabled
@@ -407,9 +378,10 @@ export const SearchRelevanceApp = ({
407378
setToasts([...toasts, { id: new Date().toISOString(), title, text, color } as Toast]);
408379
};
409380

410-
if (isLoading) {
411-
return <EuiLoadingSpinner size="xl" />;
412-
}
381+
// UI Experience are controlled by ui settings
382+
const isNewExperienceEnabled = Boolean(
383+
uiSettings?.get(SEARCH_RELEVANCE_WORKBENCH_UI_EXPERIENCE_ENABLED)
384+
);
413385

414386
const renderNewExperience = () => (
415387
<HashRouter>

server/plugin.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ import {
1414
Plugin,
1515
PluginInitializerContext,
1616
} from '../../../src/core/server';
17-
import {
18-
defineRoutes,
19-
registerSearchRelevanceRoutes,
20-
} from './routes';
17+
import { defineRoutes, registerSearchRelevanceRoutes } from './routes';
2118

2219
import { DataSourcePluginSetup } from '../../../src/plugins/data_source/server/types';
2320
import { DataSourceManagementPlugin } from '../../../src/plugins/data_source_management/public/plugin';
2421
import { SearchRelevancePluginConfigType } from '../config';
2522
import { MetricsService, MetricsServiceSetup } from './metrics/metrics_service';
2623
import { SearchRelevancePluginSetup, SearchRelevancePluginStart } from './types';
24+
import { schema } from '@osd/config-schema';
25+
import { SEARCH_RELEVANCE_WORKBENCH_UI_EXPERIENCE_ENABLED } from '../common';
2726

2827
export interface SearchRelevancePluginSetupDependencies {
2928
dataSourceManagement: ReturnType<DataSourceManagementPlugin['setup']>;
@@ -46,6 +45,16 @@ export class SearchRelevancePlugin
4645
const dataSourceEnabled = !!dataSource;
4746
this.logger.debug('SearchRelevance: Setup');
4847

48+
core.uiSettings.register({
49+
[SEARCH_RELEVANCE_WORKBENCH_UI_EXPERIENCE_ENABLED]: {
50+
name: 'Search Relevance Workbench UI Experience',
51+
value: false,
52+
description: 'Whether to opt-in search relevance workbench',
53+
schema: schema.boolean(),
54+
category: ['search relevance'],
55+
},
56+
});
57+
4958
const config: SearchRelevancePluginConfigType = await this.config$.pipe(first()).toPromise();
5059

5160
const metricsService: MetricsServiceSetup = this.metricsService.setup(
@@ -57,8 +66,8 @@ export class SearchRelevancePlugin
5766

5867
let opensearchSearchRelevanceClient: ILegacyClusterClient | undefined = undefined;
5968
opensearchSearchRelevanceClient = core.opensearch.legacy.createClient(
60-
'opensearch_search_relevance',
61-
)
69+
'opensearch_search_relevance'
70+
);
6271

6372
// @ts-ignore
6473
core.http.registerRouteHandlerContext('searchRelevance', (context, request) => {

0 commit comments

Comments
 (0)