Use React Router v6 for the routable tabs of the user profile page (#4137)

This commit is contained in:
Jon Koops 2023-01-06 14:30:17 +01:00 committed by GitHub
parent bd2569b50d
commit 0d541f60b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,13 +1,15 @@
import { Tab, TabTitleText } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import {
routableTab,
RoutableTabs,
useRoutableTab,
} from "../../components/routable-tabs/RoutableTabs";
import { useRealm } from "../../context/realm-context/RealmContext";
import { toUserProfile } from "../routes/UserProfile";
import {
toUserProfile,
UserProfileTab as IUserProfileTab,
} from "../routes/UserProfile";
import { AttributesGroupTab } from "./AttributesGroupTab";
import { AttributesTab } from "./AttributesTab";
import { JsonEditorTab } from "./JsonEditorTab";
@ -16,7 +18,13 @@ import { UserProfileProvider } from "./UserProfileContext";
export const UserProfileTab = () => {
const { realm } = useRealm();
const { t } = useTranslation("realm-settings");
const history = useHistory();
const useTab = (tab: IUserProfileTab) =>
useRoutableTab(toUserProfile({ realm, tab }));
const attributesTab = useTab("attributes");
const attributesGroupTab = useTab("attributes-group");
const jsonEditorTab = useTab("json-editor");
return (
<UserProfileProvider>
@ -27,30 +35,21 @@ export const UserProfileTab = () => {
<Tab
title={<TabTitleText>{t("attributes")}</TabTitleText>}
data-testid="attributesTab"
{...routableTab({
to: toUserProfile({ realm, tab: "attributes" }),
history,
})}
{...attributesTab}
>
<AttributesTab />
</Tab>
<Tab
title={<TabTitleText>{t("attributesGroup")}</TabTitleText>}
data-testid="attributesGroupTab"
{...routableTab({
to: toUserProfile({ realm, tab: "attributes-group" }),
history,
})}
{...attributesGroupTab}
>
<AttributesGroupTab />
</Tab>
<Tab
title={<TabTitleText>{t("jsonEditor")}</TabTitleText>}
data-testid="jsonEditorTab"
{...routableTab({
to: toUserProfile({ realm, tab: "json-editor" }),
history,
})}
{...jsonEditorTab}
>
<JsonEditorTab />
</Tab>