import React from 'react'; import PropTypes from 'prop-types'; import { getRightIcon, getWeightedPermissions, } from '../../../helpers/utils/permission'; import { useI18nContext } from '../../../hooks/useI18nContext'; /** * Get one or more permission descriptions for a permission name. * * @param permission - The permission to render. * @param index - The index of the permission. * @returns {JSX.Element} A permission description node. */ function getDescriptionNode(permission, index) { const { label, leftIcon, permissionName } = permission; return (
{typeof leftIcon === 'string' ? : leftIcon} {label} {getRightIcon(permission)}
); } export default function PermissionsConnectPermissionList({ permissions, targetSubjectMetadata, }) { const t = useI18nContext(); return (
{getWeightedPermissions(t, permissions, targetSubjectMetadata).map( getDescriptionNode, )}
); } PermissionsConnectPermissionList.propTypes = { permissions: PropTypes.object.isRequired, targetSubjectMetadata: PropTypes.object.isRequired, };