From a41df7ab6858df2581d5ffbbf6564d028311a4a8 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 7 Feb 2019 11:31:35 -0700 Subject: [PATCH] Convert PowerSelector to use mxField instead --- res/css/_components.scss | 1 + res/css/views/elements/_PowerSelector.scss | 25 +++++ .../views/elements/PowerSelector.js | 94 ++++++++----------- src/components/views/rooms/MemberInfo.js | 14 ++- .../tabs/room/RolesRoomSettingsTab.js | 69 ++++++-------- src/i18n/strings/en_EN.json | 37 ++++---- 6 files changed, 119 insertions(+), 121 deletions(-) create mode 100644 res/css/views/elements/_PowerSelector.scss diff --git a/res/css/_components.scss b/res/css/_components.scss index f3b07255ae..6f66a8c15e 100644 --- a/res/css/_components.scss +++ b/res/css/_components.scss @@ -85,6 +85,7 @@ @import "./views/elements/_InlineSpinner.scss"; @import "./views/elements/_ManageIntegsButton.scss"; @import "./views/elements/_MemberEventListSummary.scss"; +@import "./views/elements/_PowerSelector.scss"; @import "./views/elements/_ProgressBar.scss"; @import "./views/elements/_ReplyThread.scss"; @import "./views/elements/_ResizeHandle.scss"; diff --git a/res/css/views/elements/_PowerSelector.scss b/res/css/views/elements/_PowerSelector.scss new file mode 100644 index 0000000000..69f3a8eebb --- /dev/null +++ b/res/css/views/elements/_PowerSelector.scss @@ -0,0 +1,25 @@ +/* +Copyright 2019 New Vector Ltd. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +.mx_PowerSelector { + width: 100%; +} + +.mx_PowerSelector .mx_Field select, +.mx_PowerSelector .mx_Field input { + width: 100%; + box-sizing: border-box; +} diff --git a/src/components/views/elements/PowerSelector.js b/src/components/views/elements/PowerSelector.js index d1f102d9fe..83b8711bef 100644 --- a/src/components/views/elements/PowerSelector.js +++ b/src/components/views/elements/PowerSelector.js @@ -20,6 +20,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import * as Roles from '../../../Roles'; import { _t } from '../../../languageHandler'; +import Field from "./Field"; module.exports = React.createClass({ displayName: 'PowerSelector', @@ -32,19 +33,15 @@ module.exports = React.createClass({ // Default user power level for the room usersDefault: PropTypes.number.isRequired, - // if true, the - ; - } - } - - let selectValue; - if (this.state.custom) { - selectValue = "SELECT_VALUE_CUSTOM"; - } else { - selectValue = this.state.levelRoleMap[this.props.value] ? - this.props.value : "SELECT_VALUE_CUSTOM"; - } - let select; - if (this.props.disabled) { - select = { this.state.levelRoleMap[selectValue] }; + picker = ( + + ); } else { // Each level must have a definition in this.state.levelRoleMap let options = this.state.options.map((level) => { @@ -145,20 +134,19 @@ module.exports = React.createClass({ return ; }); - select = - ; + picker = ( + + {options} + + ); } return ( - - { select } - { customPicker } - +
+ { picker } +
); }, }); diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index d7726c8fe8..3ada730ec8 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -947,14 +947,12 @@ module.exports = withMatrixClient(React.createClass({ const PowerSelector = sdk.getComponent('elements.PowerSelector'); roomMemberDetails =
- { _t("Level:") } - - +
{presenceLabel} diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js index a6dac5a147..c4b1ae8ddc 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js @@ -24,14 +24,14 @@ import Modal from "../../../../../Modal"; const plEventsToLabels = { // These will be translated for us later. - "m.room.avatar": _td("To change the room's avatar, you must be a"), - "m.room.name": _td("To change the room's name, you must be a"), - "m.room.canonical_alias": _td("To change the room's main address, you must be a"), - "m.room.history_visibility": _td("To change the room's history visibility, you must be a"), - "m.room.power_levels": _td("To change the permissions in the room, you must be a"), - "m.room.topic": _td("To change the topic, you must be a"), + "m.room.avatar": _td("Change room avatar"), + "m.room.name": _td("Change room name"), + "m.room.canonical_alias": _td("Change main address for the room"), + "m.room.history_visibility": _td("Change history visibility"), + "m.room.power_levels": _td("Change permissions"), + "m.room.topic": _td("Change topic"), - "im.vector.modular.widgets": _td("To modify widgets in the room, you must be a"), + "im.vector.modular.widgets": _td("Modify widgets"), }; const plEventsToShow = { @@ -158,35 +158,35 @@ export default class RolesRoomSettingsTab extends React.Component { const powerLevelDescriptors = { "users_default": { - desc: _t('The default role for new room members is'), + desc: _t('Default role'), defaultValue: 0, }, "events_default": { - desc: _t('To send messages, you must be a'), + desc: _t('Send messages'), defaultValue: 0, }, "invite": { - desc: _t('To invite users into the room, you must be a'), + desc: _t('Invite users'), defaultValue: 50, }, "state_default": { - desc: _t('To configure the room, you must be a'), + desc: _t('Change settings'), defaultValue: 50, }, "kick": { - desc: _t('To kick users, you must be a'), + desc: _t('Kick users'), defaultValue: 50, }, "ban": { - desc: _t('To ban users, you must be a'), + desc: _t('Ban users'), defaultValue: 50, }, "redact": { - desc: _t('To remove other users\' messages, you must be a'), + desc: _t('Remove messages'), defaultValue: 50, }, "notifications.room": { - desc: _t('To notify everyone in the room, you must be a'), + desc: _t('Notify everyone'), defaultValue: 50, }, }; @@ -217,20 +217,15 @@ export default class RolesRoomSettingsTab extends React.Component { const mutedUsers = []; Object.keys(userLevels).forEach(function(user) { + const canChange = userLevels[user] < currentUserLevel && canChangeLevels; if (userLevels[user] > defaultUserLevel) { // privileged - privilegedUsers.push(
  • - { _t("%(user)s is a %(userRole)s", { - user: user, - userRole: , - }) } -
  • ); + privilegedUsers.push( + , + ); } else if (userLevels[user] < defaultUserLevel) { // muted - mutedUsers.push(
  • - { _t("%(user)s is a %(userRole)s", { - user: user, - userRole: , - }) } -
  • ); + mutedUsers.push( + , + ); } }); @@ -247,18 +242,14 @@ export default class RolesRoomSettingsTab extends React.Component { privilegedUsersSection =
    { _t('Privileged Users') }
    -
      - {privilegedUsers} -
    + {privilegedUsers}
    ; } if (mutedUsers.length) { mutedUsersSection =
    { _t('Muted Users') }
    -
      - {mutedUsers} -
    + {mutedUsers}
    ; } } @@ -300,11 +291,10 @@ export default class RolesRoomSettingsTab extends React.Component { const value = parseIntWithDefault(currentObj, descriptor.defaultValue); return
    - {descriptor.desc}  , you must be a", {}, - { 'eventType': { eventType } }, - ); + label = _t("Send %(eventType)s events", {eventType}); } return (
    - {label}  {_t("Permissions")} +

    {_t('Select the roles required to change various parts of the room')}

    {powerSelectors} {eventPowerSelectors}
    diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 696bd8152c..0d7cbd5f7f 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -586,32 +586,32 @@ "Room Addresses": "Room Addresses", "Publish this room to the public in %(domain)s's room directory?": "Publish this room to the public in %(domain)s's room directory?", "URL Previews": "URL Previews", - "To change the room's avatar, you must be a": "To change the room's avatar, you must be a", - "To change the room's name, you must be a": "To change the room's name, you must be a", - "To change the room's main address, you must be a": "To change the room's main address, you must be a", - "To change the room's history visibility, you must be a": "To change the room's history visibility, you must be a", - "To change the permissions in the room, you must be a": "To change the permissions in the room, you must be a", - "To change the topic, you must be a": "To change the topic, you must be a", - "To modify widgets in the room, you must be a": "To modify widgets in the room, you must be a", + "Change room avatar": "Change room avatar", + "Change room name": "Change room name", + "Change main address for the room": "Change main address for the room", + "Change history visibility": "Change history visibility", + "Change permissions": "Change permissions", + "Change topic": "Change topic", + "Modify widgets": "Modify widgets", "Failed to unban": "Failed to unban", "Unban": "Unban", "Banned by %(displayName)s": "Banned by %(displayName)s", - "The default role for new room members is": "The default role for new room members is", - "To send messages, you must be a": "To send messages, you must be a", - "To invite users into the room, you must be a": "To invite users into the room, you must be a", - "To configure the room, you must be a": "To configure the room, you must be a", - "To kick users, you must be a": "To kick users, you must be a", - "To ban users, you must be a": "To ban users, you must be a", - "To remove other users' messages, you must be a": "To remove other users' messages, you must be a", - "To notify everyone in the room, you must be a": "To notify everyone in the room, you must be a", + "Default role": "Default role", + "Send messages": "Send messages", + "Invite users": "Invite users", + "Change settings": "Change settings", + "Kick users": "Kick users", + "Ban users": "Ban users", + "Remove messages": "Remove messages", + "Notify everyone": "Notify everyone", "No users have specific privileges in this room": "No users have specific privileges in this room", - "%(user)s is a %(userRole)s": "%(user)s is a %(userRole)s", "Privileged Users": "Privileged Users", "Muted Users": "Muted Users", "Banned users": "Banned users", - "To send events of type , you must be a": "To send events of type , you must be a", + "Send %(eventType)s events": "Send %(eventType)s events", "Roles & Permissions": "Roles & Permissions", "Permissions": "Permissions", + "Select the roles required to change various parts of the room": "Select the roles required to change various parts of the room", "Guests cannot join this room even if explicitly invited.": "Guests cannot join this room even if explicitly invited.", "Click here to fix": "Click here to fix", "To link to this room, please add an alias.": "To link to this room, please add an alias.", @@ -685,7 +685,6 @@ "Revoke Moderator": "Revoke Moderator", "Make Moderator": "Make Moderator", "Admin Tools": "Admin Tools", - "Level:": "Level:", "Close": "Close", "and %(count)s others...|other": "and %(count)s others...", "and %(count)s others...|one": "and one other...", @@ -998,7 +997,7 @@ "%(items)s and %(lastItem)s": "%(items)s and %(lastItem)s", "collapse": "collapse", "expand": "expand", - "Custom of %(powerLevel)s": "Custom of %(powerLevel)s", + "Power level": "Power level", "Custom level": "Custom level", "Unable to load event that was replied to, it either does not exist or you do not have permission to view it.": "Unable to load event that was replied to, it either does not exist or you do not have permission to view it.", "In reply to ": "In reply to ",