fix: redirect old logs routes to new routes (#4584)

This commit is contained in:
Yunus M 2024-02-22 16:57:06 +05:30 committed by GitHub
parent f3bc1a8f8a
commit f2d5d21581
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 9 deletions

View File

@ -20,11 +20,16 @@ import { UPDATE_USER_IS_FETCH } from 'types/actions/app';
import AppReducer from 'types/reducer/app'; import AppReducer from 'types/reducer/app';
import { routePermission } from 'utils/permission'; import { routePermission } from 'utils/permission';
import routes, { LIST_LICENSES } from './routes'; import routes, {
LIST_LICENSES,
oldNewRoutesMapping,
oldRoutes,
} from './routes';
import afterLogin from './utils'; import afterLogin from './utils';
function PrivateRoute({ children }: PrivateRouteProps): JSX.Element { function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
const { pathname } = useLocation(); const location = useLocation();
const { pathname } = location;
const mapRoutes = useMemo( const mapRoutes = useMemo(
() => () =>
@ -59,6 +64,8 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
const currentRoute = mapRoutes.get('current'); const currentRoute = mapRoutes.get('current');
const isOldRoute = oldRoutes.indexOf(pathname) > -1;
const isLocalStorageLoggedIn = const isLocalStorageLoggedIn =
getLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN) === 'true'; getLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN) === 'true';
@ -158,6 +165,16 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
useEffect(() => { useEffect(() => {
(async (): Promise<void> => { (async (): Promise<void> => {
try { try {
if (isOldRoute) {
const redirectUrl = oldNewRoutesMapping[pathname];
const newLocation = {
...location,
pathname: redirectUrl,
};
history.replace(newLocation);
}
if (currentRoute) { if (currentRoute) {
const { isPrivate, key } = currentRoute; const { isPrivate, key } = currentRoute;

View File

@ -279,6 +279,13 @@ const routes: AppRoutes[] = [
key: 'LIVE_LOGS', key: 'LIVE_LOGS',
isPrivate: true, isPrivate: true,
}, },
{
path: ROUTES.LOGS_PIPELINES,
exact: true,
component: PipelinePage,
key: 'LOGS_PIPELINES',
isPrivate: true,
},
{ {
path: ROUTES.LOGIN, path: ROUTES.LOGIN,
exact: true, exact: true,
@ -307,13 +314,6 @@ const routes: AppRoutes[] = [
key: 'SOMETHING_WENT_WRONG', key: 'SOMETHING_WENT_WRONG',
isPrivate: false, isPrivate: false,
}, },
{
path: ROUTES.LOGS_PIPELINES,
exact: true,
component: PipelinePage,
key: 'LOGS_PIPELINES',
isPrivate: true,
},
{ {
path: ROUTES.BILLING, path: ROUTES.BILLING,
exact: true, exact: true,
@ -353,6 +353,20 @@ export const LIST_LICENSES: AppRoutes = {
key: 'LIST_LICENSES', 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 { export interface AppRoutes {
component: RouteProps['component']; component: RouteProps['component'];
path: RouteProps['path']; path: RouteProps['path'];