From 6237631a85b79311a60b87df423abbdce56c7876 Mon Sep 17 00:00:00 2001
From: hmhealey
Date: Mon, 16 Nov 2015 12:08:05 -0500
Subject: [PATCH] Ported EditChannelModal to React-Bootstrap
---
web/react/components/channel_header.jsx | 27 ++-
web/react/components/edit_channel_modal.jsx | 174 ++++++++-----------
web/react/components/navbar.jsx | 56 ++++--
web/react/components/toggle_modal_button.jsx | 17 +-
web/react/pages/channel.jsx | 6 -
web/react/utils/channel_intro_mssages.jsx | 51 ++----
web/react/utils/utils.jsx | 17 +-
7 files changed, 161 insertions(+), 187 deletions(-)
diff --git a/web/react/components/channel_header.jsx b/web/react/components/channel_header.jsx
index 8c721348fb..06d5db8b0a 100644
--- a/web/react/components/channel_header.jsx
+++ b/web/react/components/channel_header.jsx
@@ -4,6 +4,7 @@
import NavbarSearchBox from './search_bar.jsx';
import MessageWrapper from './message_wrapper.jsx';
import PopoverListMembers from './popover_list_members.jsx';
+import EditChannelModal from './edit_channel_modal.jsx';
import EditChannelPurposeModal from './edit_channel_purpose_modal.jsx';
import ChannelInfoModal from './channel_info_modal.jsx';
import ChannelInviteModal from './channel_invite_modal.jsx';
@@ -167,17 +168,13 @@ export default class ChannelHeader extends React.Component {
key='edit_header_direct'
role='presentation'
>
-
{'Set Channel Header...'}
-
+
);
} else {
@@ -235,17 +232,13 @@ export default class ChannelHeader extends React.Component {
key='set_channel_header'
role='presentation'
>
-
- {'Set '}{channelTerm}{' Header...'}
-
+ {`Set ${channelTerm} Header...`}
+
);
dropdownContents.push(
diff --git a/web/react/components/edit_channel_modal.jsx b/web/react/components/edit_channel_modal.jsx
index 80dab4a57f..487ae69647 100644
--- a/web/react/components/edit_channel_modal.jsx
+++ b/web/react/components/edit_channel_modal.jsx
@@ -3,39 +3,51 @@
import * as Client from '../utils/client.jsx';
import * as AsyncClient from '../utils/async_client.jsx';
+import * as Utils from '../utils/utils.jsx';
+
+const Modal = ReactBootstrap.Modal;
export default class EditChannelModal extends React.Component {
constructor(props) {
super(props);
this.handleEdit = this.handleEdit.bind(this);
- this.handleUserInput = this.handleUserInput.bind(this);
- this.handleClose = this.handleClose.bind(this);
+
this.onShow = this.onShow.bind(this);
- this.handleShown = this.handleShown.bind(this);
+ this.onHide = this.onHide.bind(this);
this.state = {
- header: '',
- title: '',
- channelId: '',
serverError: ''
};
}
+
+ componentDidMount() {
+ if (this.props.show) {
+ this.onShow();
+ }
+ }
+
+ componentDidUpdate(prevProps) {
+ if (this.props.show && !prevProps.show) {
+ this.onShow();
+ }
+ }
+
handleEdit() {
var data = {};
- data.channel_id = this.state.channelId;
+ data.channel_id = this.props.channel.id;
if (data.channel_id.length !== 26) {
return;
}
- data.channel_header = this.state.header.trim();
+ data.channel_header = ReactDOM.findDOMNode(this.refs.textarea).value;
Client.updateChannelHeader(data,
() => {
this.setState({serverError: ''});
- AsyncClient.getChannel(this.state.channelId);
- $(ReactDOM.findDOMNode(this.refs.modal)).modal('hide');
+ AsyncClient.getChannel(this.props.channel.id);
+ this.onHide();
},
(err) => {
if (err.message === 'Invalid channel_header parameter') {
@@ -46,105 +58,69 @@ export default class EditChannelModal extends React.Component {
}
);
}
- handleUserInput(e) {
- this.setState({header: e.target.value});
+
+ onShow() {
+ const textarea = ReactDOM.findDOMNode(this.refs.textarea);
+ Utils.placeCaretAtEnd(textarea);
}
- handleClose() {
- this.setState({header: '', serverError: ''});
- }
- onShow(e) {
- const button = e.relatedTarget;
- this.setState({header: $(button).attr('data-header'), title: $(button).attr('data-title'), channelId: $(button).attr('data-channelid'), serverError: ''});
- }
- handleShown() {
- $('#edit_channel #edit_header').focus();
- }
- componentDidMount() {
- $(ReactDOM.findDOMNode(this.refs.modal)).on('show.bs.modal', this.onShow);
- $(ReactDOM.findDOMNode(this.refs.modal)).on('hidden.bs.modal', this.handleClose);
- $(ReactDOM.findDOMNode(this.refs.modal)).on('shown.bs.modal', this.handleShown);
- }
- componentWillUnmount() {
- $(ReactDOM.findDOMNode(this.refs.modal)).off('hidden.bs.modal', this.handleClose);
+
+ onHide() {
+ this.setState({
+ serverError: ''
+ });
+
+ this.props.onHide();
}
+
render() {
var serverError = null;
if (this.state.serverError) {
serverError =
;
}
- var editTitle = (
-
- {'Edit Header'}
-
- );
- if (this.state.title) {
- editTitle = (
-
- {'Edit Header for '}{this.state.title}
-
- );
- }
-
return (
-
-
-
-
-
- {editTitle}
-
-
-
{'Edit the text appearing next to the channel name in the channel header.'}
-
- {serverError}
-
-
-
-
-
-
-
-
+
+ {'Edit Header for ' + this.props.channel.display_name}
+
+
+ {'Edit the text appearing next to the channel name in the channel header.'}
+
+ {serverError}
+
+
+
+
+
+
);
}
}
+
+EditChannelModal.propTypes = {
+ show: React.PropTypes.bool.isRequired,
+ onHide: React.PropTypes.func.isRequired,
+ channel: React.PropTypes.object.isRequired
+};
diff --git a/web/react/components/navbar.jsx b/web/react/components/navbar.jsx
index 6848ee5da2..8d3d779f36 100644
--- a/web/react/components/navbar.jsx
+++ b/web/react/components/navbar.jsx
@@ -1,6 +1,7 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
+import EditChannelModal from './edit_channel_modal.jsx';
import EditChannelPurposeModal from './edit_channel_purpose_modal.jsx';
import MessageWrapper from './message_wrapper.jsx';
import NotifyCounts from './notify_counts.jsx';
@@ -33,11 +34,15 @@ export default class Navbar extends React.Component {
this.onChange = this.onChange.bind(this);
this.handleLeave = this.handleLeave.bind(this);
this.showSearch = this.showSearch.bind(this);
+
+ this.showEditChannelHeaderModal = this.showEditChannelHeaderModal.bind(this);
+
this.createCollapseButtons = this.createCollapseButtons.bind(this);
this.createDropdown = this.createDropdown.bind(this);
const state = this.getStateFromStores();
state.showEditChannelPurposeModal = false;
+ state.showEditChannelHeaderModal = false;
state.showMembersModal = false;
state.showInviteModal = false;
this.state = state;
@@ -110,6 +115,16 @@ export default class Navbar extends React.Component {
this.setState(this.getStateFromStores());
$('#navbar .navbar-brand .description').popover({placement: 'bottom', trigger: 'click', html: true});
}
+ showEditChannelHeaderModal() {
+ // this can't be done using a ToggleModalButton because we can't use one inside an OverlayTrigger
+ if (this.refs.headerOverlay) {
+ this.refs.headerOverlay.hide();
+ }
+
+ this.setState({
+ showEditChannelHeaderModal: true
+ });
+ }
createDropdown(channel, channelTitle, isAdmin, isDirect, popoverContent) {
if (channel) {
var viewInfoOption = (
@@ -129,11 +144,7 @@ export default class Navbar extends React.Component {
{'Set Channel Header...'}
@@ -239,7 +250,7 @@ export default class Navbar extends React.Component {
dialogType={ChannelNotificationsModal}
dialogProps={{channel}}
>
- {'Notification Preferences'}
+ {'Notification Preferences'}
);
@@ -249,6 +260,7 @@ export default class Navbar extends React.Component {
{'Click here'}
@@ -413,6 +424,22 @@ export default class Navbar extends React.Component {
);
}
+
+ editChannelHeaderModal = (
+
this.setState({showEditChannelHeaderModal: false})}
+ channel={channel}
+ />
+ );
+
+ editChannelPurposeModal = (
+ this.setState({showEditChannelPurposeModal: false})}
+ channel={channel}
+ />
+ );
}
var collapseButtons = this.createCollapseButtons(currentId);
@@ -443,11 +470,8 @@ export default class Navbar extends React.Component {
- this.setState({showEditChannelPurposeModal: false})}
- channel={channel}
- />
+ {editChannelHeaderModal}
+ {editChannelPurposeModal}
this.setState({showMembersModal: false})}
diff --git a/web/react/components/toggle_modal_button.jsx b/web/react/components/toggle_modal_button.jsx
index eae4a024db..ce8ff3f60d 100644
--- a/web/react/components/toggle_modal_button.jsx
+++ b/web/react/components/toggle_modal_button.jsx
@@ -22,7 +22,17 @@ export default class ModalToggleButton extends React.Component {
}
render() {
- const {children, dialogType, dialogProps, ...props} = this.props; //eslint-disable-line no-redeclare
+ const {children, dialogType, dialogProps, onClick, ...props} = this.props; // eslint-disable-line no-redeclare
+
+ // allow callers to provide an onClick which will be called before the modal is shown
+ let clickHandler = this.show;
+ if (onClick) {
+ clickHandler = () => {
+ onClick();
+
+ this.show();
+ };
+ }
// this assumes that all modals will have a show property and an onHide event
const dialog = React.createElement(this.props.dialogType, Object.assign({}, dialogProps, {
@@ -42,7 +52,7 @@ export default class ModalToggleButton extends React.Component {
{children}
{dialog}
@@ -54,7 +64,8 @@ export default class ModalToggleButton extends React.Component {
ModalToggleButton.propTypes = {
children: React.PropTypes.node.isRequired,
dialogType: React.PropTypes.func.isRequired,
- dialogProps: React.PropTypes.object
+ dialogProps: React.PropTypes.object,
+ onClick: React.PropTypes.func
};
ModalToggleButton.defaultProps = {
diff --git a/web/react/pages/channel.jsx b/web/react/pages/channel.jsx
index 5cc1be741b..1c0d873d5e 100644
--- a/web/react/pages/channel.jsx
+++ b/web/react/pages/channel.jsx
@@ -8,7 +8,6 @@ import ErrorStore from '../stores/error_store.jsx';
import MentionList from '../components/mention_list.jsx';
import GetLinkModal from '../components/get_link_modal.jsx';
-import EditChannelModal from '../components/edit_channel_modal.jsx';
import RenameChannelModal from '../components/rename_channel_modal.jsx';
import EditPostModal from '../components/edit_post_modal.jsx';
import DeletePostModal from '../components/delete_post_modal.jsx';
@@ -92,11 +91,6 @@ function setupChannelPage(props, team, channel) {
document.getElementById('team_members_modal')
);
- ReactDOM.render(
- ,
- document.getElementById('edit_channel_modal')
- );
-
ReactDOM.render(
,
document.getElementById('rename_channel_modal')
diff --git a/web/react/utils/channel_intro_mssages.jsx b/web/react/utils/channel_intro_mssages.jsx
index 0bbc7366ec..4047ec0289 100644
--- a/web/react/utils/channel_intro_mssages.jsx
+++ b/web/react/utils/channel_intro_mssages.jsx
@@ -1,9 +1,10 @@
-
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import * as Utils from './utils.jsx';
+import EditChannelModal from '../components/edit_channel_modal.jsx';
import InviteMemberModal from '../components/invite_member_modal.jsx';
+import ToggleModalButton from '../components/toggle_modal_button.jsx';
import UserProfile from '../components/user_profile.jsx';
import ChannelStore from '../stores/channel_store.jsx';
import Constants from '../utils/constants.jsx';
@@ -49,17 +50,13 @@ export function createDMIntroMessage(channel) {
{'This is the start of your direct message history with ' + teammateName + '.'}
{'Direct messages and files shared here are not shown to people outside this area.'}
-
{'Set a header'}
-
+
);
}
@@ -79,17 +76,13 @@ export function createOffTopicIntroMessage(channel, showInviteModal) {
{'This is the start of ' + channel.display_name + ', a channel for non-work-related conversations.'}
-
{'Set a header'}
-
+
{inviteModalLink}
-
{'Set a header'}
-
+
);
@@ -193,17 +182,13 @@ export function createStandardIntroMessage(channel, showInviteModal) {
{memberMessage}
-
{'Set a header'}
-
+