Added ChannelSelect component
Этот коммит содержится в:
@@ -5,9 +5,9 @@ import React from 'react';
|
|||||||
|
|
||||||
import * as AsyncClient from 'utils/async_client.jsx';
|
import * as AsyncClient from 'utils/async_client.jsx';
|
||||||
import {browserHistory} from 'react-router';
|
import {browserHistory} from 'react-router';
|
||||||
import ChannelStore from 'stores/channel_store.jsx';
|
|
||||||
import TeamStore from 'stores/team_store.jsx';
|
import TeamStore from 'stores/team_store.jsx';
|
||||||
|
|
||||||
|
import ChannelSelect from 'components/channel_select.jsx';
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
import FormError from 'components/form_error.jsx';
|
import FormError from 'components/form_error.jsx';
|
||||||
import {Link} from 'react-router';
|
import {Link} from 'react-router';
|
||||||
@@ -22,13 +22,13 @@ export default class AddIncomingWebhook extends React.Component {
|
|||||||
|
|
||||||
this.updateName = this.updateName.bind(this);
|
this.updateName = this.updateName.bind(this);
|
||||||
this.updateDescription = this.updateDescription.bind(this);
|
this.updateDescription = this.updateDescription.bind(this);
|
||||||
this.updateChannelName = this.updateChannelName.bind(this);
|
this.updateChannelId = this.updateChannelId.bind(this);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
team: TeamStore.getCurrent(),
|
team: TeamStore.getCurrent(),
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
channelName: '',
|
channelId: '',
|
||||||
saving: false,
|
saving: false,
|
||||||
serverError: '',
|
serverError: '',
|
||||||
clientError: null
|
clientError: null
|
||||||
@@ -62,15 +62,13 @@ export default class AddIncomingWebhook extends React.Component {
|
|||||||
clientError: ''
|
clientError: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const channel = ChannelStore.getByName(this.state.channelName);
|
if (!this.state.channelId) {
|
||||||
|
|
||||||
if (!channel) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
saving: false,
|
saving: false,
|
||||||
clientError: (
|
clientError: (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='add_incoming_webhook.channel_name_required'
|
id='add_incoming_webhook.channel_required'
|
||||||
defaultMessage='A valid channel name (eg. town-square) is required'
|
defaultMessage='A valid channel is required'
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@@ -79,7 +77,7 @@ export default class AddIncomingWebhook extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hook = {
|
const hook = {
|
||||||
channel_id: channel.id
|
channel_id: this.state.channelId
|
||||||
};
|
};
|
||||||
|
|
||||||
AsyncClient.addIncomingHook(
|
AsyncClient.addIncomingHook(
|
||||||
@@ -107,9 +105,9 @@ export default class AddIncomingWebhook extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateChannelName(e) {
|
updateChannelId(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
channelName: e.target.value
|
channelId: e.target.value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,18 +168,17 @@ export default class AddIncomingWebhook extends React.Component {
|
|||||||
<div className='add-integration__row'>
|
<div className='add-integration__row'>
|
||||||
<label
|
<label
|
||||||
className='add-integration__label'
|
className='add-integration__label'
|
||||||
htmlFor='channelName'
|
htmlFor='channelId'
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='add-incoming-webhook.channelName'
|
id='add-incoming-webhook.channelId'
|
||||||
defaultMessage='Channel Name'
|
defaultMessage='Channel'
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<input
|
<ChannelSelect
|
||||||
id='channelName'
|
id='channelId'
|
||||||
type='text'
|
value={this.state.channelId}
|
||||||
value={this.state.channelName}
|
onChange={this.updateChannelId}
|
||||||
onChange={this.updateChannelName}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='add-integration__submit-row'>
|
<div className='add-integration__submit-row'>
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import React from 'react';
|
|||||||
|
|
||||||
import * as AsyncClient from 'utils/async_client.jsx';
|
import * as AsyncClient from 'utils/async_client.jsx';
|
||||||
import {browserHistory} from 'react-router';
|
import {browserHistory} from 'react-router';
|
||||||
import ChannelStore from 'stores/channel_store.jsx';
|
|
||||||
import TeamStore from 'stores/team_store.jsx';
|
import TeamStore from 'stores/team_store.jsx';
|
||||||
|
|
||||||
|
import ChannelSelect from 'components/channel_select.jsx';
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
import FormError from 'components/form_error.jsx';
|
import FormError from 'components/form_error.jsx';
|
||||||
import {Link} from 'react-router';
|
import {Link} from 'react-router';
|
||||||
@@ -22,7 +22,7 @@ export default class AddOutgoingWebhook extends React.Component {
|
|||||||
|
|
||||||
this.updateName = this.updateName.bind(this);
|
this.updateName = this.updateName.bind(this);
|
||||||
this.updateDescription = this.updateDescription.bind(this);
|
this.updateDescription = this.updateDescription.bind(this);
|
||||||
this.updateChannelName = this.updateChannelName.bind(this);
|
this.updateChannelId = this.updateChannelId.bind(this);
|
||||||
this.updateTriggerWords = this.updateTriggerWords.bind(this);
|
this.updateTriggerWords = this.updateTriggerWords.bind(this);
|
||||||
this.updateCallbackUrls = this.updateCallbackUrls.bind(this);
|
this.updateCallbackUrls = this.updateCallbackUrls.bind(this);
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ export default class AddOutgoingWebhook extends React.Component {
|
|||||||
team: TeamStore.getCurrent(),
|
team: TeamStore.getCurrent(),
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
channelName: '',
|
channelId: '',
|
||||||
triggerWords: '',
|
triggerWords: '',
|
||||||
callbackUrls: '',
|
callbackUrls: '',
|
||||||
saving: false,
|
saving: false,
|
||||||
@@ -66,32 +66,13 @@ export default class AddOutgoingWebhook extends React.Component {
|
|||||||
clientError: ''
|
clientError: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
let channelId = '';
|
if (!this.state.channelId || !this.state.triggerWords) {
|
||||||
if (this.state.channelName) {
|
|
||||||
const channel = ChannelStore.getByName(this.state.channelName);
|
|
||||||
|
|
||||||
if (!channel) {
|
|
||||||
this.setState({
|
|
||||||
saving: false,
|
|
||||||
clientError: (
|
|
||||||
<FormattedMessage
|
|
||||||
id='add_outgoing_webhook.channel_name_required'
|
|
||||||
defaultMessage='A valid channel name (eg. town-square) is required'
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
channelId = channel.id;
|
|
||||||
} else if (!this.state.triggerWords) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
saving: false,
|
saving: false,
|
||||||
clientError: (
|
clientError: (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='add_outgoing_webhook.trigger_words_required'
|
id='add_outgoing_webhook.trigger_words_required'
|
||||||
defaultMessage='A valid channel name or a list of trigger words is required'
|
defaultMessage='A valid channel or a list of trigger words is required'
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@@ -114,7 +95,7 @@ export default class AddOutgoingWebhook extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hook = {
|
const hook = {
|
||||||
channel_id: channelId,
|
channel_id: this.state.channelId,
|
||||||
trigger_words: this.state.triggerWords.split('\n').map((word) => word.trim()),
|
trigger_words: this.state.triggerWords.split('\n').map((word) => word.trim()),
|
||||||
callback_urls: this.state.callbackUrls.split('\n').map((url) => url.trim())
|
callback_urls: this.state.callbackUrls.split('\n').map((url) => url.trim())
|
||||||
};
|
};
|
||||||
@@ -144,9 +125,9 @@ export default class AddOutgoingWebhook extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateChannelName(e) {
|
updateChannelId(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
channelName: e.target.value
|
channelId: e.target.value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,18 +200,17 @@ export default class AddOutgoingWebhook extends React.Component {
|
|||||||
<div className='add-integration__row'>
|
<div className='add-integration__row'>
|
||||||
<label
|
<label
|
||||||
className='add-integration__label'
|
className='add-integration__label'
|
||||||
htmlFor='channelName'
|
htmlFor='channelId'
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='add-outgoing-webhook.channelName'
|
id='add-outgoing-webhook.channelId'
|
||||||
defaultMessage='Channel Name'
|
defaultMessage='Channel'
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<input
|
<ChannelSelect
|
||||||
id='channelName'
|
id='channelId'
|
||||||
type='text'
|
value={this.state.channelId}
|
||||||
value={this.state.channelName}
|
onChange={this.updateChannelId}
|
||||||
onChange={this.updateChannelName}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='add-integration__row'>
|
<div className='add-integration__row'>
|
||||||
|
|||||||
79
webapp/components/channel_select.jsx
Обычный файл
79
webapp/components/channel_select.jsx
Обычный файл
@@ -0,0 +1,79 @@
|
|||||||
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import Constants from 'utils/constants.jsx';
|
||||||
|
import ChannelStore from 'stores/channel_store.jsx';
|
||||||
|
import * as Utils from 'utils/utils.jsx';
|
||||||
|
|
||||||
|
export default class ChannelSelect extends React.Component {
|
||||||
|
static get propTypes() {
|
||||||
|
return {
|
||||||
|
onChange: React.PropTypes.func,
|
||||||
|
value: React.PropTypes.string
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.handleChannelChange = this.handleChannelChange.bind(this);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
channels: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
this.setState({
|
||||||
|
channels: ChannelStore.getAll()
|
||||||
|
});
|
||||||
|
|
||||||
|
ChannelStore.addChangeListener(this.handleChannelChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
ChannelStore.removeChangeListener(this.handleChannelChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChannelChange() {
|
||||||
|
this.setState({
|
||||||
|
channels: ChannelStore.getAll()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = [
|
||||||
|
<option
|
||||||
|
key=''
|
||||||
|
value=''
|
||||||
|
>
|
||||||
|
{Utils.localizeMessage('channel-select.select', '--- Select a channel ---')}
|
||||||
|
</option>
|
||||||
|
];
|
||||||
|
|
||||||
|
this.state.channels.forEach((channel) => {
|
||||||
|
if (channel.type !== Constants.DM_CHANNEL) {
|
||||||
|
options.push(
|
||||||
|
<option
|
||||||
|
key={channel.id}
|
||||||
|
value={channel.id}
|
||||||
|
>
|
||||||
|
{channel.display_name}
|
||||||
|
</option>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
className='form-control'
|
||||||
|
value={this.props.value}
|
||||||
|
onChange={this.props.onChange}
|
||||||
|
>
|
||||||
|
{options}
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,7 +69,9 @@ export default {
|
|||||||
RECEIVED_PREFERENCES: null,
|
RECEIVED_PREFERENCES: null,
|
||||||
RECEIVED_FILE_INFO: null,
|
RECEIVED_FILE_INFO: null,
|
||||||
RECEIVED_INCOMING_WEBHOOKS: null,
|
RECEIVED_INCOMING_WEBHOOKS: null,
|
||||||
|
RECEIVED_INCOMING_WEBHOOK: null,
|
||||||
RECEIVED_OUTGOING_WEBHOOKS: null,
|
RECEIVED_OUTGOING_WEBHOOKS: null,
|
||||||
|
RECEIVED_OUTGOING_WEBHOOK: null,
|
||||||
|
|
||||||
RECEIVED_MSG: null,
|
RECEIVED_MSG: null,
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user