Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apis Page Reload Fix #110

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/v0.0.37/api-page-reload-env-var-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
- type: NEW_FEATURE
description: >-
Fixes the API page reload behavior when navigating to it with `VITE_API_PAGE_RELOAD=true`,
so that the React Router behavior is overridden in that case.
18 changes: 14 additions & 4 deletions projects/ui/src/Components/Structure/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useContext, useMemo } from "react";
import { MouseEventHandler, useContext, useMemo } from "react";
import { Link, NavLink, useLocation } from "react-router-dom";
import { ReactComponent as Logo } from "../../Assets/logo.svg";
import { AppContext } from "../../Context/AppContext";
import { AuthContext } from "../../Context/AuthContext";
import {apiPageReload, logoImageURL} from "../../user_variables.tmplr";
import { apiPageReload, logoImageURL } from "../../user_variables.tmplr";
import { ErrorBoundary } from "../Common/ErrorBoundary";
import { HeaderStyles } from "./Header.style";
import HeaderSectionLoggedIn from "./HeaderSectionLoggedIn";
Expand All @@ -17,6 +17,17 @@ if (!window.isSecureContext) {
);
}

// If apiPageReload is true use the onclick to reload the page
export const onApisPageClick: MouseEventHandler<HTMLAnchorElement> | undefined =
apiPageReload === "true"
? (e) => {
// If we are using `apiPageReload=true`, we want to override the react router
// behavior here, otherwise we get 2 `/apis` page history entries.
e.preventDefault();
window.location.href = "/apis";
}
: undefined;

/**
* MAIN COMPONENT
**/
Expand Down Expand Up @@ -89,8 +100,7 @@ export function Header() {
*/}
<NavLink
to={"/apis"}
// if apiPageReload is true use the onclick to reload the page
onClick={apiPageReload === "true" ? () => (window.location.href = "/apis") : undefined}
onClick={onApisPageClick}
className={`navLink ${inAPIsArea ? "active" : ""}`}
>
APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Link, NavLink, useLocation } from "react-router-dom";
import { ReactComponent as Logo } from "../../../Assets/logo.svg";
import { AppContext } from "../../../Context/AppContext";
import { ErrorBoundary } from "../../Common/ErrorBoundary";
import { onApisPageClick } from "../Header";
import { HeaderStyles } from "../Header.style";
import { OidcAuthCodeHeaderDropdown } from "./OidcAuthCodeHeaderDropdown";
import {apiPageReload} from "../../../user_variables.tmplr";

/**
* This is for when there is an
Expand Down Expand Up @@ -37,7 +37,7 @@ const OidcAuthCodeHeaderVariant = () => {
</NavLink>
<NavLink
to={"/apis"}
onClick={apiPageReload === "true" ? () => (window.location.href = "/apis") : undefined}
onClick={onApisPageClick}
className={`navLink ${inAPIsArea ? "active" : ""}`}
>
APIs
Expand Down
Loading