diff --git a/apps/admin-ui/src/clients/ClientDetails.tsx b/apps/admin-ui/src/clients/ClientDetails.tsx index c84ecab59d..c2aa92915e 100644 --- a/apps/admin-ui/src/clients/ClientDetails.tsx +++ b/apps/admin-ui/src/clients/ClientDetails.tsx @@ -20,7 +20,6 @@ import { useWatch, } from "react-hook-form-v7"; import { useTranslation } from "react-i18next"; -import { useHistory } from "react-router-dom"; import { useNavigate } from "react-router-dom-v5-compat"; import { useAlerts } from "../components/alert/Alerts"; @@ -33,8 +32,8 @@ import type { KeyValueType } from "../components/key-value-form/key-value-conver import { KeycloakSpinner } from "../components/keycloak-spinner/KeycloakSpinner"; import { PermissionsTab } from "../components/permission-tab/PermissionTab"; import { - routableTab, RoutableTabs, + useRoutableTab, } from "../components/routable-tabs/RoutableTabs"; import { ViewHeader, @@ -72,7 +71,7 @@ import { } from "./routes/AuthenticationTab"; import { ClientParams, ClientTab, toClient } from "./routes/Client"; import { toClients } from "./routes/Clients"; -import { toClientScopesTab } from "./routes/ClientScopeTab"; +import { ClientScopesTab, toClientScopesTab } from "./routes/ClientScopeTab"; import { ClientScopes } from "./scopes/ClientScopes"; import { EvaluateScopes } from "./scopes/EvaluateScopes"; import { ServiceAccount } from "./service-account/ServiceAccount"; @@ -204,7 +203,6 @@ export default function ClientDetails() { const hasManageClients = hasAccess("manage-clients"); const hasViewUsers = hasAccess("view-users"); - const history = useHistory(); const navigate = useNavigate(); const [downloadDialogOpen, toggleDownloadDialogOpen] = useToggle(); @@ -227,6 +225,55 @@ export default function ClientDetails() { return sortBy(roles, (role) => role.name?.toUpperCase()); }; + const useTab = (tab: ClientTab) => + useRoutableTab( + toClient({ + realm, + clientId, + tab, + }) + ); + + const settingsTab = useTab("settings"); + const keysTab = useTab("keys"); + const credentialsTab = useTab("credentials"); + const rolesTab = useTab("roles"); + const clientScopesTab = useTab("clientScopes"); + const authorizationTab = useTab("authorization"); + const serviceAccountTab = useTab("serviceAccount"); + const sessionsTab = useTab("sessions"); + const permissionsTab = useTab("permissions"); + const advancedTab = useTab("advanced"); + + const useClientScopesTab = (tab: ClientScopesTab) => + useRoutableTab( + toClientScopesTab({ + realm, + clientId, + tab, + }) + ); + + const clientScopesSetupTab = useClientScopesTab("setup"); + const clientScopesEvaluateTab = useClientScopesTab("evaluate"); + + const useAuthorizationTab = (tab: AuthorizationTab) => + useRoutableTab( + toAuthorizationTab({ + realm, + clientId, + tab, + }) + ); + + const authorizationSettingsTab = useAuthorizationTab("settings"); + const authorizationResourcesTab = useAuthorizationTab("resources"); + const authorizationScopesTab = useAuthorizationTab("scopes"); + const authorizationPoliciesTab = useAuthorizationTab("policies"); + const authorizationPermissionsTab = useAuthorizationTab("permissions"); + const authorizationEvaluateTab = useAuthorizationTab("evaluate"); + const authorizationExportTab = useAuthorizationTab("export"); + const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: "clients:clientDeleteConfirmTitle", messageKey: "clients:clientDeleteConfirm", @@ -324,26 +371,6 @@ export default function ClientDetails() { return ; } - const route = (tab: ClientTab) => - routableTab({ - to: toClient({ - realm, - clientId, - tab, - }), - history, - }); - - const authenticationRoute = (tab: AuthorizationTab) => - routableTab({ - to: toAuthorizationTab({ - realm, - clientId, - tab, - }), - history, - }); - return ( <> {t("common:settings")}} - {...route("settings")} + {...settingsTab} > {t("keys")}} - {...route("keys")} + {...keysTab} > {client.protocol === "openid-connect" && ( {t("credentials")}} - {...route("credentials")} + {...credentialsTab} > {t("roles")}} - {...route("roles")} + {...rolesTab} > {t("clientScopes")}} - {...route("clientScopes")} + {...clientScopesTab} > {t("setup")}} - {...routableTab({ - to: toClientScopesTab({ - realm, - clientId, - tab: "setup", - }), - history, - })} + {...clientScopesSetupTab} > {t("evaluate")}} - {...routableTab({ - to: toClientScopesTab({ - realm, - clientId, - tab: "evaluate", - }), - history, - })} + {...clientScopesEvaluateTab} > {t("authorization")}} - {...route("authorization")} + {...authorizationTab} > {t("settings")}} - {...authenticationRoute("settings")} + {...authorizationSettingsTab} > @@ -531,7 +544,7 @@ export default function ClientDetails() { id="resources" data-testid="authorizationResources" title={{t("resources")}} - {...authenticationRoute("resources")} + {...authorizationResourcesTab} > @@ -539,7 +552,7 @@ export default function ClientDetails() { id="scopes" data-testid="authorizationScopes" title={{t("scopes")}} - {...authenticationRoute("scopes")} + {...authorizationScopesTab} > @@ -547,7 +560,7 @@ export default function ClientDetails() { id="policies" data-testid="authorizationPolicies" title={{t("policies")}} - {...authenticationRoute("policies")} + {...authorizationPoliciesTab} > @@ -557,7 +570,7 @@ export default function ClientDetails() { title={ {t("common:permissions")} } - {...authenticationRoute("permissions")} + {...authorizationPermissionsTab} > @@ -565,7 +578,7 @@ export default function ClientDetails() { id="evaluate" data-testid="authorizationEvaluate" title={{t("evaluate")}} - {...authenticationRoute("evaluate")} + {...authorizationEvaluateTab} > @@ -573,7 +586,7 @@ export default function ClientDetails() { id="export" data-testid="authorizationExport" title={{t("common:export")}} - {...authenticationRoute("export")} + {...authorizationExportTab} > @@ -585,7 +598,7 @@ export default function ClientDetails() { id="serviceAccount" data-testid="serviceAccountTab" title={{t("serviceAccount")}} - {...route("serviceAccount")} + {...serviceAccountTab} > @@ -594,7 +607,7 @@ export default function ClientDetails() { id="sessions" data-testid="sessionsTab" title={{t("sessions")}} - {...route("sessions")} + {...sessionsTab} > @@ -604,7 +617,7 @@ export default function ClientDetails() { id="permissions" data-testid="permissionsTab" title={{t("common:permissions")}} - {...route("permissions")} + {...permissionsTab} > @@ -613,7 +626,7 @@ export default function ClientDetails() { id="advanced" data-testid="advancedTab" title={{t("advanced")}} - {...route("advanced")} + {...advancedTab} >