2022-03-04 17:56:31 +01:00
|
|
|
import React from 'react';
|
2021-12-02 18:22:18 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2023-04-14 12:04:23 +02:00
|
|
|
import {
|
|
|
|
getRightIcon,
|
|
|
|
getWeightedPermissions,
|
|
|
|
} from '../../../helpers/utils/permission';
|
2022-03-14 19:26:02 +01:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2023-04-14 12:04:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 (
|
|
|
|
<div className="permission" key={`${permissionName}-${index}`}>
|
|
|
|
{typeof leftIcon === 'string' ? <i className={leftIcon} /> : leftIcon}
|
|
|
|
{label}
|
|
|
|
{getRightIcon(permission)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-08-18 17:07:34 +02:00
|
|
|
|
2023-04-05 15:34:33 +02:00
|
|
|
export default function PermissionsConnectPermissionList({
|
|
|
|
permissions,
|
|
|
|
targetSubjectMetadata,
|
|
|
|
}) {
|
2022-03-14 19:26:02 +01:00
|
|
|
const t = useI18nContext();
|
2021-12-02 18:22:18 +01:00
|
|
|
|
|
|
|
return (
|
2023-04-14 12:04:23 +02:00
|
|
|
<div className="permissions-connect-permission-list">
|
2023-04-05 15:34:33 +02:00
|
|
|
{getWeightedPermissions(t, permissions, targetSubjectMetadata).map(
|
2023-04-14 12:04:23 +02:00
|
|
|
getDescriptionNode,
|
2023-04-05 15:34:33 +02:00
|
|
|
)}
|
2023-04-14 12:04:23 +02:00
|
|
|
</div>
|
2021-12-02 18:22:18 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
PermissionsConnectPermissionList.propTypes = {
|
2022-02-15 01:02:51 +01:00
|
|
|
permissions: PropTypes.object.isRequired,
|
2023-04-05 15:34:33 +02:00
|
|
|
targetSubjectMetadata: PropTypes.object.isRequired,
|
2021-12-02 18:22:18 +01:00
|
|
|
};
|