From 51aba823efb0da604f97f5cca3d0f6ed0580e1ca Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 21 Mar 2022 07:45:49 +0100 Subject: [PATCH] Convert detail tab text to links (#2277) * convert to link * changed to be link to details fixes: #2039 --- src/clients/authorization/DetailCell.tsx | 25 ++++++++++++++++--- .../authorization/DetailDescription.tsx | 21 +++++++++++++--- src/clients/authorization/Permissions.tsx | 13 ++++++++-- src/clients/authorization/Policies.tsx | 13 ++++++++-- src/clients/authorization/Scopes.tsx | 23 ++++++++++++++--- 5 files changed, 82 insertions(+), 13 deletions(-) diff --git a/src/clients/authorization/DetailCell.tsx b/src/clients/authorization/DetailCell.tsx index 9224dd8bb6..6d657af86b 100644 --- a/src/clients/authorization/DetailCell.tsx +++ b/src/clients/authorization/DetailCell.tsx @@ -4,7 +4,10 @@ import { DescriptionList } from "@patternfly/react-core"; import type ResourceServerRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceServerRepresentation"; import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinner"; import { useAdminClient, useFetch } from "../../context/auth/AdminClient"; -import { DetailDescription } from "./DetailDescription"; +import { DetailDescription, DetailDescriptionLink } from "./DetailDescription"; +import { toScopeDetails } from "../routes/Scope"; +import { useRealm } from "../../context/realm-context/RealmContext"; +import { toPermissionDetails } from "../routes/PermissionDetails"; import "./detail-cell.css"; @@ -18,6 +21,7 @@ type DetailCellProps = { export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => { const adminClient = useAdminClient(); + const { realm } = useRealm(); const [scope, setScope] = useState(); const [permissions, setPermissions] = useState(); @@ -48,11 +52,26 @@ export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => { return ( - s.name} /> - s.name} + link={(scope) => + toScopeDetails({ id: clientId, realm, scopeId: scope.id! }) + } + /> + p.name!} + link={(permission) => + toPermissionDetails({ + id: clientId, + realm, + permissionId: permission.id!, + permissionType: "resource", + }) + } /> ); diff --git a/src/clients/authorization/DetailDescription.tsx b/src/clients/authorization/DetailDescription.tsx index 9e4f65c42a..7dbc673e95 100644 --- a/src/clients/authorization/DetailDescription.tsx +++ b/src/clients/authorization/DetailDescription.tsx @@ -1,4 +1,6 @@ import React from "react"; +import { Link } from "react-router-dom"; +import type { LocationDescriptor } from "history"; import { useTranslation } from "react-i18next"; import { DescriptionListGroup, @@ -12,11 +14,20 @@ type DetailDescriptionProps = { convert?: (obj: T) => string; }; -export function DetailDescription({ +export function DetailDescription(props: DetailDescriptionProps) { + return ; +} + +type DetailDescriptionLinkProps = DetailDescriptionProps & { + link?: (element: T) => LocationDescriptor; +}; + +export function DetailDescriptionLink({ name, array, convert, -}: DetailDescriptionProps) { + link, +}: DetailDescriptionLinkProps) { const { t } = useTranslation("clients"); return ( @@ -25,7 +36,11 @@ export function DetailDescription({ {array?.map((element) => { const value = typeof element === "string" ? element : convert!(element); - return ( + return link ? ( + + {value} + + ) : ( {value} diff --git a/src/clients/authorization/Permissions.tsx b/src/clients/authorization/Permissions.tsx index e22a8c7753..d685174ed4 100644 --- a/src/clients/authorization/Permissions.tsx +++ b/src/clients/authorization/Permissions.tsx @@ -32,13 +32,14 @@ import useToggle from "../../utils/useToggle"; import { useRealm } from "../../context/realm-context/RealmContext"; import { SearchDropdown, SearchForm } from "./SearchDropdown"; import { MoreLabel } from "./MoreLabel"; -import { DetailDescription } from "./DetailDescription"; +import { DetailDescriptionLink } from "./DetailDescription"; import { EmptyPermissionsState } from "./EmptyPermissionsState"; import { toNewPermission } from "../routes/NewPermission"; import { toPermissionDetails } from "../routes/PermissionDetails"; import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState"; import "./permissions.css"; +import { toPolicyDetails } from "../routes/PolicyDetails"; type PermissionsProps = { clientId: string; @@ -324,10 +325,18 @@ export const AuthorizationPermissions = ({ clientId }: PermissionsProps) => { isHorizontal className="keycloak_resource_details" > - p.name!} + link={(p) => + toPolicyDetails({ + id: clientId, + realm, + policyId: p.id!, + policyType: p.type!, + }) + } /> )} diff --git a/src/clients/authorization/Policies.tsx b/src/clients/authorization/Policies.tsx index e9cc4c0ef4..781973e2e8 100644 --- a/src/clients/authorization/Policies.tsx +++ b/src/clients/authorization/Policies.tsx @@ -34,8 +34,9 @@ import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState import useToggle from "../../utils/useToggle"; import { NewPolicyDialog } from "./NewPolicyDialog"; import { toCreatePolicy } from "../routes/NewPolicy"; -import { DetailDescription } from "./DetailDescription"; +import { toPermissionDetails } from "../routes/PermissionDetails"; import { SearchDropdown, SearchForm } from "./SearchDropdown"; +import { DetailDescriptionLink } from "./DetailDescription"; type PoliciesProps = { clientId: string; @@ -278,10 +279,18 @@ export const AuthorizationPolicies = ({ clientId }: PoliciesProps) => { isHorizontal className="keycloak_resource_details" > - p.name!} + link={(permission) => + toPermissionDetails({ + realm, + id: clientId, + permissionId: permission.id!, + permissionType: permission.type!, + }) + } /> )} diff --git a/src/clients/authorization/Scopes.tsx b/src/clients/authorization/Scopes.tsx index 7dd056781e..65c04385b6 100644 --- a/src/clients/authorization/Scopes.tsx +++ b/src/clients/authorization/Scopes.tsx @@ -30,8 +30,10 @@ import { toNewScope } from "../routes/NewScope"; import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState"; import useToggle from "../../utils/useToggle"; import { DeleteScopeDialog } from "./DeleteScopeDialog"; -import { DetailDescription } from "./DetailDescription"; +import { DetailDescriptionLink } from "./DetailDescription"; import { toNewPermission } from "../routes/NewPermission"; +import { toResourceDetails } from "../routes/Resource"; +import { toPermissionDetails } from "../routes/PermissionDetails"; type ScopesProps = { clientId: string; @@ -251,15 +253,30 @@ export const AuthorizationScopes = ({ clientId }: ScopesProps) => { isHorizontal className="keycloak_resource_details" > - r.name!} + link={(r) => + toResourceDetails({ + id: clientId, + realm, + resourceId: r._id!, + }) + } /> - p.name!} + link={(p) => + toPermissionDetails({ + id: clientId, + realm, + permissionId: p.id!, + permissionType: p.type!, + }) + } /> )}