Skip to content

change how frontend to read access #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const PLUGIN_ID = 'searchRelevance';
export const PLUGIN_NAME = 'Search Relevance';
export const COMPARE_SEARCH_RESULTS_TITLE = 'Compare Search Results';

export const SEARCH_RELEVANCE_EXPERIMENTAL_WORKBENCH_UI_EXPERIENCE_ENABLED =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yizheliu-amazon
updated experimental in toggle name

'search-relevance:experimental_workbench_ui_enabled';

const SEARCH_RELEVANCE_WORKBENCH_BASE_PATH = '/api/relevancy';
export const ServiceEndpoints = Object.freeze({
// OpenSearch node APIs
Expand Down
1 change: 1 addition & 0 deletions public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const renderApp = (
dataSourceManagement,
setActionMenu: setHeaderActionMenu,
application,
uiSettings,
};

ReactDOM.render(
Expand Down
51 changes: 11 additions & 40 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
import { CoreStart, MountPoint, Toast, ReactChild } from '../../../../src/core/public';
import { DataSourceManagementPluginSetup } from '../../../../src/plugins/data_source_management/public';
import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public';
import { PLUGIN_NAME, COMPARE_SEARCH_RESULTS_TITLE, ServiceEndpoints } from '../../common';
import {
PLUGIN_NAME,
COMPARE_SEARCH_RESULTS_TITLE,
SEARCH_RELEVANCE_EXPERIMENTAL_WORKBENCH_UI_EXPERIENCE_ENABLED,
} from '../../common';
import { SearchRelevanceContextProvider } from '../contexts';
import { Home as QueryCompareHome } from './query_compare/home';
import { useOpenSearchDashboards } from '../../../../src/plugins/opensearch_dashboards_react/public';
Expand Down Expand Up @@ -61,7 +65,7 @@ interface SearchRelevanceAppDeps {
dataSourceManagement: DataSourceManagementPluginSetup;
setActionMenu: (menuMount: MountPoint | undefined) => void;
application: CoreStart['application'];
isNewExperienceEnabled?: boolean;
uiSettings: CoreStart['uiSettings'];
}

const SearchRelevancePage = ({ history }) => {
Expand Down Expand Up @@ -355,46 +359,12 @@ export const SearchRelevanceApp = ({
setActionMenu,
dataSourceManagement,
application,
uiSettings,
}: SearchRelevanceAppDeps) => {
// Move all useState declarations to the top
const [isNewExperienceEnabled, setIsNewExperienceEnabled] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [toasts, setToasts] = useState<Toast[]>([]);
const [toastRightSide, setToastRightSide] = useState<boolean>(true);

useEffect(() => {
const fetchClusterSettings = async () => {
try {
const response = await http.get(ServiceEndpoints.GetClusterSettings);

// Check both persistent and defaults settings
const persistentEnabled =
response?.persistent?.plugins?.search_relevance?.workbench_enabled === 'true';
const defaultsEnabled =
response?.defaults?.plugins?.search_relevance?.workbench_enabled === 'true';

// Use persistent setting if available, otherwise use defaults
const enabled = persistentEnabled || defaultsEnabled;
setIsNewExperienceEnabled(enabled);
} catch (error) {
console.error('Error fetching cluster settings:', error);
notifications.toasts.addError(error as Error, {
title: 'Error fetching cluster settings',
toastLifeTimeMs: 5000,
});
setIsNewExperienceEnabled(false);
} finally {
setIsLoading(false);
}
};

fetchClusterSettings();
}, [http, notifications]);

if (isLoading) {
return <EuiLoadingSpinner size="xl" />;
}

const getNavGroupEnabled = chrome.navGroup.getNavGroupEnabled();

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

if (isLoading) {
return <EuiLoadingSpinner size="xl" />;
}
// UI Experience are controlled by ui settings
const isNewExperienceEnabled = Boolean(
uiSettings?.get(SEARCH_RELEVANCE_EXPERIMENTAL_WORKBENCH_UI_EXPERIENCE_ENABLED)
);

const renderNewExperience = () => (
<HashRouter>
Expand Down
21 changes: 15 additions & 6 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';

import { schema } from '@osd/config-schema';
import {
CoreSetup,
CoreStart,
Expand All @@ -14,16 +15,14 @@ import {
Plugin,
PluginInitializerContext,
} from '../../../src/core/server';
import {
defineRoutes,
registerSearchRelevanceRoutes,
} from './routes';
import { defineRoutes, registerSearchRelevanceRoutes } from './routes';

import { DataSourcePluginSetup } from '../../../src/plugins/data_source/server/types';
import { DataSourceManagementPlugin } from '../../../src/plugins/data_source_management/public/plugin';
import { SearchRelevancePluginConfigType } from '../config';
import { MetricsService, MetricsServiceSetup } from './metrics/metrics_service';
import { SearchRelevancePluginSetup, SearchRelevancePluginStart } from './types';
import { SEARCH_RELEVANCE_EXPERIMENTAL_WORKBENCH_UI_EXPERIENCE_ENABLED } from '../common';

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

core.uiSettings.register({
[SEARCH_RELEVANCE_EXPERIMENTAL_WORKBENCH_UI_EXPERIENCE_ENABLED]: {
name: 'Experimental Search Relevance Workbench',
value: false,
description: 'Whether to opt-in the experimental search relevance workbench feature',
schema: schema.boolean(),
category: ['search relevance'],
},
});

const config: SearchRelevancePluginConfigType = await this.config$.pipe(first()).toPromise();

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

let opensearchSearchRelevanceClient: ILegacyClusterClient | undefined = undefined;
opensearchSearchRelevanceClient = core.opensearch.legacy.createClient(
'opensearch_search_relevance',
)
'opensearch_search_relevance'
);

// @ts-ignore
core.http.registerRouteHandlerContext('searchRelevance', (context, request) => {
Expand Down
Loading