Use React Router v6 for the routable tabs of the realm settings keys page (#4129)

This commit is contained in:
Jon Koops 2023-01-05 13:08:14 +01:00 committed by GitHub
parent d2163efe3f
commit 0b7ab7d008
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,4 @@
import { useState } from "react";
import { useHistory } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Tab, TabTitleText } from "@patternfly/react-core";
@ -8,8 +7,8 @@ import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
import { useRealm } from "../../context/realm-context/RealmContext";
import { KEY_PROVIDER_TYPE } from "../../util";
import {
routableTab,
RoutableTabs,
useRoutableTab,
} from "../../components/routable-tabs/RoutableTabs";
import { KeySubTab, toKeysTab } from "../routes/KeysTab";
import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinner";
@ -31,7 +30,6 @@ const sortByPriority = (components: ComponentRepresentation[]) => {
export const KeysTab = () => {
const { t } = useTranslation("realm-settings");
const history = useHistory();
const { adminClient } = useAdminClient();
const { realm: realmName } = useRealm();
@ -53,16 +51,16 @@ export const KeysTab = () => {
[key]
);
const useTab = (tab: KeySubTab) =>
useRoutableTab(toKeysTab({ realm: realmName, tab }));
const listTab = useTab("list");
const providersTab = useTab("providers");
if (!realmComponents) {
return <KeycloakSpinner />;
}
const keysRoute = (tab: KeySubTab) =>
routableTab({
to: toKeysTab({ realm: realmName, tab }),
history,
});
return (
<RoutableTabs
mountOnEnter
@ -74,7 +72,7 @@ export const KeysTab = () => {
data-testid="rs-keys-list-tab"
aria-label="keys-list-subtab"
title={<TabTitleText>{t("keysList")}</TabTitleText>}
{...keysRoute("list")}
{...listTab}
>
<KeysListTab realmComponents={realmComponents} />
</Tab>
@ -83,7 +81,7 @@ export const KeysTab = () => {
data-testid="rs-providers-tab"
aria-label="rs-providers-tab"
title={<TabTitleText>{t("providers")}</TabTitleText>}
{...keysRoute("providers")}
{...providersTab}
>
<KeysProvidersTab realmComponents={realmComponents} refresh={refresh} />
</Tab>