mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Added delete buttons to InstalledIntegrations
This commit is contained in:
71
webapp/components/backstage/installed_incoming_webhook.jsx
Normal file
71
webapp/components/backstage/installed_incoming_webhook.jsx
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import ChannelStore from 'stores/channel_store.jsx';
|
||||
import * as Utils from 'utils/utils.jsx';
|
||||
|
||||
import {FormattedMessage} from 'react-intl';
|
||||
|
||||
export default class InstalledIncomingWebhook extends React.Component {
|
||||
static get propTypes() {
|
||||
return {
|
||||
incomingWebhook: React.PropTypes.object.isRequired,
|
||||
onDeleteClick: React.PropTypes.func.isRequired
|
||||
};
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.handleDeleteClick = this.handleDeleteClick.bind(this);
|
||||
}
|
||||
|
||||
handleDeleteClick(e) {
|
||||
e.preventDefault();
|
||||
|
||||
this.props.onDeleteClick(this.props.incomingWebhook);
|
||||
}
|
||||
|
||||
render() {
|
||||
const incomingWebhook = this.props.incomingWebhook;
|
||||
|
||||
const channel = ChannelStore.get(incomingWebhook.channel_id);
|
||||
const channelName = channel ? channel.display_name : 'cannot find channel';
|
||||
|
||||
return (
|
||||
<div className='installed-integrations__item installed-integrations__incoming-webhook'>
|
||||
<div className='details'>
|
||||
<div className='details-row'>
|
||||
<span className='name'>
|
||||
{channelName}
|
||||
</span>
|
||||
<span className='type'>
|
||||
<FormattedMessage
|
||||
id='installed_integrations.incomingWebhookType'
|
||||
defaultMessage='(Incoming Webhook)'
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
<div className='details-row'>
|
||||
<span className='description'>
|
||||
{Utils.getWindowLocationOrigin() + '/hooks/' + incomingWebhook.id}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='actions'>
|
||||
<a
|
||||
href='#'
|
||||
onClick={this.handleDeleteClick}
|
||||
>
|
||||
<FormattedMessage
|
||||
id='installed_integrations.delete'
|
||||
defaultMessage='Delete'
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import IntegrationStore from 'stores/integration_store.jsx';
|
||||
import * as Utils from 'utils/utils.jsx';
|
||||
|
||||
import {FormattedMessage} from 'react-intl';
|
||||
import InstalledIncomingWebhook from './installed_incoming_webhook.jsx';
|
||||
import InstalledOutgoingWebhook from './installed_outgoing_webhook.jsx';
|
||||
import {Link} from 'react-router';
|
||||
|
||||
export default class InstalledIntegrations extends React.Component {
|
||||
@@ -76,6 +78,14 @@ export default class InstalledIntegrations extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
deleteIncomingWebhook(incomingWebhook) {
|
||||
AsyncClient.deleteIncomingHook(incomingWebhook.id);
|
||||
}
|
||||
|
||||
deleteOutgoingWebhook(outgoingWebhook) {
|
||||
AsyncClient.deleteOutgoingHook(outgoingWebhook.id);
|
||||
}
|
||||
|
||||
renderTypeFilters(incomingWebhooks, outgoingWebhooks) {
|
||||
const fields = [];
|
||||
|
||||
@@ -194,9 +204,10 @@ export default class InstalledIntegrations extends React.Component {
|
||||
}
|
||||
|
||||
integrations.push(
|
||||
<IncomingWebhook
|
||||
<InstalledIncomingWebhook
|
||||
key={incomingWebhook.id}
|
||||
incomingWebhook={incomingWebhook}
|
||||
onDeleteClick={this.deleteIncomingWebhook}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -213,9 +224,10 @@ export default class InstalledIntegrations extends React.Component {
|
||||
}
|
||||
|
||||
integrations.push(
|
||||
<OutgoingWebhook
|
||||
<InstalledOutgoingWebhook
|
||||
key={outgoingWebhook.id}
|
||||
outgoingWebhook={outgoingWebhook}
|
||||
onDeleteClick={this.deleteOutgoingWebhook}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -266,67 +278,3 @@ export default class InstalledIntegrations extends React.Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function IncomingWebhook({incomingWebhook}) {
|
||||
const channel = ChannelStore.get(incomingWebhook.channel_id);
|
||||
const channelName = channel ? channel.display_name : 'cannot find channel';
|
||||
|
||||
return (
|
||||
<div className='installed-integrations__item installed-integrations__incoming-webhook'>
|
||||
<div className='details'>
|
||||
<div className='details-row'>
|
||||
<span className='name'>
|
||||
{channelName}
|
||||
</span>
|
||||
<span className='type'>
|
||||
<FormattedMessage
|
||||
id='installed_integrations.incomingWebhookType'
|
||||
defaultMessage='(Incoming Webhook)'
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
<div className='details-row'>
|
||||
<span className='description'>
|
||||
{Utils.getWindowLocationOrigin() + '/hooks/' + incomingWebhook.id}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
IncomingWebhook.propTypes = {
|
||||
incomingWebhook: React.PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
function OutgoingWebhook({outgoingWebhook}) {
|
||||
const channel = ChannelStore.get(outgoingWebhook.channel_id);
|
||||
const channelName = channel ? channel.display_name : 'cannot find channel';
|
||||
|
||||
return (
|
||||
<div className='installed-integrations__item installed-integrations__outgoing-webhook'>
|
||||
<div className='details'>
|
||||
<div className='details-row'>
|
||||
<span className='name'>
|
||||
{channelName}
|
||||
</span>
|
||||
<span className='type'>
|
||||
<FormattedMessage
|
||||
id='installed_integrations.outgoingWebhookType'
|
||||
defaultMessage='(Outgoing Webhook)'
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
<div className='details-row'>
|
||||
<span className='description'>
|
||||
{Utils.getWindowLocationOrigin() + '/hooks/' + outgoingWebhook.id}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
OutgoingWebhook.propTypes = {
|
||||
outgoingWebhook: React.PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
71
webapp/components/backstage/installed_outgoing_webhook.jsx
Normal file
71
webapp/components/backstage/installed_outgoing_webhook.jsx
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import ChannelStore from 'stores/channel_store.jsx';
|
||||
import * as Utils from 'utils/utils.jsx';
|
||||
|
||||
import {FormattedMessage} from 'react-intl';
|
||||
|
||||
export default class InstalledOutgoingWebhook extends React.Component {
|
||||
static get propTypes() {
|
||||
return {
|
||||
outgoingWebhook: React.PropTypes.object.isRequired,
|
||||
onDeleteClick: React.PropTypes.func.isRequired
|
||||
};
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.handleDeleteClick = this.handleDeleteClick.bind(this);
|
||||
}
|
||||
|
||||
handleDeleteClick(e) {
|
||||
e.preventDefault();
|
||||
|
||||
this.props.onDeleteClick(this.props.outgoingWebhook);
|
||||
}
|
||||
|
||||
render() {
|
||||
const outgoingWebhook = this.props.outgoingWebhook;
|
||||
|
||||
const channel = ChannelStore.get(outgoingWebhook.channel_id);
|
||||
const channelName = channel ? channel.display_name : 'cannot find channel';
|
||||
|
||||
return (
|
||||
<div className='installed-integrations__item installed-integrations__outgoing-webhook'>
|
||||
<div className='details'>
|
||||
<div className='details-row'>
|
||||
<span className='name'>
|
||||
{channelName}
|
||||
</span>
|
||||
<span className='type'>
|
||||
<FormattedMessage
|
||||
id='installed_integrations.outgoingWebhookType'
|
||||
defaultMessage='(Outgoing Webhook)'
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
<div className='details-row'>
|
||||
<span className='description'>
|
||||
{Utils.getWindowLocationOrigin() + '/hooks/' + outgoingWebhook.id}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='actions'>
|
||||
<a
|
||||
href='#'
|
||||
onClick={this.handleDeleteClick}
|
||||
>
|
||||
<FormattedMessage
|
||||
id='installed_integrations.delete'
|
||||
defaultMessage='Delete'
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,15 @@ class IntegrationStore extends EventEmitter {
|
||||
this.incomingWebhooks.push(incomingWebhook);
|
||||
}
|
||||
|
||||
removeIncomingWebhook(id) {
|
||||
for (let i = 0; i < this.incomingWebhooks.length; i++) {
|
||||
if (this.incomingWebhooks[i].id === id) {
|
||||
this.incomingWebhooks.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasReceivedOutgoingWebhooks() {
|
||||
return this.receivedIncomingWebhooks;
|
||||
}
|
||||
@@ -68,6 +77,15 @@ class IntegrationStore extends EventEmitter {
|
||||
this.outgoingWebhooks.push(outgoingWebhook);
|
||||
}
|
||||
|
||||
removeOutgoingWebhook(id) {
|
||||
for (let i = 0; i < this.outgoingWebhooks.length; i++) {
|
||||
if (this.outgoingWebhooks[i].id === id) {
|
||||
this.outgoingWebhooks.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleEventPayload(payload) {
|
||||
const action = payload.action;
|
||||
|
||||
@@ -80,6 +98,10 @@ class IntegrationStore extends EventEmitter {
|
||||
this.addIncomingWebhook(action.incomingWebhook);
|
||||
this.emitChange();
|
||||
break;
|
||||
case ActionTypes.REMOVED_INCOMING_WEBHOOK:
|
||||
this.removeIncomingWebhook(action.id);
|
||||
this.emitChange();
|
||||
break;
|
||||
case ActionTypes.RECEIVED_OUTGOING_WEBHOOKS:
|
||||
this.setOutgoingWebhooks(action.outgoingWebhooks);
|
||||
this.emitChange();
|
||||
@@ -88,6 +110,10 @@ class IntegrationStore extends EventEmitter {
|
||||
this.addOutgoingWebhook(action.outgoingWebhook);
|
||||
this.emitChange();
|
||||
break;
|
||||
case ActionTypes.REMOVED_OUTGOING_WEBHOOK:
|
||||
this.removeOutgoingWebhook(action.id);
|
||||
this.emitChange();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1213,3 +1213,33 @@ export function addOutgoingHook(hook, success, error) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteIncomingHook(id) {
|
||||
client.deleteIncomingHook(
|
||||
{id},
|
||||
() => {
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.REMOVED_INCOMING_WEBHOOK,
|
||||
id
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
dispatchError(err, 'deleteIncomingHook');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteOutgoingHook(id) {
|
||||
client.deleteOutgoingHook(
|
||||
{id},
|
||||
() => {
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.REMOVED_OUTGOING_WEBHOOK,
|
||||
id
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
dispatchError(err, 'deleteOutgoingHook');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,10 +68,13 @@ export default {
|
||||
RECEIVED_PREFERENCE: null,
|
||||
RECEIVED_PREFERENCES: null,
|
||||
RECEIVED_FILE_INFO: null,
|
||||
|
||||
RECEIVED_INCOMING_WEBHOOKS: null,
|
||||
RECEIVED_INCOMING_WEBHOOK: null,
|
||||
REMOVED_INCOMING_WEBHOOK: null,
|
||||
RECEIVED_OUTGOING_WEBHOOKS: null,
|
||||
RECEIVED_OUTGOING_WEBHOOK: null,
|
||||
REMOVED_OUTGOING_WEBHOOK: null,
|
||||
|
||||
RECEIVED_MSG: null,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user