Skip to content

Commit

Permalink
NCL-8899 Add announcement redirect to old UI when React UI is set as …
Browse files Browse the repository at this point in the history
…primary UI
  • Loading branch information
DnsZhou authored and matedo1 committed Nov 12, 2024
1 parent 2e8f760 commit e906e7a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { DropdownLinkItem } from 'components/Dropdown/DropdownLinkItem';
import { ExperimentalContent } from 'components/ExperimentalContent/ExperimentalContent';
import { ExperimentalContentMarker } from 'components/ExperimentalContent/ExperimentalContentMarker';
import { ProtectedComponent } from 'components/ProtectedContent/ProtectedComponent';
import { OldUIAnnouncement } from 'components/TopBar/OldUIAnnouncement';
import { TopBarAnnouncement } from 'components/TopBar/TopBarAnnouncement';

import { IAuthBroadcastMessage, authBroadcastService } from 'services/broadcastService';
Expand Down Expand Up @@ -131,6 +132,11 @@ export const AppLayout = () => {
<ProtectedComponent role={AUTH_ROLE.Admin} hide key="administration">
<DropdownLinkItem to="/admin/administration">Administration</DropdownLinkItem>
</ProtectedComponent>
{process.env.REACT_APP_PNC_OLD_UI_WEB && (
<DropdownLinkItem key="old-ui" to={process.env.REACT_APP_PNC_OLD_UI_WEB}>
Old UI Version
</DropdownLinkItem>
)}
</>
);

Expand Down Expand Up @@ -358,6 +364,7 @@ export const AppLayout = () => {
return (
<>
<div ref={topBarsRef}>
<OldUIAnnouncement />
{serviceContainerPncStatus.data && (
<TopBarAnnouncement
id="site-top-bar"
Expand Down
47 changes: 47 additions & 0 deletions src/components/TopBar/OldUIAnnouncement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Alert, AlertActionCloseButton, AlertVariant } from '@patternfly/react-core';
import { ApplicationsIcon, ArrowIcon } from '@patternfly/react-icons';

import { useStorage } from 'hooks/useStorage';

const URL_TRIGGER = 'secondary';
const LOCAL_STORAGE_KEY = 'old-ui-announcement-closed';

export const OldUIAnnouncement = () => {
const { storageValue: isClosed, storeToStorage: setIsClosed } = useStorage<boolean>({
storageKey: LOCAL_STORAGE_KEY,
initialValue: false,
});

const oldUIUrl = process.env.REACT_APP_PNC_OLD_UI_WEB;

//Display announcement when oldUIUrl is configured and current host name does not contain keyword
const shouldDisplay = !!oldUIUrl && !window.location.hostname.toLowerCase().includes(URL_TRIGGER);

if (!shouldDisplay || isClosed) {
return null;
}

const closeAnnouncement = () => {
setIsClosed(true);
};

return (
<Alert
id="old-ui-announcement-bar"
variant={AlertVariant.custom}
actionClose={<AlertActionCloseButton onClose={closeAnnouncement} />}
aria-label="Old UI Announcement"
customIcon={<ApplicationsIcon />}
title={
<>
Welcome to the new PNC Web UI. The{' '}
<a href={oldUIUrl} target="_blank" rel="noopener noreferrer">
Old UI Version <ArrowIcon />
</a>{' '}
is temporarily available, but it will soon be decommissioned.
</>
}
isInline
/>
);
};

0 comments on commit e906e7a

Please sign in to comment.