Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 14th, 2018 73 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. import React from 'react';
  2. import Chip from '@material-ui/core/Chip';
  3. import IconButton from '@material-ui/core/IconButton';
  4. import Table from '@material-ui/core/Table';
  5. import TableBody from '@material-ui/core/TableBody';
  6. import TableCell from '@material-ui/core/TableCell';
  7. import TableHead from '@material-ui/core/TableHead';
  8. import TableRow from '@material-ui/core/TableRow';
  9. import Tooltip from '@material-ui/core/Tooltip';
  10. import withStyles from '@material-ui/core/styles/withStyles';
  11. import CloseIcon from '@material-ui/icons/Close';
  12. import DoneIcon from '@material-ui/icons/Done';
  13.  
  14. import { canRenderAction } from '../services/permission-set.service';
  15.  
  16. const styles = theme => ({
  17.   permissionWrapper: {},
  18.   permissionActionWrapper: {}
  19. });
  20.  
  21. export default withStyles(styles)(({ classes, resources, roles, removeButton, selectButton }) => {
  22.  
  23.   const renderPermissionActions = (permissions, resource) => permissions.map(permission => {
  24.     const canRender = canRenderAction(resource, permission.resource);
  25.  
  26.     return canRender ? <span>{permission.action}</span> : ''
  27.   });
  28.  
  29.   const renderPermissions = permissions => resources.map(resource => {
  30.     return (
  31.       <div
  32.         className={classes.permissionWrapper}
  33.         key={resource}>
  34.         <React.Fragment>
  35.           <Chip
  36.             color={"primary"}
  37.             label={resource}
  38.           />
  39.           <div className={classes.permissionActionWrapper}>{renderPermissionActions.apply(this, [permissions,resource] )}</div>
  40.         </React.Fragment>
  41.       </div>
  42.     );
  43.   });
  44.  
  45.   const renderRemoveButton = (
  46.     <Tooltip title={"Remove item"}>
  47.       <IconButton>
  48.         <CloseIcon />
  49.       </IconButton>
  50.     </Tooltip>
  51.   );
  52.  
  53.   const renderSelectButton = (
  54.     <Tooltip title={"Select item"}>
  55.       <IconButton>
  56.         <DoneIcon />
  57.       </IconButton>
  58.     </Tooltip>
  59.   );
  60.  
  61.   return (
  62.     <Table>
  63.       <TableHead>
  64.         <TableRow>
  65.           <TableCell>No.</TableCell>
  66.           <TableCell>Name</TableCell>
  67.           <TableCell>Permissions</TableCell>
  68.           <TableCell numeric />
  69.         </TableRow>
  70.       </TableHead>
  71.       <TableBody>
  72.         {roles.map((role, index) => {
  73.           let uniqueKey = role.id;
  74.           let positionNumber = ++index;
  75.           let name = role.name;
  76.           let permissions = role.permissionSet;
  77.  
  78.           return (
  79.             <TableRow key={uniqueKey}>
  80.               <TableCell>{positionNumber}.</TableCell>
  81.               <TableCell
  82.                 className={classes.tableCellForName}
  83.                 component={"th"}
  84.                 scope={"row"}>{name}
  85.               </TableCell>
  86.               <TableCell>{renderPermissions.apply(this, [permissions])}</TableCell>
  87.               <TableCell numeric>
  88.                 {removeButton ? renderRemoveButton : ''}
  89.                 {selectButton ? renderSelectButton : ''}
  90.               </TableCell>
  91.             </TableRow>
  92.           );
  93.         })}
  94.       </TableBody>
  95.     </Table>
  96.   );
  97. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top