blob: 26f8450f4cbba842cb203d6036732bca2797260b [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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
17import React from 'react';
18import i18n from 'nfvo-utils/i18n/i18n.js';
19import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
20import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
21import Tooltip from 'react-bootstrap/lib/Tooltip.js';
22
23const maxContributors = 6;
24
25function 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
33const 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
38const 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
45const 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
70const 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
82export default PermissionsView;