From 2c4805fe50187e8185658731cc51fec11ace1751 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Wed, 4 Jan 2023 11:33:43 +0100 Subject: [PATCH] Use React Router v6 for the routable tabs of clients page (#4123) --- apps/admin-ui/src/clients/ClientsSection.tsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/admin-ui/src/clients/ClientsSection.tsx b/apps/admin-ui/src/clients/ClientsSection.tsx index 1fa3fc1672..7199f2290a 100644 --- a/apps/admin-ui/src/clients/ClientsSection.tsx +++ b/apps/admin-ui/src/clients/ClientsSection.tsx @@ -13,7 +13,6 @@ import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/ import type { ClientQuery } from "@keycloak/keycloak-admin-client/lib/resources/clients"; import { useState } from "react"; import { useTranslation } from "react-i18next"; -import { useHistory } from "react-router-dom"; import { Link } from "react-router-dom-v5-compat"; import { useAlerts } from "../components/alert/Alerts"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; @@ -35,8 +34,8 @@ import { isRealmClient, getProtocolName } from "./utils"; import helpUrls from "../help-urls"; import { useAccess } from "../context/access/Access"; import { - routableTab, RoutableTabs, + useRoutableTab, } from "../components/routable-tabs/RoutableTabs"; import { ClientsTab, toClients } from "./routes/Clients"; @@ -46,7 +45,6 @@ export default function ClientsSection() { const { adminClient } = useAdminClient(); const { realm } = useRealm(); - const history = useHistory(); const [key, setKey] = useState(0); const refresh = () => setKey(new Date().getTime()); @@ -67,6 +65,11 @@ export default function ClientsSection() { return await adminClient.clients.find({ ...params }); }; + const useTab = (tab: ClientsTab) => useRoutableTab(toClients({ realm, tab })); + + const listTab = useTab("list"); + const initialAccessTokenTab = useTab("initial-access-token"); + const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: t("clientDelete", { clientId: selectedClient?.clientId }), messageKey: "clients:clientDeleteConfirm", @@ -140,12 +143,6 @@ export default function ClientsSection() { ); }; - const route = (tab: ClientsTab) => - routableTab({ - to: toClients({ realm, tab }), - history, - }); - return ( <> {t("clientsList")}} - {...route("list")} + {...listTab} > {t("initialAccessToken")}} - {...route("initial-access-token")} + {...initialAccessTokenTab} >