diff options
author | Chris <ccbrown112@gmail.com> | 2017-08-29 16:14:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-29 16:14:59 -0500 |
commit | 213a072b38d29d3c3ec8e150584685b1144a7d6a (patch) | |
tree | 1da10a494e49914b0f6641db79e7dcf8ad3886f6 /webapp/components/post_view | |
parent | 59798c137584a0b7e008ec713b489929dd83a690 (diff) | |
download | chat-213a072b38d29d3c3ec8e150584685b1144a7d6a.tar.gz chat-213a072b38d29d3c3ec8e150584685b1144a7d6a.tar.bz2 chat-213a072b38d29d3c3ec8e150584685b1144a7d6a.zip |
PLT-6403: Interactive messages (#7274)
* wip
* finish first pass
* requested changes
* add DoPostAction to Client4
Diffstat (limited to 'webapp/components/post_view')
-rw-r--r-- | webapp/components/post_view/post_attachment.jsx | 46 | ||||
-rw-r--r-- | webapp/components/post_view/post_attachment_list.jsx | 6 | ||||
-rw-r--r-- | webapp/components/post_view/post_body_additional_content.jsx | 1 |
3 files changed, 53 insertions, 0 deletions
diff --git a/webapp/components/post_view/post_attachment.jsx b/webapp/components/post_view/post_attachment.jsx index 36fe3bf9f..cc7aa509c 100644 --- a/webapp/components/post_view/post_attachment.jsx +++ b/webapp/components/post_view/post_attachment.jsx @@ -4,6 +4,8 @@ import * as TextFormatting from 'utils/text_formatting.jsx'; import {localizeMessage} from 'utils/utils.jsx'; +import * as PostActions from 'actions/post_actions.jsx'; + import $ from 'jquery'; import React from 'react'; import PropTypes from 'prop-types'; @@ -12,6 +14,11 @@ export default class PostAttachment extends React.PureComponent { static propTypes = { /** + * The post id + */ + postId: PropTypes.string.isRequired, + + /** * The attachment to render */ attachment: PropTypes.object.isRequired @@ -20,6 +27,8 @@ export default class PostAttachment extends React.PureComponent { constructor(props) { super(props); + this.handleActionButtonClick = this.handleActionButtonClick.bind(this); + this.getActionView = this.getActionView.bind(this); this.getFieldsTable = this.getFieldsTable.bind(this); this.getInitState = this.getInitState.bind(this); this.shouldCollapse = this.shouldCollapse.bind(this); @@ -80,6 +89,41 @@ export default class PostAttachment extends React.PureComponent { return TextFormatting.formatText(text) + `<div><a class="attachment-link-more" href="#">${localizeMessage('post_attachment.more', 'Show more...')}</a></div>`; } + getActionView() { + const actions = this.props.attachment.actions; + if (!actions || !actions.length) { + return ''; + } + + const buttons = []; + + actions.forEach((action) => { + if (!action.id || !action.name) { + return; + } + buttons.push( + <button + key={action.id} + onClick={() => this.handleActionButtonClick(action.id)} + > + {action.name} + </button> + ); + }); + + return ( + <div + className='attachment-actions' + > + {buttons} + </div> + ); + } + + handleActionButtonClick(actionId) { + PostActions.doPostAction(this.props.postId, actionId); + } + getFieldsTable() { const fields = this.props.attachment.fields; if (!fields || !fields.length) { @@ -275,6 +319,7 @@ export default class PostAttachment extends React.PureComponent { } const fields = this.getFieldsTable(); + const actions = this.getActionView(); let useBorderStyle; if (data.color && data.color[0] === '#') { @@ -301,6 +346,7 @@ export default class PostAttachment extends React.PureComponent { {text} {image} {fields} + {actions} </div> {thumb} <div style={{clear: 'both'}}/> diff --git a/webapp/components/post_view/post_attachment_list.jsx b/webapp/components/post_view/post_attachment_list.jsx index cfd2f81f8..ce60a0155 100644 --- a/webapp/components/post_view/post_attachment_list.jsx +++ b/webapp/components/post_view/post_attachment_list.jsx @@ -10,6 +10,11 @@ export default class PostAttachmentList extends React.PureComponent { static propTypes = { /** + * The post id + */ + postId: PropTypes.string.isRequired, + + /** * Array of attachments to render */ attachments: PropTypes.array.isRequired @@ -21,6 +26,7 @@ export default class PostAttachmentList extends React.PureComponent { content.push( <PostAttachment attachment={attachment} + postId={this.props.postId} key={'att_' + i} /> ); diff --git a/webapp/components/post_view/post_body_additional_content.jsx b/webapp/components/post_view/post_body_additional_content.jsx index ddc73d554..88e8f2ba8 100644 --- a/webapp/components/post_view/post_body_additional_content.jsx +++ b/webapp/components/post_view/post_body_additional_content.jsx @@ -90,6 +90,7 @@ export default class PostBodyAdditionalContent extends React.PureComponent { return ( <PostAttachmentList attachments={attachments} + postId={this.props.post.id} key={this.props.post.id} /> ); |