0bbd4ddad1
* Initial version of the create and edit resouce screen * refactored and fixed the attributes form introduced a new component that can be used more easily * Update src/components/json-file-upload/FileUploadForm.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/components/attribute-form/attribute-convert.ts Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/clients/authorization/ResourceDetails.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/clients/authorization/ResourceDetails.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * Update src/clients/authorization/ResourceDetails.tsx Co-authored-by: Jon Koops <jonkoops@gmail.com> * PR review * fixed tests * PR review comments * resourceId is optional * Update src/components/attribute-form/attribute-convert.ts Co-authored-by: Jon Koops <jonkoops@gmail.com> Co-authored-by: Jon Koops <jonkoops@gmail.com>
91 lines
2.7 KiB
TypeScript
91 lines
2.7 KiB
TypeScript
import React, { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import {
|
|
DescriptionList,
|
|
DescriptionListGroup,
|
|
DescriptionListTerm,
|
|
DescriptionListDescription,
|
|
} 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 "./detail-cell.css";
|
|
|
|
type Scope = { id: string; name: string }[];
|
|
|
|
type DetailCellProps = {
|
|
id: string;
|
|
clientId: string;
|
|
uris?: string[];
|
|
};
|
|
|
|
export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => {
|
|
const { t } = useTranslation("clients");
|
|
const adminClient = useAdminClient();
|
|
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);
|
|
},
|
|
[]
|
|
);
|
|
|
|
if (!permissions || !scope) {
|
|
return <KeycloakSpinner />;
|
|
}
|
|
|
|
return (
|
|
<DescriptionList isHorizontal className="keycloak_resource_details">
|
|
<DescriptionListGroup>
|
|
<DescriptionListTerm>{t("uris")}</DescriptionListTerm>
|
|
<DescriptionListDescription>
|
|
{uris?.map((uri) => (
|
|
<span key={uri} className="pf-u-pr-sm">
|
|
{uri}
|
|
</span>
|
|
))}
|
|
{uris?.length === 0 && <i>{t("common:none")}</i>}
|
|
</DescriptionListDescription>
|
|
</DescriptionListGroup>
|
|
<DescriptionListGroup>
|
|
<DescriptionListTerm>{t("scopes")}</DescriptionListTerm>
|
|
<DescriptionListDescription>
|
|
{scope.map((scope) => (
|
|
<span key={scope.id} className="pf-u-pr-sm">
|
|
{scope.name}
|
|
</span>
|
|
))}
|
|
{scope.length === 0 && <i>{t("common:none")}</i>}
|
|
</DescriptionListDescription>
|
|
</DescriptionListGroup>
|
|
<DescriptionListGroup>
|
|
<DescriptionListTerm>{t("associatedPermissions")}</DescriptionListTerm>
|
|
<DescriptionListDescription>
|
|
{permissions.map((permission) => (
|
|
<span key={permission.id} className="pf-u-pr-sm">
|
|
{permission.name}
|
|
</span>
|
|
))}
|
|
{permissions.length === 0 && <i>{t("common:none")}</i>}
|
|
</DescriptionListDescription>
|
|
</DescriptionListGroup>
|
|
</DescriptionList>
|
|
);
|
|
};
|