mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-29 01:15:48 +02:00
Fix/last viewed project (#2530)
<!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> Fix using projectId on redirect. Fix: only redirect to project(s) on app load ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
1fec43947d
commit
1eb0116e11
@ -30,7 +30,7 @@ const AUTH_PASSWORD = Cypress.env('AUTH_PASSWORD');
|
||||
Cypress.Commands.add('login', (user = AUTH_USER, password = AUTH_PASSWORD) =>
|
||||
cy.session(user, () => {
|
||||
cy.visit('/');
|
||||
cy.wait(1000);
|
||||
cy.wait(1500);
|
||||
cy.get("[data-testid='LOGIN_EMAIL_ID']").type(user);
|
||||
|
||||
if (AUTH_PASSWORD) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Suspense } from 'react';
|
||||
import { Suspense, useCallback, useEffect, useState } from 'react';
|
||||
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||
import { ErrorBoundary } from 'react-error-boundary';
|
||||
import { Error } from 'component/layout/Error/Error';
|
||||
@ -17,14 +17,48 @@ import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
||||
import { SplashPageRedirect } from 'component/splash/SplashPageRedirect/SplashPageRedirect';
|
||||
import { useStyles } from './App.styles';
|
||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||
import useProjects from '../hooks/api/getters/useProjects/useProjects';
|
||||
import { useLastViewedProject } from '../hooks/useLastViewedProject';
|
||||
|
||||
const InitialRedirect = () => {
|
||||
const { lastViewed } = useLastViewedProject();
|
||||
const { projects, loading } = useProjects();
|
||||
|
||||
const [redirectTo, setRedirectTo] = useState<string | undefined>();
|
||||
|
||||
const getRedirect = useCallback(() => {
|
||||
if (projects && lastViewed) {
|
||||
return `/projects/${lastViewed}`;
|
||||
}
|
||||
|
||||
if (projects && !lastViewed && projects.length === 1) {
|
||||
return `/projects/${projects[0].id}`;
|
||||
}
|
||||
|
||||
return '/projects';
|
||||
}, [lastViewed, projects]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
setRedirectTo(getRedirect());
|
||||
}
|
||||
}, [loading, getRedirect]);
|
||||
|
||||
if (loading || !redirectTo) {
|
||||
return <Loader />;
|
||||
}
|
||||
|
||||
return <Navigate to={redirectTo} />;
|
||||
};
|
||||
|
||||
export const App = () => {
|
||||
const { classes: styles } = useStyles();
|
||||
const { authDetails } = useAuthDetails();
|
||||
const { user } = useAuthUser();
|
||||
const { isOss } = useUiConfig();
|
||||
const hasFetchedAuth = Boolean(authDetails || user);
|
||||
|
||||
const { classes: styles } = useStyles();
|
||||
const { isOss } = useUiConfig();
|
||||
|
||||
const availableRoutes = isOss()
|
||||
? routes.filter(route => !route.enterprise)
|
||||
: routes;
|
||||
@ -38,44 +72,41 @@ export const App = () => {
|
||||
condition={!hasFetchedAuth}
|
||||
show={<Loader />}
|
||||
elseShow={
|
||||
<div className={styles.container}>
|
||||
<ToastRenderer />
|
||||
<Routes>
|
||||
{availableRoutes.map(route => (
|
||||
<Route
|
||||
key={route.path}
|
||||
path={route.path}
|
||||
element={
|
||||
<LayoutPicker
|
||||
isStandalone={
|
||||
route.isStandalone ===
|
||||
true
|
||||
}
|
||||
>
|
||||
<ProtectedRoute
|
||||
route={route}
|
||||
/>
|
||||
</LayoutPicker>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<Navigate
|
||||
to="/projects"
|
||||
replace
|
||||
<>
|
||||
<div className={styles.container}>
|
||||
<ToastRenderer />
|
||||
<Routes>
|
||||
{availableRoutes.map(route => (
|
||||
<Route
|
||||
key={route.path}
|
||||
path={route.path}
|
||||
element={
|
||||
<LayoutPicker
|
||||
isStandalone={
|
||||
route.isStandalone ===
|
||||
true
|
||||
}
|
||||
>
|
||||
<ProtectedRoute
|
||||
route={route}
|
||||
/>
|
||||
</LayoutPicker>
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="*"
|
||||
element={<NotFound />}
|
||||
/>
|
||||
</Routes>
|
||||
<FeedbackNPS openUrl="http://feedback.unleash.run" />
|
||||
<SplashPageRedirect />
|
||||
</div>
|
||||
))}
|
||||
<Route
|
||||
path="/"
|
||||
element={<InitialRedirect />}
|
||||
/>
|
||||
<Route
|
||||
path="*"
|
||||
element={<NotFound />}
|
||||
/>
|
||||
</Routes>
|
||||
<FeedbackNPS openUrl="http://feedback.unleash.run" />
|
||||
<SplashPageRedirect />
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</PlausibleProvider>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { Link, Navigate, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { mutate } from 'swr';
|
||||
import { getProjectFetcher } from 'hooks/api/getters/useProject/getProjectFetcher';
|
||||
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
||||
@ -152,10 +152,6 @@ export const ProjectListNew = () => {
|
||||
? `${filteredProjects.length} of ${projects.length}`
|
||||
: projects.length;
|
||||
|
||||
if (projects?.length === 1) {
|
||||
return <Navigate to={`/projects/${projects[0].id}`} replace />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={ref}>
|
||||
<PageContent
|
||||
|
@ -9,22 +9,15 @@ import Authentication from '../Authentication/Authentication';
|
||||
import { useAuthDetails } from 'hooks/api/getters/useAuth/useAuthDetails';
|
||||
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
||||
import { parseRedirectParam } from 'component/user/Login/parseRedirectParam';
|
||||
import { useLastViewedProject } from '../../../hooks/useLastViewedProject';
|
||||
|
||||
const Login = () => {
|
||||
const { classes: styles } = useStyles();
|
||||
const { authDetails } = useAuthDetails();
|
||||
const { user } = useAuthUser();
|
||||
const { lastViewed } = useLastViewedProject();
|
||||
const query = useQueryParams();
|
||||
const resetPassword = query.get('reset') === 'true';
|
||||
const invited = query.get('invited') === 'true';
|
||||
|
||||
const getRedirect = () => {
|
||||
return lastViewed == null ? '/projects' : `/projects/${lastViewed}`;
|
||||
};
|
||||
|
||||
const redirect = query.get('redirect') || getRedirect();
|
||||
const redirect = query.get('redirect') || '/';
|
||||
|
||||
if (user) {
|
||||
return <Navigate to={parseRedirectParam(redirect)} replace />;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { setLocalStorageItem, getLocalStorageItem } from '../utils/storage';
|
||||
import { getLocalStorageItem, setLocalStorageItem } from '../utils/storage';
|
||||
import useUiConfig from './api/getters/useUiConfig/useUiConfig';
|
||||
|
||||
export const useLastViewedProject = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user