Skip to content

Commit

Permalink
Merge pull request #915 from US-Trustee-Program/CAMS-428-case-detail-…
Browse files Browse the repository at this point in the history
…accessibility-fritz-exp

Exp - always take user back to original tab
  • Loading branch information
fmaddenflx authored Sep 17, 2024
2 parents 89687e9 + 1696b1f commit 7c153b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions user-interface/src/case-detail/panels/CaseDetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function CaseDetailHeader(props: CaseDetailHeaderProps) {
const appEl = document.querySelector('.App');
const camsHeader = document.querySelector('.cams-header');

const { previousLocation } = useLocationTracker();
const { previousLocation, homeTab } = useLocationTracker();

const modifyHeader = () => {
if (camsHeader) {
Expand Down Expand Up @@ -64,7 +64,7 @@ export default function CaseDetailHeader(props: CaseDetailHeaderProps) {
<div className="grid-row grid-gap-lg">
<div className="grid-col-1"></div>
<div className="grid-col-10">
<Link className="back-button" to={previousLocation}>
<Link className="back-button" to={previousLocation} target={homeTab}>
<Icon name="arrow_back"></Icon>
Back to {getBackLinkText()}
</Link>
Expand Down Expand Up @@ -117,7 +117,7 @@ export default function CaseDetailHeader(props: CaseDetailHeaderProps) {
<div className="grid-row grid-gap-lg">
<div className="grid-col-1"></div>
<div className="grid-col-10">
<Link className="back-button" to={previousLocation}>
<Link className="back-button" to={previousLocation} target={homeTab}>
<Icon name="arrow_back"></Icon>
Back to {getBackLinkText()}
</Link>
Expand Down
18 changes: 16 additions & 2 deletions user-interface/src/lib/hooks/UseLocationTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export default function useLocationTracker() {

return storedLocation && isValidPath(storedLocation) ? storedLocation : '/my-cases';
});
const [homeTab, setHomeTab] = useState<string>(() => {
const target = localStorage.getItem('homeTab');

return target ?? '';
});

const updateLocation = useCallback((newLocation?: string) => {
if (newLocation && isValidPath(newLocation)) {
Expand All @@ -23,14 +28,23 @@ export default function useLocationTracker() {
setPreviousLocation(pathLocation);
localStorage.setItem('previousLocation', pathLocation);
}
if (window.name.match(/^CAMS_WINDOW_[0-9]+/)) {
setHomeTab(window.name);
localStorage.setItem('homeTab', window.name);
}
}, []);

useEffect(() => {
const storedLocation = localStorage.getItem('previousLocation');
const storedTab = localStorage.getItem('homeTab');

if (storedLocation && isValidPath(storedLocation)) {
setPreviousLocation(storedLocation);
}
});
if (storedTab && storedTab.length > 0) {
setHomeTab(storedTab);
}
}, []);

return { previousLocation, updateLocation };
return { previousLocation, homeTab, updateLocation };
}
2 changes: 2 additions & 0 deletions user-interface/src/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export function Login(props: LoginProps): React.ReactNode {
}
}

window.name = `CAMS_WINDOW_${Math.floor(Date.now() / 1000)}`;

let providerComponent;
switch (provider) {
case 'okta':
Expand Down

0 comments on commit 7c153b7

Please sign in to comment.