Skip to content

Commit

Permalink
NCL-8833 Implement backwards compatibility for AngularJS URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
DnsZhou committed Nov 18, 2024
1 parent a170330 commit 4604dc5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { StorageKeys, useStorage } from 'hooks/useStorage';
import { DropdownLinkItem } from 'components/Dropdown/DropdownLinkItem';
import { ExperimentalContent } from 'components/ExperimentalContent/ExperimentalContent';
import { ExperimentalContentMarker } from 'components/ExperimentalContent/ExperimentalContentMarker';
import LegacyUrlRedirector from 'components/OldUrlRedirector/LegacyUrlRedirector';
import { ProtectedComponent } from 'components/ProtectedContent/ProtectedComponent';
import { OldUIAnnouncement } from 'components/TopBar/OldUIAnnouncement';
import { TopBarAnnouncement } from 'components/TopBar/TopBarAnnouncement';
Expand Down Expand Up @@ -363,6 +364,7 @@ export const AppLayout = () => {

return (
<>
<LegacyUrlRedirector />
<div ref={topBarsRef}>
<OldUIAnnouncement />
{serviceContainerPncStatus.data && (
Expand Down
32 changes: 32 additions & 0 deletions src/components/OldUrlRedirector/LegacyUrlRedirector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

const LegacyUrlRedirector = () => {
const navigate = useNavigate();

useEffect(() => {
const { pathname, hash } = window.location;

if (pathname.startsWith('/pnc-web/') && hash.startsWith('#/')) {
let newPath = '/' + hash.substring(2); // Remove '#/' and concatenate

// If it contains '/build-configs/', remove everything between '/pnc-web/' and '/build-configs/'
const buildConfigsIndex = newPath.indexOf('/build-configs/');
if (buildConfigsIndex !== -1) {
newPath = newPath.substring(buildConfigsIndex);
}

// If it contains '/builds/', remove everything between '/pnc-web/' and '/builds/'
const buildsIndex = newPath.indexOf('/builds/');
if (buildsIndex !== -1) {
newPath = newPath.substring(buildsIndex);
}

navigate(newPath, { replace: true });
}
}, [navigate]);

return null;
};

export default LegacyUrlRedirector;

0 comments on commit 4604dc5

Please sign in to comment.