Skip to content

ARTESCA-14759: Fix Flaky UI E2E Tests Due to Local Storage redirectUrl Handling #4543

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

Open
wants to merge 1 commit into
base: development/130.0
Choose a base branch
from
Open
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
47 changes: 20 additions & 27 deletions shell-ui/src/FederatedApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ import {
FederatedComponentProps,
SolutionUI,
} from '@scality/module-federation';
import React, {
useEffect,
useLayoutEffect,
useMemo,
useTransition,
useRef,
useState,
} from 'react';
import React, { useEffect, useMemo } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { QueryClient } from 'react-query';
import { BrowserRouter, Route, Routes, useLocation } from 'react-router';
import { BrowserRouter, Route, Routes } from 'react-router';

import { loadShare } from '@module-federation/enhanced/runtime';
import { useQuery } from 'react-query';
Expand Down Expand Up @@ -242,23 +235,21 @@ function InternalApp() {
});

return (
<BrowserRouter>
<ShellHistoryProvider>
<FirstTimeLoginProvider>
<NotificationCenterProvider>
{(status === 'idle' || status === 'loading') && (
<Loader size="massive" centered={true} aria-label="loading" />
)}
{status === 'error' && <ErrorPage500 data-cy="sc-error-page500" />}
{status === 'success' && (
<SolutionsNavbar>
<InternalRouter />
</SolutionsNavbar>
)}
</NotificationCenterProvider>
</FirstTimeLoginProvider>
</ShellHistoryProvider>
</BrowserRouter>
<ShellHistoryProvider>
<FirstTimeLoginProvider>
<NotificationCenterProvider>
{(status === 'idle' || status === 'loading') && (
<Loader size="massive" centered={true} aria-label="loading" />
)}
{status === 'error' && <ErrorPage500 data-cy="sc-error-page500" />}
{status === 'success' && (
<SolutionsNavbar>
<InternalRouter />
</SolutionsNavbar>
)}
</NotificationCenterProvider>
</FirstTimeLoginProvider>
</ShellHistoryProvider>
);
}

Expand All @@ -272,7 +263,9 @@ export function WithInitFederationProviders({
<UIListProvider discoveryURL={shellConfig.discoveryUrl}>
<ConfigurationProvider>
<AuthConfigProvider>
<AuthProvider>{children}</AuthProvider>
<BrowserRouter>
<AuthProvider>{children}</AuthProvider>
</BrowserRouter>
</AuthConfigProvider>
</ConfigurationProvider>
</UIListProvider>
Expand Down
13 changes: 6 additions & 7 deletions shell-ui/src/auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
import { useShellConfig } from '../initFederation/ShellConfigProvider';
import { getUserGroups } from '../navbar/auth/permissionUtils';
import { useAuthConfig } from './AuthConfigProvider';
import { useNavigate } from 'react-router-dom';
export function AuthProvider({ children }: { children: React.ReactNode }) {
const { authConfig } = useAuthConfig();

Expand Down Expand Up @@ -101,6 +102,7 @@ function OAuth2AuthProvider({ children }: { children: React.ReactNode }) {
});
};
const { logOut } = useInternalLogout(userManager, authConfig);
const navigate = useNavigate();
//Force logout on silent renewal error
useEffect(() => {
const onSilentRenewError = (err) => {
Expand All @@ -125,15 +127,12 @@ function OAuth2AuthProvider({ children }: { children: React.ReactNode }) {
}, [logOut]);
const oidcConfig: AuthProviderProps = {
onBeforeSignIn: () => {
localStorage.setItem('redirectUrl', window.location.href);
return window.location.href;
return location.pathname + location.search + location.hash;
},
onSignIn: () => {
const savedRedirectUri = localStorage.getItem('redirectUrl');
localStorage.removeItem('redirectUrl');

onSignIn: (userData) => {
const savedRedirectUri = userData.state;
if (savedRedirectUri) {
location.href = savedRedirectUri;
navigate(savedRedirectUri);
} else {
const searchParams = new URLSearchParams(location.search);
searchParams.delete('state');
Expand Down
12 changes: 5 additions & 7 deletions shell-ui/src/navbar/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ export const wrapper = ({ children }) => {
<LanguageProvider>
<NotificationCenterProvider>
<WithInitFederationProviders>
<MemoryRouter>
<FirstTimeLoginProvider>
<ShellHistoryProvider>
<SolutionsNavbar>{children}</SolutionsNavbar>
</ShellHistoryProvider>
</FirstTimeLoginProvider>
</MemoryRouter>
<FirstTimeLoginProvider>
<ShellHistoryProvider>
<SolutionsNavbar>{children}</SolutionsNavbar>
</ShellHistoryProvider>
</FirstTimeLoginProvider>
</WithInitFederationProviders>
</NotificationCenterProvider>
</LanguageProvider>
Expand Down
Loading