Skip to content

Commit

Permalink
fix: redirect old logs routes to new routes (#4584)
Browse files Browse the repository at this point in the history
  • Loading branch information
YounixM committed Feb 22, 2024
1 parent f3bc1a8 commit f2d5d21
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
21 changes: 19 additions & 2 deletions frontend/src/AppRoutes/Private.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ import { UPDATE_USER_IS_FETCH } from 'types/actions/app';
import AppReducer from 'types/reducer/app';
import { routePermission } from 'utils/permission';

import routes, { LIST_LICENSES } from './routes';
import routes, {
LIST_LICENSES,
oldNewRoutesMapping,
oldRoutes,
} from './routes';
import afterLogin from './utils';

function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
const { pathname } = useLocation();
const location = useLocation();
const { pathname } = location;

const mapRoutes = useMemo(
() =>
Expand Down Expand Up @@ -59,6 +64,8 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {

const currentRoute = mapRoutes.get('current');

const isOldRoute = oldRoutes.indexOf(pathname) > -1;

const isLocalStorageLoggedIn =
getLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN) === 'true';

Expand Down Expand Up @@ -158,6 +165,16 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
useEffect(() => {
(async (): Promise<void> => {
try {
if (isOldRoute) {
const redirectUrl = oldNewRoutesMapping[pathname];

const newLocation = {
...location,
pathname: redirectUrl,
};
history.replace(newLocation);
}

if (currentRoute) {
const { isPrivate, key } = currentRoute;

Expand Down
28 changes: 21 additions & 7 deletions frontend/src/AppRoutes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ const routes: AppRoutes[] = [
key: 'LIVE_LOGS',
isPrivate: true,
},
{
path: ROUTES.LOGS_PIPELINES,
exact: true,
component: PipelinePage,
key: 'LOGS_PIPELINES',
isPrivate: true,
},
{
path: ROUTES.LOGIN,
exact: true,
Expand Down Expand Up @@ -307,13 +314,6 @@ const routes: AppRoutes[] = [
key: 'SOMETHING_WENT_WRONG',
isPrivate: false,
},
{
path: ROUTES.LOGS_PIPELINES,
exact: true,
component: PipelinePage,
key: 'LOGS_PIPELINES',
isPrivate: true,
},
{
path: ROUTES.BILLING,
exact: true,
Expand Down Expand Up @@ -353,6 +353,20 @@ export const LIST_LICENSES: AppRoutes = {
key: 'LIST_LICENSES',
};

export const oldRoutes = [
'/pipelines',
'/logs/old-logs-explorer',
'/logs-explorer',
'/logs-explorer/live',
];

export const oldNewRoutesMapping: Record<string, string> = {
'/pipelines': '/logs/pipelines',
'/logs/old-logs-explorer': '/logs/old-logs-explorer',
'/logs-explorer': '/logs/logs-explorer',
'/logs-explorer/live': '/logs/logs-explorer/live',
};

export interface AppRoutes {
component: RouteProps['component'];
path: RouteProps['path'];
Expand Down

0 comments on commit f2d5d21

Please sign in to comment.