2022-08-03 12:12:07 +00:00
|
|
|
import { useState } from "react";
|
2022-01-12 16:01:54 +00:00
|
|
|
import { DescriptionList } from "@patternfly/react-core";
|
2021-11-17 08:27:56 +00:00
|
|
|
|
|
|
|
import type ResourceServerRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceServerRepresentation";
|
2021-12-01 07:58:25 +00:00
|
|
|
import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinner";
|
2021-11-17 08:27:56 +00:00
|
|
|
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
2022-03-21 06:45:49 +00:00
|
|
|
import { DetailDescription, DetailDescriptionLink } from "./DetailDescription";
|
|
|
|
import { toScopeDetails } from "../routes/Scope";
|
|
|
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
|
|
|
import { toPermissionDetails } from "../routes/PermissionDetails";
|
2021-11-17 08:27:56 +00:00
|
|
|
|
|
|
|
import "./detail-cell.css";
|
|
|
|
|
|
|
|
type Scope = { id: string; name: string }[];
|
|
|
|
|
|
|
|
type DetailCellProps = {
|
|
|
|
id: string;
|
|
|
|
clientId: string;
|
|
|
|
uris?: string[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => {
|
2022-07-14 13:02:28 +00:00
|
|
|
const { adminClient } = useAdminClient();
|
2022-03-21 06:45:49 +00:00
|
|
|
const { realm } = useRealm();
|
2021-11-17 08:27:56 +00:00
|
|
|
const [scope, setScope] = useState<Scope>();
|
|
|
|
const [permissions, setPermissions] =
|
|
|
|
useState<ResourceServerRepresentation[]>();
|
|
|
|
|
|
|
|
useFetch(
|
|
|
|
() =>
|
|
|
|
Promise.all([
|
|
|
|
adminClient.clients.listScopesByResource({
|
|
|
|
id: clientId,
|
|
|
|
resourceName: id,
|
|
|
|
}),
|
|
|
|
adminClient.clients.listPermissionsByResource({
|
|
|
|
id: clientId,
|
|
|
|
resourceId: id,
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
([scopes, permissions]) => {
|
|
|
|
setScope(scopes);
|
|
|
|
setPermissions(permissions);
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
2021-12-01 07:58:25 +00:00
|
|
|
|
|
|
|
if (!permissions || !scope) {
|
|
|
|
return <KeycloakSpinner />;
|
|
|
|
}
|
|
|
|
|
2021-11-17 08:27:56 +00:00
|
|
|
return (
|
|
|
|
<DescriptionList isHorizontal className="keycloak_resource_details">
|
2022-01-12 16:01:54 +00:00
|
|
|
<DetailDescription name="uris" array={uris} />
|
2022-03-21 06:45:49 +00:00
|
|
|
<DetailDescriptionLink
|
|
|
|
name="scopes"
|
|
|
|
array={scope}
|
|
|
|
convert={(s) => s.name}
|
|
|
|
link={(scope) =>
|
|
|
|
toScopeDetails({ id: clientId, realm, scopeId: scope.id! })
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<DetailDescriptionLink
|
2022-01-12 16:01:54 +00:00
|
|
|
name="associatedPermissions"
|
|
|
|
array={permissions}
|
|
|
|
convert={(p) => p.name!}
|
2022-03-21 06:45:49 +00:00
|
|
|
link={(permission) =>
|
|
|
|
toPermissionDetails({
|
|
|
|
id: clientId,
|
|
|
|
realm,
|
|
|
|
permissionId: permission.id!,
|
|
|
|
permissionType: "resource",
|
|
|
|
})
|
|
|
|
}
|
2022-01-12 16:01:54 +00:00
|
|
|
/>
|
2021-11-17 08:27:56 +00:00
|
|
|
</DescriptionList>
|
|
|
|
);
|
|
|
|
};
|