diff options
author | Einav Weiss Keidar <einavw@amdocs.com> | 2018-03-20 14:45:40 +0200 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-03-20 13:52:31 +0000 |
commit | 7fdf733a64670fceefc3ded35cfa581e1c458179 (patch) | |
tree | b3623ac9a331473830cb0167c0b487f2a176427c /openecomp-ui/src/sdc-app/onboarding/permissions | |
parent | c7916a4e5955ccc5f0f5252307363b791ec5c7b9 (diff) |
Adding Prettier and fixing up eslint version
Issue-ID: SDC-1094
Change-Id: Ie83ad95a03899345dd90235daf0323cbe3bc6afd
Signed-off-by: Einav Weiss Keidar <einavw@amdocs.com>
Diffstat (limited to 'openecomp-ui/src/sdc-app/onboarding/permissions')
5 files changed, 291 insertions, 192 deletions
diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js index c25d93f2fc..d42a2f83ad 100644 --- a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js +++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js @@ -15,94 +15,110 @@ */ import i18n from 'nfvo-utils/i18n/i18n.js'; -import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js'; -import {actionTypes} from './PermissionsConstants.js'; -import {permissionTypes} from './PermissionsConstants.js'; -import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js'; -import {askForRightsMsg} from './PermissionsManager.jsx'; +import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js'; +import { actionTypes } from './PermissionsConstants.js'; +import { permissionTypes } from './PermissionsConstants.js'; +import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js'; +import { askForRightsMsg } from './PermissionsManager.jsx'; import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js'; const PermissionsActionHelper = { - openPermissonsManager(dispatch, {itemId, askForRights}) { - if (askForRights) { - dispatch({ - type: modalActionTypes.GLOBAL_MODAL_SHOW, - data: { - title: i18n('Ask For Contributers Rights'), - msg: askForRightsMsg(), - confirmationButtonText: i18n('SEND'), - onConfirmed: () => this.askForContributorRights() - } - }); - } else { - dispatch({ - type: modalActionTypes.GLOBAL_MODAL_SHOW, - data: { - modalComponentName: modalContentMapper.MANAGE_PERMISSIONS, - title: i18n('Manage Permissions'), - modalComponentProps: { - itemId - } - } - }); - } - }, + openPermissonsManager(dispatch, { itemId, askForRights }) { + if (askForRights) { + dispatch({ + type: modalActionTypes.GLOBAL_MODAL_SHOW, + data: { + title: i18n('Ask For Contributers Rights'), + msg: askForRightsMsg(), + confirmationButtonText: i18n('SEND'), + onConfirmed: () => this.askForContributorRights() + } + }); + } else { + dispatch({ + type: modalActionTypes.GLOBAL_MODAL_SHOW, + data: { + modalComponentName: modalContentMapper.MANAGE_PERMISSIONS, + title: i18n('Manage Permissions'), + modalComponentProps: { + itemId + } + } + }); + } + }, - closePermissionManager(dispatch) { - dispatch({ - type: modalActionTypes.GLOBAL_MODAL_CLOSE - }); - }, + closePermissionManager(dispatch) { + dispatch({ + type: modalActionTypes.GLOBAL_MODAL_CLOSE + }); + }, - saveItemUsers(dispatch, {itemId, removedUsersIds, addedUsersIds, allUsers}) { - return ItemsHelper.updateContributors({itemId, removedUsersIds, addedUsersIds}).then(() => - PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers}) - ); - }, + saveItemUsers( + dispatch, + { itemId, removedUsersIds, addedUsersIds, allUsers } + ) { + return ItemsHelper.updateContributors({ + itemId, + removedUsersIds, + addedUsersIds + }).then(() => + PermissionsActionHelper.fetchItemUsers(dispatch, { + itemId, + allUsers + }) + ); + }, - changeOwner(dispatch, {itemId, newOwnerId, allUsers}) { - return ItemsHelper.changeOwner({itemId, ownerId: newOwnerId}).then(() => - PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers}) - ); - }, + changeOwner(dispatch, { itemId, newOwnerId, allUsers }) { + return ItemsHelper.changeOwner({ itemId, ownerId: newOwnerId }).then( + () => + PermissionsActionHelper.fetchItemUsers(dispatch, { + itemId, + allUsers + }) + ); + }, - fetchItemUsers(dispatch, {itemId, allUsers}) { - return ItemsHelper.fetchUsers({itemId}).then(response => { + fetchItemUsers(dispatch, { itemId, allUsers }) { + return ItemsHelper.fetchUsers({ itemId }).then(response => { + let allContributors = response.results; - let allContributors = response.results; - - let owner = {}; - let contributors = []; - allContributors.map(user => { - let userObject = allUsers.find(userObject => userObject.userId === user.userId); - if (userObject) { - user = {...user, fullName: userObject.fullName, role: userObject.role}; - - switch(user.permission) { - case permissionTypes.OWNER: - owner = user; - break; - case permissionTypes.CONTRIBUTOR: - contributors.push(user); - break; - } - } - }); - - dispatch({ - type: actionTypes.ITEM_USERS_LOADED, - contributors, - owner - }); - }); - }, - - askForContributorRights() { - console.log('asked for contributor rights'); - } + let owner = {}; + let contributors = []; + allContributors.map(user => { + let userObject = allUsers.find( + userObject => userObject.userId === user.userId + ); + if (userObject) { + user = { + ...user, + fullName: userObject.fullName, + role: userObject.role + }; + switch (user.permission) { + case permissionTypes.OWNER: + owner = user; + break; + case permissionTypes.CONTRIBUTOR: + contributors.push(user); + break; + } + } + }); + dispatch({ + type: actionTypes.ITEM_USERS_LOADED, + contributors, + owner + }); + }); + }, + askForContributorRights() { + console.log('asked for contributor rights'); + } }; export default PermissionsActionHelper; diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js index 48a3461799..686aaaf0dd 100644 --- a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js +++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js @@ -16,12 +16,13 @@ import keyMirror from 'nfvo-utils/KeyMirror.js'; export const actionTypes = keyMirror({ - ITEM_USERS_LOADED: null + ITEM_USERS_LOADED: null }); export const permissionTypes = { - OWNER: 'Owner', - CONTRIBUTOR: 'Contributor' + OWNER: 'Owner', + CONTRIBUTOR: 'Contributor' }; -export const changeOwnerMessage = 'You will no longer be able to manage the permissions of this item.\nYour permission level will be set to contributor.'; +export const changeOwnerMessage = + 'You will no longer be able to manage the permissions of this item.\nYour permission level will be set to contributor.'; diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js index ba6562b28f..3b6d62bc15 100644 --- a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js +++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js @@ -14,30 +14,55 @@ * permissions and limitations under the License. */ -import {connect} from 'react-redux'; +import { connect } from 'react-redux'; import PermissionsManager from './PermissionsManager.jsx'; import PermissionsActionHelper from './PermissionsActionHelper.js'; -export const mapStateToProps = ({versionsPage, users: {usersList, userInfo}}) => { - let {permissions} = versionsPage; +export const mapStateToProps = ({ + versionsPage, + users: { usersList, userInfo } +}) => { + let { permissions } = versionsPage; - return { - users: usersList, - userInfo, - owner: permissions.owner, - itemUsers: permissions.contributors - }; + return { + users: usersList, + userInfo, + owner: permissions.owner, + itemUsers: permissions.contributors + }; }; -const mapActionsToProps = (dispatch) => { - return { - onCancel: () => PermissionsActionHelper.closePermissionManager(dispatch), - onSubmit: ({itemId, addedUsersIds, removedUsersIds, allUsers, newOwnerId}) => { - return PermissionsActionHelper.saveItemUsers(dispatch,{itemId, addedUsersIds, removedUsersIds, allUsers}).then(() => { - return newOwnerId ? PermissionsActionHelper.changeOwner(dispatch, {itemId, newOwnerId, allUsers}) : Promise.resolve(); - }).then(() => PermissionsActionHelper.closePermissionManager(dispatch)); - } - }; +const mapActionsToProps = dispatch => { + return { + onCancel: () => + PermissionsActionHelper.closePermissionManager(dispatch), + onSubmit: ({ + itemId, + addedUsersIds, + removedUsersIds, + allUsers, + newOwnerId + }) => { + return PermissionsActionHelper.saveItemUsers(dispatch, { + itemId, + addedUsersIds, + removedUsersIds, + allUsers + }) + .then(() => { + return newOwnerId + ? PermissionsActionHelper.changeOwner(dispatch, { + itemId, + newOwnerId, + allUsers + }) + : Promise.resolve(); + }) + .then(() => + PermissionsActionHelper.closePermissionManager(dispatch) + ); + } + }; }; export default connect(mapStateToProps, mapActionsToProps)(PermissionsManager); diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx index b7d5d57cca..ab6add8ac2 100644 --- a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx +++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx @@ -21,97 +21,154 @@ import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js'; import Tooltip from 'react-bootstrap/lib/Tooltip.js'; import i18n from 'nfvo-utils/i18n/i18n.js'; -import {permissionTypes, changeOwnerMessage} from './PermissionsConstants.js'; +import { permissionTypes, changeOwnerMessage } from './PermissionsConstants.js'; export const askForRightsMsg = () => { - return ( - <div> - <p>{i18n('Send a Contributor rights reguest to Owner')}</p> - </div> - ); + return ( + <div> + <p>{i18n('Send a Contributor rights reguest to Owner')}</p> + </div> + ); }; - class Permissions extends React.Component { - constructor(props) { - super(props); - this.state = { - itemUsers: props.itemUsers, - newOwnerId: '', - showChangeOwner: false - }; - } + constructor(props) { + super(props); + this.state = { + itemUsers: props.itemUsers, + newOwnerId: '', + showChangeOwner: false + }; + } - buildUserOptions() { - let {users, owner} = this.props; - return users.filter(user => user.userId !== owner.userId).map(item => {return {label: item.fullName, value: item.userId};}); - } + buildUserOptions() { + let { users, owner } = this.props; + return users.filter(user => user.userId !== owner.userId).map(item => { + return { label: item.fullName, value: item.userId }; + }); + } - render() { - let {onCancel, owner} = this.props; - let {newOwnerId} = this.state; - return ( - <div className='manage-permissions-page'> - <Form - hasButtons={true} - onSubmit={() => this.onsaveItemUsers()} - onReset={() => onCancel() } - labledButtons={true}> - <div className='manage-permissions-title'>{i18n('Owner')}</div> - <div className='owner-details'> - <span>{owner.fullName}</span> - <span className='change-owner' onClick={() => this.setState({showChangeOwner: !this.state.showChangeOwner})}>{i18n('Change Owner')}</span> - </div> - {this.state.showChangeOwner && <div className='change-owner-wrapper'> - <div className='change-owner-title'> - <span className='manage-permissions-title' data-test-id='change-owner'>{i18n('Change Owner')}</span> - <OverlayTrigger placement='right' trigger='click' overlay={ - <Tooltip id='manage-permissions-owner-tooltip' className='manage-permissions-owner-tooltip'>{i18n(changeOwnerMessage)}</Tooltip> }> - <SVGIcon name='questionMark' /> - </OverlayTrigger> - </div> - <Select - data-test-id='selected-owner' - value={newOwnerId} - onChange={(item) => this.setState({newOwnerId: item ? item.value : ''})} - options={this.buildUserOptions()} /> - </div>} - <div className='manage-permissions-title'>{i18n('Contributors')}</div> - <Select - data-test-id='selected-contributors' - value={this.state.itemUsers.map(item => item.userId)} - className='options-input contributors-select' - clearable={false} - onMultiSelectChanged={(value) => {this.onChangeItemUsers({itemUsers: value});}} - options={this.buildUserOptions()} - multi/> - </Form> - </div> - ); - } + render() { + let { onCancel, owner } = this.props; + let { newOwnerId } = this.state; + return ( + <div className="manage-permissions-page"> + <Form + hasButtons={true} + onSubmit={() => this.onsaveItemUsers()} + onReset={() => onCancel()} + labledButtons={true}> + <div className="manage-permissions-title"> + {i18n('Owner')} + </div> + <div className="owner-details"> + <span>{owner.fullName}</span> + <span + className="change-owner" + onClick={() => + this.setState({ + showChangeOwner: !this.state.showChangeOwner + }) + }> + {i18n('Change Owner')} + </span> + </div> + {this.state.showChangeOwner && ( + <div className="change-owner-wrapper"> + <div className="change-owner-title"> + <span + className="manage-permissions-title" + data-test-id="change-owner"> + {i18n('Change Owner')} + </span> + <OverlayTrigger + placement="right" + trigger="click" + overlay={ + <Tooltip + id="manage-permissions-owner-tooltip" + className="manage-permissions-owner-tooltip"> + {i18n(changeOwnerMessage)} + </Tooltip> + }> + <SVGIcon name="questionMark" /> + </OverlayTrigger> + </div> + <Select + data-test-id="selected-owner" + value={newOwnerId} + onChange={item => + this.setState({ + newOwnerId: item ? item.value : '' + }) + } + options={this.buildUserOptions()} + /> + </div> + )} + <div className="manage-permissions-title"> + {i18n('Contributors')} + </div> + <Select + data-test-id="selected-contributors" + value={this.state.itemUsers.map(item => item.userId)} + className="options-input contributors-select" + clearable={false} + onMultiSelectChanged={value => { + this.onChangeItemUsers({ itemUsers: value }); + }} + options={this.buildUserOptions()} + multi + /> + </Form> + </div> + ); + } - onChangeItemUsers({itemUsers}) { - this.setState({ - itemUsers: itemUsers.map(contributor => { - let contributorFromProps = this.props.itemUsers.find(user => user.userId === contributor.userId); - return { - userId: contributor.value, - fullName: contributor.label, - permission: contributorFromProps ? contributorFromProps.permission : permissionTypes.CONTRIBUTOR - }; - }) - }); - } + onChangeItemUsers({ itemUsers }) { + this.setState({ + itemUsers: itemUsers.map(contributor => { + let contributorFromProps = this.props.itemUsers.find( + user => user.userId === contributor.userId + ); + return { + userId: contributor.value, + fullName: contributor.label, + permission: contributorFromProps + ? contributorFromProps.permission + : permissionTypes.CONTRIBUTOR + }; + }) + }); + } - onsaveItemUsers() { - let {itemUsers: newUsers, newOwnerId} = this.state; - let {itemUsers: oldUsers, onSubmit, itemId, users} = this.props; - let addedUsersIds = newUsers.filter(newUser => !oldUsers.map(oldUser => oldUser.userId).includes(newUser.userId)) - .map(user => user.userId); - let removedUsersIds = oldUsers.filter(oldUser => !newUsers.map(newUser => newUser.userId).includes(oldUser.userId)) - .map(user => user.userId); - onSubmit({itemId, addedUsersIds, removedUsersIds, allUsers: users, newOwnerId}); - } + onsaveItemUsers() { + let { itemUsers: newUsers, newOwnerId } = this.state; + let { itemUsers: oldUsers, onSubmit, itemId, users } = this.props; + let addedUsersIds = newUsers + .filter( + newUser => + !oldUsers + .map(oldUser => oldUser.userId) + .includes(newUser.userId) + ) + .map(user => user.userId); + let removedUsersIds = oldUsers + .filter( + oldUser => + !newUsers + .map(newUser => newUser.userId) + .includes(oldUser.userId) + ) + .map(user => user.userId); + onSubmit({ + itemId, + addedUsersIds, + removedUsersIds, + allUsers: users, + newOwnerId + }); + } } export default Permissions; diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js index b4ab78964d..6e817ae3db 100644 --- a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js +++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js @@ -13,16 +13,16 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -import {actionTypes} from './PermissionsConstants.js'; +import { actionTypes } from './PermissionsConstants.js'; export default (state = {}, action) => { - switch (action.type) { - case actionTypes.ITEM_USERS_LOADED: - return { - owner: action.owner, - contributors: action.contributors - }; - default: - return state; - } -};
\ No newline at end of file + switch (action.type) { + case actionTypes.ITEM_USERS_LOADED: + return { + owner: action.owner, + contributors: action.contributors + }; + default: + return state; + } +}; |