Convert detail tab text to links (#2277)
* convert to link * changed to be link to details fixes: #2039
This commit is contained in:
parent
73958176f5
commit
51aba823ef
5 changed files with 82 additions and 13 deletions
|
@ -4,7 +4,10 @@ import { DescriptionList } from "@patternfly/react-core";
|
||||||
import type ResourceServerRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceServerRepresentation";
|
import type ResourceServerRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceServerRepresentation";
|
||||||
import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinner";
|
import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinner";
|
||||||
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
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";
|
import "./detail-cell.css";
|
||||||
|
|
||||||
|
@ -18,6 +21,7 @@ type DetailCellProps = {
|
||||||
|
|
||||||
export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => {
|
export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => {
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
|
const { realm } = useRealm();
|
||||||
const [scope, setScope] = useState<Scope>();
|
const [scope, setScope] = useState<Scope>();
|
||||||
const [permissions, setPermissions] =
|
const [permissions, setPermissions] =
|
||||||
useState<ResourceServerRepresentation[]>();
|
useState<ResourceServerRepresentation[]>();
|
||||||
|
@ -48,11 +52,26 @@ export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => {
|
||||||
return (
|
return (
|
||||||
<DescriptionList isHorizontal className="keycloak_resource_details">
|
<DescriptionList isHorizontal className="keycloak_resource_details">
|
||||||
<DetailDescription name="uris" array={uris} />
|
<DetailDescription name="uris" array={uris} />
|
||||||
<DetailDescription name="scopes" array={scope} convert={(s) => s.name} />
|
<DetailDescriptionLink
|
||||||
<DetailDescription
|
name="scopes"
|
||||||
|
array={scope}
|
||||||
|
convert={(s) => s.name}
|
||||||
|
link={(scope) =>
|
||||||
|
toScopeDetails({ id: clientId, realm, scopeId: scope.id! })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<DetailDescriptionLink
|
||||||
name="associatedPermissions"
|
name="associatedPermissions"
|
||||||
array={permissions}
|
array={permissions}
|
||||||
convert={(p) => p.name!}
|
convert={(p) => p.name!}
|
||||||
|
link={(permission) =>
|
||||||
|
toPermissionDetails({
|
||||||
|
id: clientId,
|
||||||
|
realm,
|
||||||
|
permissionId: permission.id!,
|
||||||
|
permissionType: "resource",
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</DescriptionList>
|
</DescriptionList>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
import type { LocationDescriptor } from "history";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
DescriptionListGroup,
|
DescriptionListGroup,
|
||||||
|
@ -12,11 +14,20 @@ type DetailDescriptionProps<T> = {
|
||||||
convert?: (obj: T) => string;
|
convert?: (obj: T) => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function DetailDescription<T>({
|
export function DetailDescription<T>(props: DetailDescriptionProps<T>) {
|
||||||
|
return <DetailDescriptionLink {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
type DetailDescriptionLinkProps<T> = DetailDescriptionProps<T> & {
|
||||||
|
link?: (element: T) => LocationDescriptor;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function DetailDescriptionLink<T>({
|
||||||
name,
|
name,
|
||||||
array,
|
array,
|
||||||
convert,
|
convert,
|
||||||
}: DetailDescriptionProps<T>) {
|
link,
|
||||||
|
}: DetailDescriptionLinkProps<T>) {
|
||||||
const { t } = useTranslation("clients");
|
const { t } = useTranslation("clients");
|
||||||
return (
|
return (
|
||||||
<DescriptionListGroup>
|
<DescriptionListGroup>
|
||||||
|
@ -25,7 +36,11 @@ export function DetailDescription<T>({
|
||||||
{array?.map((element) => {
|
{array?.map((element) => {
|
||||||
const value =
|
const value =
|
||||||
typeof element === "string" ? element : convert!(element);
|
typeof element === "string" ? element : convert!(element);
|
||||||
return (
|
return link ? (
|
||||||
|
<Link key={value} to={link(element as T)} className="pf-u-pr-sm">
|
||||||
|
{value}
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
<span key={value} className="pf-u-pr-sm">
|
<span key={value} className="pf-u-pr-sm">
|
||||||
{value}
|
{value}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -32,13 +32,14 @@ import useToggle from "../../utils/useToggle";
|
||||||
import { useRealm } from "../../context/realm-context/RealmContext";
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
||||||
import { SearchDropdown, SearchForm } from "./SearchDropdown";
|
import { SearchDropdown, SearchForm } from "./SearchDropdown";
|
||||||
import { MoreLabel } from "./MoreLabel";
|
import { MoreLabel } from "./MoreLabel";
|
||||||
import { DetailDescription } from "./DetailDescription";
|
import { DetailDescriptionLink } from "./DetailDescription";
|
||||||
import { EmptyPermissionsState } from "./EmptyPermissionsState";
|
import { EmptyPermissionsState } from "./EmptyPermissionsState";
|
||||||
import { toNewPermission } from "../routes/NewPermission";
|
import { toNewPermission } from "../routes/NewPermission";
|
||||||
import { toPermissionDetails } from "../routes/PermissionDetails";
|
import { toPermissionDetails } from "../routes/PermissionDetails";
|
||||||
import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState";
|
import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState";
|
||||||
|
|
||||||
import "./permissions.css";
|
import "./permissions.css";
|
||||||
|
import { toPolicyDetails } from "../routes/PolicyDetails";
|
||||||
|
|
||||||
type PermissionsProps = {
|
type PermissionsProps = {
|
||||||
clientId: string;
|
clientId: string;
|
||||||
|
@ -324,10 +325,18 @@ export const AuthorizationPermissions = ({ clientId }: PermissionsProps) => {
|
||||||
isHorizontal
|
isHorizontal
|
||||||
className="keycloak_resource_details"
|
className="keycloak_resource_details"
|
||||||
>
|
>
|
||||||
<DetailDescription
|
<DetailDescriptionLink
|
||||||
name="associatedPolicy"
|
name="associatedPolicy"
|
||||||
array={permission.associatedPolicies}
|
array={permission.associatedPolicies}
|
||||||
convert={(p) => p.name!}
|
convert={(p) => p.name!}
|
||||||
|
link={(p) =>
|
||||||
|
toPolicyDetails({
|
||||||
|
id: clientId,
|
||||||
|
realm,
|
||||||
|
policyId: p.id!,
|
||||||
|
policyType: p.type!,
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</DescriptionList>
|
</DescriptionList>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -34,8 +34,9 @@ import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState
|
||||||
import useToggle from "../../utils/useToggle";
|
import useToggle from "../../utils/useToggle";
|
||||||
import { NewPolicyDialog } from "./NewPolicyDialog";
|
import { NewPolicyDialog } from "./NewPolicyDialog";
|
||||||
import { toCreatePolicy } from "../routes/NewPolicy";
|
import { toCreatePolicy } from "../routes/NewPolicy";
|
||||||
import { DetailDescription } from "./DetailDescription";
|
import { toPermissionDetails } from "../routes/PermissionDetails";
|
||||||
import { SearchDropdown, SearchForm } from "./SearchDropdown";
|
import { SearchDropdown, SearchForm } from "./SearchDropdown";
|
||||||
|
import { DetailDescriptionLink } from "./DetailDescription";
|
||||||
|
|
||||||
type PoliciesProps = {
|
type PoliciesProps = {
|
||||||
clientId: string;
|
clientId: string;
|
||||||
|
@ -278,10 +279,18 @@ export const AuthorizationPolicies = ({ clientId }: PoliciesProps) => {
|
||||||
isHorizontal
|
isHorizontal
|
||||||
className="keycloak_resource_details"
|
className="keycloak_resource_details"
|
||||||
>
|
>
|
||||||
<DetailDescription
|
<DetailDescriptionLink
|
||||||
name="dependentPermission"
|
name="dependentPermission"
|
||||||
array={policy.dependentPolicies}
|
array={policy.dependentPolicies}
|
||||||
convert={(p) => p.name!}
|
convert={(p) => p.name!}
|
||||||
|
link={(permission) =>
|
||||||
|
toPermissionDetails({
|
||||||
|
realm,
|
||||||
|
id: clientId,
|
||||||
|
permissionId: permission.id!,
|
||||||
|
permissionType: permission.type!,
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</DescriptionList>
|
</DescriptionList>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -30,8 +30,10 @@ import { toNewScope } from "../routes/NewScope";
|
||||||
import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState";
|
import { ListEmptyState } from "../../components/list-empty-state/ListEmptyState";
|
||||||
import useToggle from "../../utils/useToggle";
|
import useToggle from "../../utils/useToggle";
|
||||||
import { DeleteScopeDialog } from "./DeleteScopeDialog";
|
import { DeleteScopeDialog } from "./DeleteScopeDialog";
|
||||||
import { DetailDescription } from "./DetailDescription";
|
import { DetailDescriptionLink } from "./DetailDescription";
|
||||||
import { toNewPermission } from "../routes/NewPermission";
|
import { toNewPermission } from "../routes/NewPermission";
|
||||||
|
import { toResourceDetails } from "../routes/Resource";
|
||||||
|
import { toPermissionDetails } from "../routes/PermissionDetails";
|
||||||
|
|
||||||
type ScopesProps = {
|
type ScopesProps = {
|
||||||
clientId: string;
|
clientId: string;
|
||||||
|
@ -251,15 +253,30 @@ export const AuthorizationScopes = ({ clientId }: ScopesProps) => {
|
||||||
isHorizontal
|
isHorizontal
|
||||||
className="keycloak_resource_details"
|
className="keycloak_resource_details"
|
||||||
>
|
>
|
||||||
<DetailDescription
|
<DetailDescriptionLink
|
||||||
name="resources"
|
name="resources"
|
||||||
array={scope.resources}
|
array={scope.resources}
|
||||||
convert={(r) => r.name!}
|
convert={(r) => r.name!}
|
||||||
|
link={(r) =>
|
||||||
|
toResourceDetails({
|
||||||
|
id: clientId,
|
||||||
|
realm,
|
||||||
|
resourceId: r._id!,
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<DetailDescription
|
<DetailDescriptionLink
|
||||||
name="associatedPermissions"
|
name="associatedPermissions"
|
||||||
array={scope.permissions}
|
array={scope.permissions}
|
||||||
convert={(p) => p.name!}
|
convert={(p) => p.name!}
|
||||||
|
link={(p) =>
|
||||||
|
toPermissionDetails({
|
||||||
|
id: clientId,
|
||||||
|
realm,
|
||||||
|
permissionId: p.id!,
|
||||||
|
permissionType: p.type!,
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</DescriptionList>
|
</DescriptionList>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in a new issue