Sidecar: Always hide at /login page (#96621)

This commit is contained in:
Sven Grossmann 2024-11-18 13:07:59 +01:00 committed by GitHub
parent 1915efbc95
commit 2ff9baa271
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,12 +1,15 @@
import { createContext, useContext } from 'react';
import { useObservable } from 'react-use';
import { locationService as mainLocationService } from './LocationService';
import { SidecarService_EXPERIMENTAL, sidecarServiceSingleton_EXPERIMENTAL } from './SidecarService_EXPERIMENTAL';
export const SidecarContext_EXPERIMENTAL = createContext<SidecarService_EXPERIMENTAL>(
sidecarServiceSingleton_EXPERIMENTAL
);
const HIDDEN_ROUTES = ['/login'];
/**
* This is the main way to interact with the sidecar service inside a react context. It provides a wrapper around the
* service props so that even though they are observables we just pass actual values to the components.
@ -24,17 +27,33 @@ export function useSidecar_EXPERIMENTAL() {
const initialContext = useObservable(service.initialContextObservable, service.initialContext);
const activePluginId = useObservable(service.activePluginIdObservable, service.activePluginId);
const locationService = service.getLocationService();
const forceHidden = HIDDEN_ROUTES.includes(mainLocationService.getLocation().pathname);
return {
activePluginId,
initialContext,
activePluginId: forceHidden ? undefined : activePluginId,
initialContext: forceHidden ? undefined : initialContext,
locationService,
// TODO: currently this allows anybody to open any app, in the future we should probably scope this to the
// current app but that means we will need to incorporate this better into the plugin platform APIs which
// we will do once the functionality is reasonably stable
openApp: (pluginId: string, context?: unknown) => service.openApp(pluginId, context),
openAppV2: (pluginId: string, path?: string) => service.openAppV2(pluginId, path),
openApp: (pluginId: string, context?: unknown) => {
if (forceHidden) {
return;
}
return service.openApp(pluginId, context);
},
openAppV2: (pluginId: string, path?: string) => {
if (forceHidden) {
return;
}
return service.openAppV2(pluginId, path);
},
closeApp: () => service.closeApp(),
isAppOpened: (pluginId: string) => service.isAppOpened(pluginId),
isAppOpened: (pluginId: string) => {
if (forceHidden) {
return false;
}
return service.isAppOpened(pluginId);
},
};
}