From b3edd32aee47a0b123870de58664600acc17087b Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 5 Apr 2016 09:29:01 -0400 Subject: PLT-1750 Moved slash commands to backstage * Added slash commands to InstalledIntegrations page * Reset installed integration type filter if there is no longer any integrations of the selected type * Added pages to backstage to add slash commands * Cleaned up internationalization for slash commands * Added ability to regen slash command tokens from backstage * Removed Integrations tab from UserSettings --- webapp/components/backstage/add_command.jsx | 509 +++++++++++++++ webapp/components/backstage/add_integration.jsx | 22 + webapp/components/backstage/backstage_sidebar.jsx | 9 + webapp/components/backstage/installed_command.jsx | 97 +++ .../backstage/installed_incoming_webhook.jsx | 10 +- .../backstage/installed_integrations.jsx | 104 +++- .../user_settings/manage_command_hooks.jsx | 681 --------------------- webapp/components/user_settings/user_settings.jsx | 15 - .../user_settings/user_settings_integrations.jsx | 126 ---- .../user_settings/user_settings_modal.jsx | 17 - 10 files changed, 740 insertions(+), 850 deletions(-) create mode 100644 webapp/components/backstage/add_command.jsx create mode 100644 webapp/components/backstage/installed_command.jsx delete mode 100644 webapp/components/user_settings/manage_command_hooks.jsx delete mode 100644 webapp/components/user_settings/user_settings_integrations.jsx (limited to 'webapp/components') diff --git a/webapp/components/backstage/add_command.jsx b/webapp/components/backstage/add_command.jsx new file mode 100644 index 000000000..93ff66271 --- /dev/null +++ b/webapp/components/backstage/add_command.jsx @@ -0,0 +1,509 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import React from 'react'; + +import * as AsyncClient from 'utils/async_client.jsx'; +import {browserHistory} from 'react-router'; +import * as Utils from 'utils/utils.jsx'; + +import {FormattedMessage} from 'react-intl'; +import FormError from 'components/form_error.jsx'; +import {Link} from 'react-router'; +import SpinnerButton from 'components/spinner_button.jsx'; + +const REQUEST_POST = 'P'; +const REQUEST_GET = 'G'; + +export default class AddCommand extends React.Component { + constructor(props) { + super(props); + + this.handleSubmit = this.handleSubmit.bind(this); + + this.updateDisplayName = this.updateDisplayName.bind(this); + this.updateDescription = this.updateDescription.bind(this); + this.updateTrigger = this.updateTrigger.bind(this); + this.updateUrl = this.updateUrl.bind(this); + this.updateMethod = this.updateMethod.bind(this); + this.updateUsername = this.updateUsername.bind(this); + this.updateIconUrl = this.updateIconUrl.bind(this); + this.updateAutocomplete = this.updateAutocomplete.bind(this); + this.updateAutocompleteHint = this.updateAutocompleteHint.bind(this); + this.updateAutocompleteDescription = this.updateAutocompleteDescription.bind(this); + + this.state = { + displayName: '', + description: '', + trigger: '', + url: '', + method: REQUEST_POST, + username: '', + iconUrl: '', + autocomplete: false, + autocompleteHint: '', + autocompleteDescription: '', + saving: false, + serverError: '', + clientError: null + }; + } + + handleSubmit(e) { + e.preventDefault(); + + if (this.state.saving) { + return; + } + + this.setState({ + saving: true, + serverError: '', + clientError: '' + }); + + const command = { + display_name: this.state.displayName, + description: this.state.description, + trigger: this.state.trigger.trim(), + url: this.state.url.trim(), + method: this.state.method, + username: this.state.username, + icon_url: this.state.iconUrl, + auto_complete: this.state.autocomplete + }; + + if (command.auto_complete) { + command.auto_complete_desc = this.state.autocompleteDescription; + command.auto_complete_hint = this.state.autocompleteHint; + } + + if (!command.trigger) { + this.setState({ + saving: false, + clientError: ( + + ) + }); + } + + if (!command.url) { + this.setState({ + saving: false, + clientError: ( + + ) + }); + } + + AsyncClient.addCommand( + command, + () => { + browserHistory.push('/settings/integrations/installed'); + }, + (err) => { + this.setState({ + saving: false, + serverError: err.message + }); + } + ); + } + + updateDisplayName(e) { + this.setState({ + displayName: e.target.value + }); + } + + updateDescription(e) { + this.setState({ + description: e.target.value + }); + } + + updateTrigger(e) { + this.setState({ + trigger: e.target.value + }); + } + + updateUrl(e) { + this.setState({ + url: e.target.value + }); + } + + updateMethod(e) { + this.setState({ + method: e.target.value + }); + } + + updateUsername(e) { + this.setState({ + username: e.target.value + }); + } + + updateIconUrl(e) { + this.setState({ + iconUrl: e.target.value + }); + } + + updateAutocomplete(e) { + this.setState({ + autocomplete: e.target.checked + }); + } + + updateAutocompleteHint(e) { + this.setState({ + autocompleteHint: e.target.value + }); + } + + updateAutocompleteDescription(e) { + this.setState({ + autocompleteDescription: e.target.value + }); + } + + render() { + let autocompleteFields = null; + if (this.state.autocomplete) { + autocompleteFields = [( +
+ +
+ +
+ +
+
+
+ ), + ( +
+ +
+ +
+ +
+
+
+ )]; + } + + return ( +
+
+
+

+ +

+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+ {autocompleteFields} +
+ + + + + + + +
+
+
+
+ ); + } +} diff --git a/webapp/components/backstage/add_integration.jsx b/webapp/components/backstage/add_integration.jsx index 5f4a69bfe..0ab36e101 100644 --- a/webapp/components/backstage/add_integration.jsx +++ b/webapp/components/backstage/add_integration.jsx @@ -56,6 +56,28 @@ export default class AddIntegration extends React.Component { ); } + if (window.mm_config.EnableCommands === 'true') { + options.push( + + } + description={ + + } + link={'/settings/integrations/add/command'} + /> + ); + } + return (
diff --git a/webapp/components/backstage/backstage_sidebar.jsx b/webapp/components/backstage/backstage_sidebar.jsx index 13c4f8b50..172119b32 100644 --- a/webapp/components/backstage/backstage_sidebar.jsx +++ b/webapp/components/backstage/backstage_sidebar.jsx @@ -59,6 +59,15 @@ export default class BackstageSidebar extends React.Component { /> )} /> + + )} + /> diff --git a/webapp/components/backstage/installed_command.jsx b/webapp/components/backstage/installed_command.jsx new file mode 100644 index 000000000..51adce160 --- /dev/null +++ b/webapp/components/backstage/installed_command.jsx @@ -0,0 +1,97 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import React from 'react'; + +import * as Utils from 'utils/utils.jsx'; + +import {FormattedMessage} from 'react-intl'; + +export default class InstalledCommand extends React.Component { + static get propTypes() { + return { + command: React.PropTypes.object.isRequired, + onRegenToken: React.PropTypes.func.isRequired, + onDelete: React.PropTypes.func.isRequired + }; + } + + constructor(props) { + super(props); + + this.handleRegenToken = this.handleRegenToken.bind(this); + this.handleDelete = this.handleDelete.bind(this); + } + + handleRegenToken(e) { + e.preventDefault(); + + this.props.onRegenToken(this.props.command); + } + + handleDelete(e) { + e.preventDefault(); + + this.props.onDelete(this.props.command); + } + + render() { + const command = this.props.command; + + return ( +
+
+
+ + {command.display_name} + + + + +
+
+ + {command.description} + +
+
+ + + +
+
+
+ + + + {' - '} + + + +
+
+ ); + } +} diff --git a/webapp/components/backstage/installed_incoming_webhook.jsx b/webapp/components/backstage/installed_incoming_webhook.jsx index 95a303edc..cd9a6d761 100644 --- a/webapp/components/backstage/installed_incoming_webhook.jsx +++ b/webapp/components/backstage/installed_incoming_webhook.jsx @@ -12,20 +12,20 @@ export default class InstalledIncomingWebhook extends React.Component { static get propTypes() { return { incomingWebhook: React.PropTypes.object.isRequired, - onDeleteClick: React.PropTypes.func.isRequired + onDelete: React.PropTypes.func.isRequired }; } constructor(props) { super(props); - this.handleDeleteClick = this.handleDeleteClick.bind(this); + this.handleDelete = this.handleDelete.bind(this); } - handleDeleteClick(e) { + handleDelete(e) { e.preventDefault(); - this.props.onDeleteClick(this.props.incomingWebhook); + this.props.onDelete(this.props.incomingWebhook); } render() { @@ -69,7 +69,7 @@ export default class InstalledIncomingWebhook extends React.Component {
0 || outgoingWebhooks.length > 0) { + if (incomingWebhooks.length > 0 || outgoingWebhooks.length > 0 || commands.length > 0) { let filterClassName = 'filter-sort'; if (this.state.typeFilter === '') { filterClassName += ' filter-sort--active'; @@ -187,6 +223,39 @@ export default class InstalledIntegrations extends React.Component { ); } + if (commands.length > 0) { + fields.push( + + {'|'} + + ); + + let filterClassName = 'filter-sort'; + if (this.state.typeFilter === 'commands') { + filterClassName += ' filter-sort--active'; + } + + fields.push( + this.updateTypeFilter(e, 'commands')} + > + + + ); + } + return (
{fields} @@ -197,7 +266,9 @@ export default class InstalledIntegrations extends React.Component { render() { const incomingWebhooks = this.state.incomingWebhooks; const outgoingWebhooks = this.state.outgoingWebhooks; + const commands = this.state.commands; + // TODO description, name, creator filtering const filter = this.state.filter.toLowerCase(); const integrations = []; @@ -215,7 +286,7 @@ export default class InstalledIntegrations extends React.Component { ); } @@ -242,6 +313,27 @@ export default class InstalledIntegrations extends React.Component { } } + if (!this.state.typeFilter || this.state.typeFilter === 'commands') { + for (const command of commands) { + if (filter) { + const channel = ChannelStore.get(command.channel_id); + + if (!channel || channel.name.toLowerCase().indexOf(filter) === -1) { + continue; + } + } + + integrations.push( + + ); + } + } + return (
@@ -270,7 +362,7 @@ export default class InstalledIntegrations extends React.Component {
- {this.renderTypeFilters(this.state.incomingWebhooks, this.state.outgoingWebhooks)} + {this.renderTypeFilters(incomingWebhooks, outgoingWebhooks, commands)}
{ - let cmds = Object.assign([], this.state.cmds); - if (!cmds) { - cmds = []; - } - cmds.push(data); - this.setState({cmds, addError: null, cmd: this.emptyCmd()}); - }, - (err) => { - this.setState({addError: err.message}); - } - ); - } - - removeCmd(id) { - const data = {}; - data.id = id; - - Client.deleteCommand( - data, - () => { - const cmds = this.state.cmds; - let index = -1; - for (let i = 0; i < cmds.length; i++) { - if (cmds[i].id === id) { - index = i; - break; - } - } - - if (index !== -1) { - cmds.splice(index, 1); - } - - this.setState({cmds}); - }, - (err) => { - this.setState({editError: err.message}); - } - ); - } - - regenToken(id) { - const regenData = {}; - regenData.id = id; - - Client.regenCommandToken( - regenData, - (data) => { - const cmds = Object.assign([], this.state.cmds); - for (let i = 0; i < cmds.length; i++) { - if (cmds[i].id === id) { - cmds[i] = data; - break; - } - } - - this.setState({cmds, editError: null}); - }, - (err) => { - this.setState({editError: err.message}); - } - ); - } - - getCmds() { - Client.listTeamCommands( - (data) => { - if (data) { - this.setState({cmds: data, getCmdsComplete: true, editError: null}); - } - }, - (err) => { - this.setState({editError: err.message}); - } - ); - } - - updateTrigger(e) { - var cmd = this.state.cmd; - cmd.trigger = e.target.value; - this.setState(cmd); - } - - updateURL(e) { - var cmd = this.state.cmd; - cmd.url = e.target.value; - this.setState(cmd); - } - - updateMethod(e) { - var cmd = this.state.cmd; - cmd.method = e.target.value; - this.setState(cmd); - } - - updateUsername(e) { - var cmd = this.state.cmd; - cmd.username = e.target.value; - this.setState(cmd); - } - - updateIconURL(e) { - var cmd = this.state.cmd; - cmd.icon_url = e.target.value; - this.setState(cmd); - } - - updateDisplayName(e) { - var cmd = this.state.cmd; - cmd.display_name = e.target.value; - this.setState(cmd); - } - - updateAutoComplete(e) { - var cmd = this.state.cmd; - cmd.auto_complete = e.target.checked; - this.setState(cmd); - } - - updateAutoCompleteDesc(e) { - var cmd = this.state.cmd; - cmd.auto_complete_desc = e.target.value; - this.setState(cmd); - } - - updateAutoCompleteHint(e) { - var cmd = this.state.cmd; - cmd.auto_complete_hint = e.target.value; - this.setState(cmd); - } - - render() { - let addError; - if (this.state.addError) { - addError = ; - } - - let editError; - if (this.state.editError) { - addError = ; - } - - const cmds = []; - this.state.cmds.forEach((cmd) => { - let triggerDiv; - if (cmd.trigger && cmd.trigger.length !== 0) { - triggerDiv = ( -
- - - {cmd.trigger} -
- ); - } - - cmds.push( -
- {triggerDiv} -
- - - {cmd.url} -
-
- - - - - { - cmd.method === 'P' ? - : - - } - -
-
- - - {cmd.username} -
-
- - - {cmd.icon_url} -
-
- - - {cmd.auto_complete ? this.props.intl.formatMessage(holders.autocompleteYes) : this.props.intl.formatMessage(holders.autocompleteNo)} -
-
- - - {cmd.auto_complete_hint} -
-
- - - {cmd.auto_complete_desc} -
-
- - - {cmd.display_name} -
-
- - - {cmd.token} -
- -
-
- ); - }); - - let displayCmds; - if (!this.state.getCmdsComplete) { - displayCmds = ; - } else if (cmds.length > 0) { - displayCmds = cmds; - } else { - displayCmds = ( -
- -
- ); - } - - const existingCmds = ( -
- -
-
- {displayCmds} -
-
- ); - - const disableButton = this.state.cmd.trigger === '' || this.state.cmd.url === ''; - - return ( -
- -
-
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
-
- -
- -
-
- -
-
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
-
- -
- -
- -
-
- -
- {addError} -
- -
- - - -
-
- {existingCmds} - {editError} -
- ); - } -} - -export default injectIntl(ManageCommandCmds); diff --git a/webapp/components/user_settings/user_settings.jsx b/webapp/components/user_settings/user_settings.jsx index 904232da9..d89298cfb 100644 --- a/webapp/components/user_settings/user_settings.jsx +++ b/webapp/components/user_settings/user_settings.jsx @@ -7,7 +7,6 @@ import NotificationsTab from './user_settings_notifications.jsx'; import SecurityTab from './user_settings_security.jsx'; import GeneralTab from './user_settings_general.jsx'; import DeveloperTab from './user_settings_developer.jsx'; -import IntegrationsTab from './user_settings_integrations.jsx'; import DisplayTab from './user_settings_display.jsx'; import AdvancedTab from './user_settings_advanced.jsx'; @@ -98,20 +97,6 @@ export default class UserSettings extends React.Component { />
); - } else if (this.props.activeTab === 'integrations') { - return ( -
- -
- ); } else if (this.props.activeTab === 'display') { return (
diff --git a/webapp/components/user_settings/user_settings_integrations.jsx b/webapp/components/user_settings/user_settings_integrations.jsx deleted file mode 100644 index 37081b863..000000000 --- a/webapp/components/user_settings/user_settings_integrations.jsx +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import $ from 'jquery'; -import SettingItemMin from '../setting_item_min.jsx'; -import SettingItemMax from '../setting_item_max.jsx'; -import ManageCommandHooks from './manage_command_hooks.jsx'; - -import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl'; - -const holders = defineMessages({ - cmdName: { - id: 'user.settings.integrations.commands', - defaultMessage: 'Slash Commands' - }, - cmdDesc: { - id: 'user.settings.integrations.commandsDescription', - defaultMessage: 'Manage your slash commands' - } -}); - -import React from 'react'; - -class UserSettingsIntegrationsTab extends React.Component { - constructor(props) { - super(props); - - this.updateSection = this.updateSection.bind(this); - - this.state = {}; - } - updateSection(section) { - $('.settings-modal .modal-body').scrollTop(0).perfectScrollbar('update'); - this.props.updateSection(section); - } - render() { - let commandHooksSection; - var inputs = []; - const {formatMessage} = this.props.intl; - - if (global.window.mm_config.EnableCommands === 'true') { - if (this.props.activeSection === 'command-hooks') { - inputs.push( - - ); - - commandHooksSection = ( - { - this.updateSection(''); - e.preventDefault(); - }} - /> - ); - } else { - commandHooksSection = ( - { - this.updateSection('command-hooks'); - }} - /> - ); - } - } - - return ( -
-
- -

-
- -
- -

-
-
-

- -

-
- {commandHooksSection} -
-
-
- ); - } -} - -UserSettingsIntegrationsTab.propTypes = { - intl: intlShape.isRequired, - user: React.PropTypes.object, - updateSection: React.PropTypes.func, - updateTab: React.PropTypes.func, - activeSection: React.PropTypes.string, - closeModal: React.PropTypes.func.isRequired, - collapseModal: React.PropTypes.func.isRequired -}; - -export default injectIntl(UserSettingsIntegrationsTab); diff --git a/webapp/components/user_settings/user_settings_modal.jsx b/webapp/components/user_settings/user_settings_modal.jsx index b71547baf..43fb728bd 100644 --- a/webapp/components/user_settings/user_settings_modal.jsx +++ b/webapp/components/user_settings/user_settings_modal.jsx @@ -31,10 +31,6 @@ const holders = defineMessages({ id: 'user.settings.modal.developer', defaultMessage: 'Developer' }, - integrations: { - id: 'user.settings.modal.integrations', - defaultMessage: 'Integrations' - }, display: { id: 'user.settings.modal.display', defaultMessage: 'Display' @@ -227,7 +223,6 @@ class UserSettingsModal extends React.Component { if (this.state.currentUser == null) { return (
); } - var isAdmin = Utils.isAdmin(this.state.currentUser.roles); var tabs = []; tabs.push({name: 'general', uiName: formatMessage(holders.general), icon: 'glyphicon glyphicon-cog'}); @@ -237,18 +232,6 @@ class UserSettingsModal extends React.Component { tabs.push({name: 'developer', uiName: formatMessage(holders.developer), icon: 'glyphicon glyphicon-th'}); } - if (global.window.mm_config.EnableIncomingWebhooks === 'true' || global.window.mm_config.EnableOutgoingWebhooks === 'true' || global.window.mm_config.EnableCommands === 'true') { - var show = global.window.mm_config.EnableOnlyAdminIntegrations !== 'true'; - - if (global.window.mm_config.EnableOnlyAdminIntegrations === 'true' && isAdmin) { - show = true; - } - - if (show) { - tabs.push({name: 'integrations', uiName: formatMessage(holders.integrations), icon: 'glyphicon glyphicon-transfer'}); - } - } - tabs.push({name: 'display', uiName: formatMessage(holders.display), icon: 'glyphicon glyphicon-eye-open'}); tabs.push({name: 'advanced', uiName: formatMessage(holders.advanced), icon: 'glyphicon glyphicon-list-alt'}); -- cgit v1.2.3-1-g7c22