Skip to content
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

Remote auth fix #7263

Merged
merged 1 commit into from
Nov 28, 2024
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
27 changes: 15 additions & 12 deletions designer/client/src/components/RemoteComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useMemo } from "react";
import LoaderSpinner from "./spinner/Spinner";
import { FederatedComponent, FederatedComponentProps, getFederatedComponentLoader } from "@touk/federated-component";
import { NuThemeProvider } from "../containers/theme/nuThemeProvider";
import React, { useMemo } from "react";
import SystemUtils from "../common/SystemUtils";
import { NuThemeProvider } from "../containers/theme/nuThemeProvider";
import { useWindows, WindowKind } from "../windowManager";
import LoaderSpinner from "./spinner/Spinner";

export const loadExternalReactModule = getFederatedComponentLoader({ Wrapper: NuThemeProvider });
export const loadExternalReactModuleWithAuth = getFederatedComponentLoader({
Expand All @@ -14,6 +14,17 @@ export const loadExternalReactModuleWithAuth = getFederatedComponentLoader({
window["loadExternalReactModule"] = loadExternalReactModule;
window["loadExternalReactModuleWithAuth"] = loadExternalReactModuleWithAuth;

function PlainRemoteComponentRender<P extends NonNullable<unknown>, T = unknown>(
props: FederatedComponentProps<P>,
ref: React.ForwardedRef<T>,
) {
return <FederatedComponent<P, T> ref={ref} {...props} fallback={<LoaderSpinner show={true} />} buildHash={__BUILD_HASH__} />;
}

export const PlainRemoteComponent = React.forwardRef(PlainRemoteComponentRender) as <P extends NonNullable<unknown>, T = unknown>(
props: FederatedComponentProps<P> & React.RefAttributes<T>,
) => React.ReactElement;

export type RemoteToolbarContentProps = {
openRemoteModuleWindow: <P extends NonNullable<unknown>>(props: P & { url?: string; title?: string }) => void;
};
Expand All @@ -32,15 +43,7 @@ function RemoteComponentRender<P extends NonNullable<unknown>, T = unknown>(prop
[open],
);

return (
<FederatedComponent<P, T>
ref={ref}
{...sharedContext}
{...props}
fallback={<LoaderSpinner show={true} />}
buildHash={__BUILD_HASH__}
/>
);
return <PlainRemoteComponent<P, T> ref={ref} {...sharedContext} {...props} />;
}

export const RemoteComponent = React.forwardRef(RemoteComponentRender) as <P extends NonNullable<unknown>, T = unknown>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { FunctionComponent, PropsWithChildren } from "react";
import { PendingPromise } from "../../../../common/PendingPromise";
import SystemUtils from "../../../../common/SystemUtils";
import { ErrorBoundary } from "../../../../components/common/error-boundary";
import { RemoteComponent } from "../../../../components/RemoteComponent";
import { PlainRemoteComponent } from "../../../../components/RemoteComponent";
import { RemoteAuthenticationSettings } from "../../../../reducers/settings";
import { AuthErrorCodes } from "../../AuthErrorCodes";
import { Strategy, StrategyConstructor } from "../../Strategy";
Expand All @@ -18,9 +18,9 @@ function createAuthWrapper(url: ModuleUrl, onInit: AuthLibCallback): FunctionCom
return function Wrapper({ children }: PropsWithChildren<unknown>) {
return (
<ErrorBoundary>
<RemoteComponent<RemoteAuthProviderProps> url={url} onInit={onInit}>
<PlainRemoteComponent<RemoteAuthProviderProps> url={url} onInit={onInit}>
{children}
</RemoteComponent>
</PlainRemoteComponent>
</ErrorBoundary>
);
};
Expand Down
10 changes: 9 additions & 1 deletion designer/client/src/windowManager/useWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ const useRemoveFocusOnEscKey = (isWindowOpen: boolean) => {
};

export function useWindows(parent?: WindowId) {
const { open: _open, closeAll, windows } = useWindowManager(parent);
let windowManager: ReturnType<typeof useWindowManager>;

try {
windowManager = useWindowManager(parent);
} catch (e) {
throw "used outside WindowManager context";
}

const { open: _open, closeAll, windows } = windowManager;
useRemoveFocusOnEscKey(windows.length > 0);
const [settings] = useUserSettings();
const forceDisableModals = useMemo(() => settings["debug.forceDisableModals"], [settings]);
Expand Down
Loading