Skip to content

Commit 14b3f90

Browse files
committed
change how frontend to read access
Signed-off-by: Fen Qin <[email protected]>
1 parent e4e3c4c commit 14b3f90

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

public/components/app.tsx

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -363,32 +363,42 @@ export const SearchRelevanceApp = ({
363363
const [toastRightSide, setToastRightSide] = useState<boolean>(true);
364364

365365
useEffect(() => {
366-
const fetchClusterSettings = async () => {
366+
const checkWorkbenchAccess = async () => {
367367
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);
368+
setIsLoading(true);
369+
// Try to fetch query sets as a test endpoint
370+
await http.get(ServiceEndpoints.QuerySets);
371+
// If we get here without error, the workbench is enabled
372+
setIsNewExperienceEnabled(true);
379373
} 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);
374+
if (error.response?.status === 404) {
375+
// 404 means the API is accessible but index doesn't exist yet
376+
setIsNewExperienceEnabled(true);
377+
} else if (
378+
error.response?.status === 403 &&
379+
error.body?.includes('Search Relevance Workbench is disabled')
380+
) {
381+
// 403 with specific message means the workbench is disabled
382+
setIsNewExperienceEnabled(false);
383+
notifications.toasts.addWarning({
384+
title: 'Search Relevance Workbench is disabled',
385+
text: 'Access to this feature is currently disabled.',
386+
toastLifeTimeMs: 5000,
387+
});
388+
} else {
389+
// For all other errors, keep the workbench enabled but show an error toast
390+
setIsNewExperienceEnabled(false);
391+
notifications.toasts.addError(error as Error, {
392+
title: 'Error occurred while accessing Search Relevance Workbench',
393+
toastLifeTimeMs: 5000,
394+
});
395+
}
386396
} finally {
387397
setIsLoading(false);
388398
}
389399
};
390400

391-
fetchClusterSettings();
401+
checkWorkbenchAccess();
392402
}, [http, notifications]);
393403

394404
if (isLoading) {

0 commit comments

Comments
 (0)