diff options
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/components/suggestion/command_provider.jsx | 4 | ||||
-rw-r--r-- | webapp/components/suggestion/suggestion_box.jsx | 2 | ||||
-rw-r--r-- | webapp/components/textbox.jsx | 1 | ||||
-rw-r--r-- | webapp/components/user_settings/manage_command_hooks.jsx | 43 | ||||
-rw-r--r-- | webapp/utils/async_client.jsx | 9 | ||||
-rw-r--r-- | webapp/utils/client.jsx | 5 |
6 files changed, 54 insertions, 10 deletions
diff --git a/webapp/components/suggestion/command_provider.jsx b/webapp/components/suggestion/command_provider.jsx index 36860fa66..204f52483 100644 --- a/webapp/components/suggestion/command_provider.jsx +++ b/webapp/components/suggestion/command_provider.jsx @@ -37,9 +37,9 @@ CommandSuggestion.propTypes = { }; export default class CommandProvider { - handlePretextChanged(suggestionId, pretext) { + handlePretextChanged(suggestionId, pretext, channelId) { if (pretext.startsWith('/')) { - AsyncClient.getSuggestedCommands(pretext, suggestionId, CommandSuggestion); + AsyncClient.getSuggestedCommands(pretext, channelId, suggestionId, CommandSuggestion); } } } diff --git a/webapp/components/suggestion/suggestion_box.jsx b/webapp/components/suggestion/suggestion_box.jsx index e3ec63194..04e4006f1 100644 --- a/webapp/components/suggestion/suggestion_box.jsx +++ b/webapp/components/suggestion/suggestion_box.jsx @@ -111,7 +111,7 @@ export default class SuggestionBox extends React.Component { handlePretextChanged(pretext) { for (const provider of this.props.providers) { - provider.handlePretextChanged(this.suggestionId, pretext); + provider.handlePretextChanged(this.suggestionId, pretext, this.props.channelId); } } diff --git a/webapp/components/textbox.jsx b/webapp/components/textbox.jsx index 1a395072e..952026ed5 100644 --- a/webapp/components/textbox.jsx +++ b/webapp/components/textbox.jsx @@ -224,6 +224,7 @@ export default class Textbox extends React.Component { style={{visibility: this.state.preview ? 'hidden' : 'visible'}} listComponent={SuggestionList} providers={this.suggestionProviders} + channelId={this.props.channelId} /> <div ref='preview' diff --git a/webapp/components/user_settings/manage_command_hooks.jsx b/webapp/components/user_settings/manage_command_hooks.jsx index ce353ad64..4053a62aa 100644 --- a/webapp/components/user_settings/manage_command_hooks.jsx +++ b/webapp/components/user_settings/manage_command_hooks.jsx @@ -59,6 +59,7 @@ export default class ManageCommandCmds extends React.Component { this.getCmds = this.getCmds.bind(this); this.addNewCmd = this.addNewCmd.bind(this); this.emptyCmd = this.emptyCmd.bind(this); + this.updateExternalManagement = this.updateExternalManagement.bind(this); this.updateTrigger = this.updateTrigger.bind(this); this.updateURL = this.updateURL.bind(this); this.updateMethod = this.updateMethod.bind(this); @@ -99,7 +100,7 @@ export default class ManageCommandCmds extends React.Component { addNewCmd(e) { e.preventDefault(); - if (this.state.cmd.trigger === '' || this.state.cmd.url === '') { + if (this.state.cmd.url === '' || (this.state.cmd.trigger === '' && !this.state.external_management)) { return; } @@ -189,6 +190,12 @@ export default class ManageCommandCmds extends React.Component { ); } + updateExternalManagement(e) { + var cmd = this.state.cmd; + cmd.external_management = e.target.checked; + this.setState(cmd); + } + updateTrigger(e) { var cmd = this.state.cmd; cmd.trigger = e.target.value; @@ -275,6 +282,14 @@ export default class ManageCommandCmds extends React.Component { key={cmd.id} className='webhook__item webcmd__item' > + <div className='padding-top x2'> + <strong> + <FormattedMessage + id='user.settings.cmds.external_management' + defaultMessage='External management: ' + /> + </strong><span className='word-break--all'>{cmd.external_management ? this.props.intl.formatMessage(holders.autocompleteYes) : this.props.intl.formatMessage(holders.autocompleteNo)}</span> + </div> {triggerDiv} <div className='padding-top x2 webcmd__url'> <strong> @@ -416,7 +431,7 @@ export default class ManageCommandCmds extends React.Component { </div> ); - const disableButton = this.state.cmd.trigger === '' || this.state.cmd.url === ''; + const disableButton = this.state.cmd.url === '' || (this.state.cmd.trigger === '' && !this.state.external_management); return ( <div key='addCommandCmd'> @@ -436,6 +451,30 @@ export default class ManageCommandCmds extends React.Component { <div className='padding-top x2'> <label className='control-label'> <FormattedMessage + id='user.settings.cmds.external_management' + defaultMessage='External management: ' + /> + </label> + <div className='padding-top'> + <div className='checkbox'> + <label> + <input + type='checkbox' + checked={this.state.cmd.external_management} + onChange={this.updateExternalManagement} + /> + <FormattedMessage + id='user.settings.cmds.external_management_help' + defaultMessage=' Let an external integration manage commands.' + /> + </label> + </div> + </div> + </div> + + <div className='padding-top x2'> + <label className='control-label'> + <FormattedMessage id='user.settings.cmds.trigger' defaultMessage='Command Trigger Word: ' /> diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx index 9c40311cf..3e2a706d4 100644 --- a/webapp/utils/async_client.jsx +++ b/webapp/utils/async_client.jsx @@ -755,12 +755,15 @@ export function savePreferences(preferences, success, error) { ); } -export function getSuggestedCommands(command, suggestionId, component) { - client.listCommands( +export function getSuggestedCommands(command, channelId, suggestionId, component) { + client.listCommands({ + command: command, + channelId: channelId + }, (data) => { var matches = []; data.forEach((cmd) => { - if (('/' + cmd.trigger).indexOf(command) === 0) { + if (('/' + cmd.trigger).indexOf(command) === 0 || cmd.external_management) { let s = '/' + cmd.trigger; let hint = ''; if (cmd.auto_complete_hint && cmd.auto_complete_hint.length !== 0) { diff --git a/webapp/utils/client.jsx b/webapp/utils/client.jsx index 9bd62e22d..ef6d496a2 100644 --- a/webapp/utils/client.jsx +++ b/webapp/utils/client.jsx @@ -1002,12 +1002,13 @@ export function regenCommandToken(data, success, error) { }); } -export function listCommands(success, error) { +export function listCommands(data, success, error) { $.ajax({ url: '/api/v1/commands/list', dataType: 'json', contentType: 'application/json', - type: 'GET', + type: 'POST', + data: JSON.stringify(data), success, error: function onError(xhr, status, err) { var e = handleError('listCommands', xhr, status, err); |