From 73d88771af80f6d27dc48ccfae515d616b075327 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 25 Feb 2017 15:18:47 -0800 Subject: [PATCH] more badass permissions selector --- frontend/src/components/TopicCard/Links.js | 5 +- .../src/components/TopicCard/Permission.js | 61 ++++++++----------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/frontend/src/components/TopicCard/Links.js b/frontend/src/components/TopicCard/Links.js index 02fd7281..23e6cfe1 100644 --- a/frontend/src/components/TopicCard/Links.js +++ b/frontend/src/components/TopicCard/Links.js @@ -72,6 +72,7 @@ class Links extends Component { render = () => { const { topic, ActiveMapper } = this.props + const authorizedToEdit = topic.authorizeToEdit(ActiveMapper) const metacode = topic.getMetacode() return ( @@ -125,8 +126,8 @@ class Links extends Component { {this.state.hoveringSynapseCount &&
Click to see this topics synapses
}
diff --git a/frontend/src/components/TopicCard/Permission.js b/frontend/src/components/TopicCard/Permission.js index d92ad72c..c3e78fb1 100644 --- a/frontend/src/components/TopicCard/Permission.js +++ b/frontend/src/components/TopicCard/Permission.js @@ -22,54 +22,43 @@ class Permission extends Component { this.setState({selectingPermission: false}) } + liClick = value => event => { + this.closePermissionSelect() + this.props.updateTopic({ + permission: value, + defer_to_map_id: null + }) + // prevents it from also firing the event listener on the parent + event.preventDefault() + } + render = () => { - const self = this - const { topic, ActiveMapper, updateTopic } = this.props + const { permission, authorizedToEdit } = this.props const { selectingPermission } = this.state - const permission = topic.get('permission') - const canChange = topic.authorizePermissionChange(ActiveMapper) - const onClick = canChange ? this.togglePermissionSelect : () => {} + let classes = `linkItem mapPerm ${permission.substring(0, 2)}` if (selectingPermission) classes += ' minimize' - const liClick = value => { - return event => { - self.closePermissionSelect() - updateTopic({ - permission: value, - defer_to_map_id: null - }) - // prevents it from also firing the event listener on the parent - event.preventDefault() - } - } - const selectCommons =
  • - const selectPublic =
  • - const selectPrivate =
  • - let permOptions - if (permission === 'commons') { - permOptions = [selectPublic, selectPrivate] - } else if (permission === 'public') { - permOptions = [selectCommons, selectPrivate] - } else if (permission === 'private') { - permOptions = [selectCommons, selectPublic] - } return ( -
    - {selectingPermission &&
      - {permOptions} -
    } +
    +
      + {permission !== 'commons' &&
    • } + {permission !== 'public' &&
    • } + {permission !== 'private' &&
    • } +
    ) } } Permission.propTypes = { - topic: PropTypes.object, // backbone object - ActiveMapper: PropTypes.object, + permission: PropTypes.string, // 'co', 'pu', or 'pr' + authorizedToEdit: PropTypes.bool, updateTopic: PropTypes.func }