Add referrer link (#19799)

Closes #19682
This commit is contained in:
Erik Jan de Wit 2023-05-02 11:58:56 +02:00 committed by GitHub
parent f497f8cd8f
commit eab11255ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View file

@ -11,6 +11,7 @@
"applicationsIntroMessage": "Track and manage your app permission to access your account", "applicationsIntroMessage": "Track and manage your app permission to access your account",
"applicationType": "Application type", "applicationType": "Application type",
"avatar": "Avatar", "avatar": "Avatar",
"backTo": "Back to {{app}}",
"basic-authentication": "Basic authentication", "basic-authentication": "Basic authentication",
"cancel": "Cancel", "cancel": "Cancel",
"choose": "Choose...", "choose": "Choose...",

View file

@ -1,4 +1,4 @@
import { Page, Spinner } from "@patternfly/react-core"; import { Button, Page, Spinner } from "@patternfly/react-core";
import { import {
KeycloakMasthead, KeycloakMasthead,
Translations, Translations,
@ -13,11 +13,31 @@ import { environment } from "../environment";
import { keycloak } from "../keycloak"; import { keycloak } from "../keycloak";
import { joinPath } from "../utils/joinPath"; import { joinPath } from "../utils/joinPath";
import { PageNav } from "./PageNav"; import { PageNav } from "./PageNav";
import { ExternalLinkSquareAltIcon } from "@patternfly/react-icons";
import style from "./Root.module.css"; import style from "./Root.module.css";
const ReferrerLink = () => {
const { t } = useTranslation();
const searchParams = new URLSearchParams(location.search);
return searchParams.has("referrer_uri") ? (
<Button
component="a"
href={searchParams.get("referrer_uri")!.replace("_hash_", "#")}
variant="link"
icon={<ExternalLinkSquareAltIcon />}
iconPosition="right"
isInline
>
{t("backTo", { app: searchParams.get("referrer") })}
</Button>
) : null;
};
export const Root = () => { export const Root = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const translations = useMemo<Translations>( const translations = useMemo<Translations>(
() => ({ () => ({
avatar: t("avatar"), avatar: t("avatar"),
@ -41,7 +61,7 @@ export const Root = () => {
alt: t("logo"), alt: t("logo"),
className: style.brand, className: style.brand,
}} }}
dropdownItems={[]} toolbarItems={[<ReferrerLink key="link" />]}
keycloak={keycloak} keycloak={keycloak}
/> />
</TranslationsProvider> </TranslationsProvider>

View file

@ -32,7 +32,8 @@ type KeycloakMastheadProps = PageHeaderProps & {
}; };
keycloak?: Keycloak; keycloak?: Keycloak;
kebabDropdownItems?: ReactNode[]; kebabDropdownItems?: ReactNode[];
dropdownItems: ReactNode[]; dropdownItems?: ReactNode[];
toolbarItems?: ReactNode[];
}; };
const KeycloakMasthead = ({ const KeycloakMasthead = ({
@ -45,7 +46,8 @@ const KeycloakMasthead = ({
} = {}, } = {},
keycloak, keycloak,
kebabDropdownItems, kebabDropdownItems,
dropdownItems, dropdownItems = [],
toolbarItems,
...rest ...rest
}: KeycloakMastheadProps) => { }: KeycloakMastheadProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
@ -94,6 +96,7 @@ const KeycloakMasthead = ({
]} ]}
/> />
</PageHeaderToolsItem> </PageHeaderToolsItem>
<PageHeaderToolsItem>{toolbarItems}</PageHeaderToolsItem>
<PageHeaderToolsItem <PageHeaderToolsItem
visibility={{ visibility={{
default: "hidden", default: "hidden",