Added ability to regenerate outgoing webhook tokens on InstalledIntegrations page

Этот коммит содержится в:
Harrison Healey
2016-03-29 10:04:53 -04:00
родитель fcd8f2e2ba
Коммит 149c72cf8c
5 изменённых файлов: 64 добавлений и 6 удалений

Просмотреть файл

@@ -21,6 +21,10 @@ export default class InstalledIntegrations extends React.Component {
this.updateFilter = this.updateFilter.bind(this);
this.updateTypeFilter = this.updateTypeFilter.bind(this);
this.deleteIncomingWebhook = this.deleteIncomingWebhook.bind(this);
this.regenOutgoingWebhookToken = this.regenOutgoingWebhookToken.bind(this);
this.deleteOutgoingWebhook = this.deleteOutgoingWebhook.bind(this);
this.state = {
incomingWebhooks: [],
outgoingWebhooks: [],
@@ -82,6 +86,10 @@ export default class InstalledIntegrations extends React.Component {
AsyncClient.deleteIncomingHook(incomingWebhook.id);
}
regenOutgoingWebhookToken(outgoingWebhook) {
AsyncClient.regenOutgoingHookToken(outgoingWebhook.id);
}
deleteOutgoingWebhook(outgoingWebhook) {
AsyncClient.deleteOutgoingHook(outgoingWebhook.id);
}
@@ -227,7 +235,8 @@ export default class InstalledIntegrations extends React.Component {
<InstalledOutgoingWebhook
key={outgoingWebhook.id}
outgoingWebhook={outgoingWebhook}
onDeleteClick={this.deleteOutgoingWebhook}
onRegenToken={this.regenOutgoingWebhookToken}
onDelete={this.deleteOutgoingWebhook}
/>
);
}

Просмотреть файл

@@ -12,20 +12,28 @@ export default class InstalledOutgoingWebhook extends React.Component {
static get propTypes() {
return {
outgoingWebhook: React.PropTypes.object.isRequired,
onDeleteClick: React.PropTypes.func.isRequired
onRegenToken: React.PropTypes.func.isRequired,
onDelete: React.PropTypes.func.isRequired
};
}
constructor(props) {
super(props);
this.handleDeleteClick = this.handleDeleteClick.bind(this);
this.handleRegenToken = this.handleRegenToken.bind(this);
this.handleDelete = this.handleDelete.bind(this);
}
handleDeleteClick(e) {
handleRegenToken(e) {
e.preventDefault();
this.props.onDeleteClick(this.props.outgoingWebhook);
this.props.onRegenToken(this.props.outgoingWebhook);
}
handleDelete(e) {
e.preventDefault();
this.props.onDelete(this.props.outgoingWebhook);
}
render() {
@@ -51,13 +59,25 @@ export default class InstalledOutgoingWebhook extends React.Component {
<div className='details-row'>
<span className='description'>
{Utils.getWindowLocationOrigin() + '/hooks/' + outgoingWebhook.id}
{' - '}
{outgoingWebhook.token}
</span>
</div>
</div>
<div className='actions'>
<a
href='#'
onClick={this.handleDeleteClick}
onClick={this.handleRegenToken}
>
<FormattedMessage
id='installed_integrations.regenToken'
defaultMessage='Regen Token'
/>
</a>
{' - '}
<a
href='#'
onClick={this.handleDelete}
>
<FormattedMessage
id='installed_integrations.delete'

Просмотреть файл

@@ -77,6 +77,15 @@ class IntegrationStore extends EventEmitter {
this.outgoingWebhooks.push(outgoingWebhook);
}
updateOutgoingWebhook(outgoingWebhook) {
for (let i = 0; i < this.outgoingWebhooks.length; i++) {
if (this.outgoingWebhooks[i].id === outgoingWebhook.id) {
this.outgoingWebhooks[i] = outgoingWebhook;
break;
}
}
}
removeOutgoingWebhook(id) {
for (let i = 0; i < this.outgoingWebhooks.length; i++) {
if (this.outgoingWebhooks[i].id === id) {
@@ -110,6 +119,10 @@ class IntegrationStore extends EventEmitter {
this.addOutgoingWebhook(action.outgoingWebhook);
this.emitChange();
break;
case ActionTypes.UPDATED_OUTGOING_WEBHOOK:
this.updateOutgoingWebhook(action.outgoingWebhook);
this.emitChange();
break;
case ActionTypes.REMOVED_OUTGOING_WEBHOOK:
this.removeOutgoingWebhook(action.id);
this.emitChange();

Просмотреть файл

@@ -1243,3 +1243,18 @@ export function deleteOutgoingHook(id) {
}
);
}
export function regenOutgoingHookToken(id) {
client.regenOutgoingHookToken(
{id},
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.UPDATED_OUTGOING_WEBHOOK,
outgoingWebhook: data
});
},
(err) => {
dispatchError(err, 'regenOutgoingHookToken');
}
);
}

Просмотреть файл

@@ -74,6 +74,7 @@ export default {
REMOVED_INCOMING_WEBHOOK: null,
RECEIVED_OUTGOING_WEBHOOKS: null,
RECEIVED_OUTGOING_WEBHOOK: null,
UPDATED_OUTGOING_WEBHOOK: null,
REMOVED_OUTGOING_WEBHOOK: null,
RECEIVED_MSG: null,