Skip to content

Commit

Permalink
feat(ui/assertion-ux): move new routes constant to global.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-apptware committed Jul 19, 2024
1 parent 5cbaf44 commit 8719eda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 4 additions & 10 deletions datahub-web-react/src/app/ProtectedRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@ import { Layout } from 'antd';
import { HomePage } from './home/HomePage';
import { SearchRoutes } from './SearchRoutes';
import EmbedRoutes from './EmbedRoutes';
import { PageRoutes } from '../conf/Global';
import { getRedirectUrl } from './shared/utils';
import { NEW_ROUTE_MAP, PageRoutes } from '../conf/Global';
import { getRedirectUrl } from '../conf/utils';

/**
* Container for all views behind an authentication wall.
*/
export const ProtectedRoutes = (): JSX.Element => {
export const ProtectedRoutes = (): JSX.Element => {
const location = useLocation();
const history = useHistory();

useEffect(() => {
if (location.pathname.indexOf('/Validation') !== -1) {
const newRoutes = {
'/Validation/Assertions': '/Quality/List',
'/Validation/Tests': '/Governance/Tests',
'/Validation/Data%20Contract': '/Quality/Data%20Contract',
'/Validation': '/Quality',
};
history.replace(getRedirectUrl(newRoutes));
history.replace(getRedirectUrl(NEW_ROUTE_MAP));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location]);
Expand Down
8 changes: 8 additions & 0 deletions datahub-web-react/src/conf/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ export const CLIENT_AUTH_COOKIE = 'actor';
* Name of the unique browser id cookie generated on client side
*/
export const BROWSER_ID_COOKIE = 'bid';

/** New Routes Map for redirection */
export const NEW_ROUTE_MAP = {
'/Validation/Assertions': '/Quality/List',
'/Validation/Tests': '/Governance/Tests',
'/Validation/Data%20Contract': '/Quality/Data%20Contract',
'/Validation': '/Quality',
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
}
* */

export const getRedirectUrl = (newRoutes: any) => {
export const getRedirectUrl = (newRoutes: { [key: string]: string }) => {
let newPathname = `${window.location.pathname}${window.location.search}`;
if (!newRoutes) {
return newPathname;
}

// eslint-disable-next-line no-restricted-syntax
for (const path of Object.keys(newRoutes)) {
if (newPathname.indexOf(path) !== -1) {
Expand Down

0 comments on commit 8719eda

Please sign in to comment.