forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MM-8338] Option to send as message when an invalid slash command is …
…entered (mattermost#1969) * general feature complete. changed functionality is scoped to create_post.jsx * textbox now keeps focus after slash command error. submitting twice will force submit the message. update create_post test * move "message submit error" into its own component * handle server error type correctly, and fix some i18n references * move tests to be next to source code * fix nested `FormattedMessage` components
- Loading branch information
1 parent
24e026c
commit 4453f86
Showing
6 changed files
with
248 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import {isErrorInvalidSlashCommand} from 'utils/post_utils.jsx'; | ||
|
||
class MessageSubmitError extends React.PureComponent { | ||
static propTypes = { | ||
error: PropTypes.object.isRequired, | ||
handleSubmit: PropTypes.func.isRequired, | ||
submittedMessage: PropTypes.string, | ||
} | ||
|
||
renderSlashCommandError = () => { | ||
if (!this.props.submittedMessage) { | ||
return this.props.error.message; | ||
} | ||
|
||
const command = this.props.submittedMessage.split(' ')[0]; | ||
return ( | ||
<React.Fragment> | ||
<FormattedMessage | ||
id='message_submit_error.invalidCommand' | ||
defaultMessage={'Command with a trigger of \'{command}\' not found. '} | ||
values={{ | ||
command, | ||
}} | ||
/> | ||
<a | ||
href='#' | ||
onClick={this.props.handleSubmit} | ||
> | ||
<FormattedMessage | ||
id='message-submit-error.sendAsMessageLink' | ||
defaultMessage='Click here to send as a message.' | ||
/> | ||
</a> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
render() { | ||
const error = this.props.error; | ||
|
||
if (!error) { | ||
return null; | ||
} | ||
|
||
let errorContent = error.message; | ||
if (isErrorInvalidSlashCommand(error)) { | ||
errorContent = this.renderSlashCommandError(); | ||
} | ||
|
||
return ( | ||
<div className='has-error'> | ||
<label className='control-label'> | ||
{errorContent} | ||
</label> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default MessageSubmitError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
|
||
import MessageSubmitError from 'components/message_submit_error.jsx'; | ||
|
||
describe('components/MessageSubmitError', () => { | ||
const baseProps = { | ||
handleSubmit: jest.fn(), | ||
}; | ||
|
||
it('should display the submit link if the error is for an invalid slash command', () => { | ||
const error = { | ||
message: 'No command found', | ||
server_error_id: 'api.command.execute_command.not_found.app_error', | ||
}; | ||
const submittedMessage = 'fakecommand some text'; | ||
|
||
const props = { | ||
...baseProps, | ||
error, | ||
submittedMessage, | ||
}; | ||
|
||
const wrapper = shallow( | ||
<MessageSubmitError {...props}/> | ||
); | ||
|
||
expect(wrapper.find('[id="message_submit_error.invalidCommand"]').exists()).toBe(true); | ||
expect(wrapper.text()).not.toEqual('No command found'); | ||
}); | ||
|
||
it('should not display the submit link if the error is not for an invalid slash command', () => { | ||
const error = { | ||
message: 'Some server error', | ||
server_error_id: 'api.other_error', | ||
}; | ||
const submittedMessage = '/fakecommand some text'; | ||
|
||
const props = { | ||
...baseProps, | ||
error, | ||
submittedMessage, | ||
}; | ||
|
||
const wrapper = shallow( | ||
<MessageSubmitError {...props}/> | ||
); | ||
|
||
expect(wrapper.find('[id="message_submit_error.invalidCommand"]').exists()).toBe(false); | ||
expect(wrapper.text()).toEqual('Some server error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters