talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | import React from 'react'; |
| 18 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 19 | import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js'; |
| 20 | import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js'; |
| 21 | import Tooltip from 'react-bootstrap/lib/Tooltip.js'; |
| 22 | |
| 23 | const maxContributors = 6; |
| 24 | |
| 25 | function extraUsersTooltip (extraUsers) { |
| 26 | return ( |
| 27 | <Tooltip className='extra-users-tooltip' id='extra-users-tooltip-id'> |
| 28 | {extraUsers.map(extraUser => <div key={extraUser.userId} className='extra-user'>{extraUser.fullName}</div>)} |
| 29 | </Tooltip> |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | const User = ({user, isCurrentUser, dataTestId}) => ( |
| 34 | <SVGIcon className={`user-view ${isCurrentUser ? 'current-user' : ''}`} name='user' label={user.fullName} labelPosition='right' color='primary' |
| 35 | data-test-id={dataTestId}/> |
| 36 | ); |
| 37 | |
| 38 | const Owner = ({owner, isCurrentUser}) => ( |
| 39 | <div className='owner-view'> |
| 40 | <div className='permissions-view-title'>{i18n('Owner')}</div> |
| 41 | <User user={owner} isCurrentUser={isCurrentUser} dataTestId='owner'/> |
| 42 | </div> |
| 43 | ); |
| 44 | |
| 45 | const Contributors = ({contributors, owner, currentUser, onManagePermissions, isManual}) => { |
| 46 | let extraUsers = contributors.length - maxContributors; |
| 47 | return ( |
| 48 | <div className='contributors-view'> |
| 49 | <div className='permissions-view-title'>{i18n('Contributors')}</div> |
| 50 | {contributors.slice(0, maxContributors).map(contributor => |
| 51 | <User key={contributor.userId} user={contributor} isCurrentUser={contributor.userId === currentUser.userId} dataTestId='contributor'/> |
| 52 | )} |
| 53 | {extraUsers > 0 && |
| 54 | <OverlayTrigger placement='bottom' overlay={extraUsersTooltip(contributors.slice(maxContributors))}> |
| 55 | <div className='extra-contributors'>{`+${extraUsers}`}</div> |
| 56 | </OverlayTrigger> |
| 57 | } |
| 58 | {currentUser.userId === owner.userId && !isManual && |
| 59 | <span |
| 60 | className='manage-permissions' |
| 61 | onClick={onManagePermissions} |
| 62 | data-test-id='versions-page-manage-permissions'> |
| 63 | {i18n('Manage Permissions')} |
| 64 | </span> |
| 65 | } |
| 66 | </div> |
| 67 | ); |
| 68 | }; |
| 69 | |
| 70 | const PermissionsView = ({owner, contributors, currentUser = {}, onManagePermissions, isManual}) => ( |
| 71 | <div className='versions-page-permissions-view-wrapper'> |
| 72 | <div className='permissions-view-wrapper-title'>{i18n('Permissions')}</div> |
| 73 | <div className='permissions-view-content'> |
| 74 | <div className='permissions-view'> |
| 75 | <Owner owner={owner} isCurrentUser={owner.userId === currentUser.userId} /> |
| 76 | <Contributors owner={owner} contributors={contributors} currentUser={currentUser} onManagePermissions={onManagePermissions} isManual={isManual}/> |
| 77 | </div> |
| 78 | </div> |
| 79 | </div> |
| 80 | ); |
| 81 | |
| 82 | export default PermissionsView; |