import React from 'react'; import PropTypes from 'prop-types'; import { getPermissionDescription } from '../../../helpers/utils/permission'; import { useI18nContext } from '../../../hooks/useI18nContext'; /** * Get one or more permission descriptions for a permission name. * * @param t - The translation function. * @param permissionName - The name of the permission to request. * @param permissionValue - The value of the permission to request. * @returns {JSX.Element[]} An array of permission description nodes. */ function getDescriptionNodes(t, permissionName, permissionValue) { const { label, leftIcon, rightIcon } = getPermissionDescription( t, permissionName, permissionValue, ); if (Array.isArray(label)) { return label.map((labelValue, index) => (
{labelValue} {rightIcon && }
)); } return [
{label} {rightIcon && }
, ]; } export default function PermissionsConnectPermissionList({ permissions }) { const t = useI18nContext(); return (
{Object.entries(permissions).reduce( (target, [permissionName, permissionValue]) => target.concat( getDescriptionNodes(t, permissionName, permissionValue), ), [], )}
); } PermissionsConnectPermissionList.propTypes = { permissions: PropTypes.object.isRequired, };