Use React Router v6 for the routable tabs of the user profile page (#4137)
This commit is contained in:
parent
bd2569b50d
commit
0d541f60b6
1 changed files with 15 additions and 16 deletions
|
@ -1,13 +1,15 @@
|
||||||
import { Tab, TabTitleText } from "@patternfly/react-core";
|
import { Tab, TabTitleText } from "@patternfly/react-core";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useHistory } from "react-router-dom";
|
|
||||||
import {
|
import {
|
||||||
routableTab,
|
|
||||||
RoutableTabs,
|
RoutableTabs,
|
||||||
|
useRoutableTab,
|
||||||
} from "../../components/routable-tabs/RoutableTabs";
|
} from "../../components/routable-tabs/RoutableTabs";
|
||||||
import { useRealm } from "../../context/realm-context/RealmContext";
|
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 { AttributesGroupTab } from "./AttributesGroupTab";
|
||||||
import { AttributesTab } from "./AttributesTab";
|
import { AttributesTab } from "./AttributesTab";
|
||||||
import { JsonEditorTab } from "./JsonEditorTab";
|
import { JsonEditorTab } from "./JsonEditorTab";
|
||||||
|
@ -16,7 +18,13 @@ import { UserProfileProvider } from "./UserProfileContext";
|
||||||
export const UserProfileTab = () => {
|
export const UserProfileTab = () => {
|
||||||
const { realm } = useRealm();
|
const { realm } = useRealm();
|
||||||
const { t } = useTranslation("realm-settings");
|
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 (
|
return (
|
||||||
<UserProfileProvider>
|
<UserProfileProvider>
|
||||||
|
@ -27,30 +35,21 @@ export const UserProfileTab = () => {
|
||||||
<Tab
|
<Tab
|
||||||
title={<TabTitleText>{t("attributes")}</TabTitleText>}
|
title={<TabTitleText>{t("attributes")}</TabTitleText>}
|
||||||
data-testid="attributesTab"
|
data-testid="attributesTab"
|
||||||
{...routableTab({
|
{...attributesTab}
|
||||||
to: toUserProfile({ realm, tab: "attributes" }),
|
|
||||||
history,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
<AttributesTab />
|
<AttributesTab />
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab
|
<Tab
|
||||||
title={<TabTitleText>{t("attributesGroup")}</TabTitleText>}
|
title={<TabTitleText>{t("attributesGroup")}</TabTitleText>}
|
||||||
data-testid="attributesGroupTab"
|
data-testid="attributesGroupTab"
|
||||||
{...routableTab({
|
{...attributesGroupTab}
|
||||||
to: toUserProfile({ realm, tab: "attributes-group" }),
|
|
||||||
history,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
<AttributesGroupTab />
|
<AttributesGroupTab />
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab
|
<Tab
|
||||||
title={<TabTitleText>{t("jsonEditor")}</TabTitleText>}
|
title={<TabTitleText>{t("jsonEditor")}</TabTitleText>}
|
||||||
data-testid="jsonEditorTab"
|
data-testid="jsonEditorTab"
|
||||||
{...routableTab({
|
{...jsonEditorTab}
|
||||||
to: toUserProfile({ realm, tab: "json-editor" }),
|
|
||||||
history,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
<JsonEditorTab />
|
<JsonEditorTab />
|
||||||
</Tab>
|
</Tab>
|
||||||
|
|
Loading…
Reference in a new issue