-
-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from plone/tags-commenting-sharing
Added social sharing.
- Loading branch information
Showing
18 changed files
with
1,146 additions
and
18 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
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,140 @@ | ||
/** | ||
* Comment edit modal. | ||
* @module components/theme/Comments/CommentEditModal | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import { defineMessages, injectIntl, intlShape } from 'react-intl'; | ||
|
||
import { editComment } from '../../../actions'; | ||
import { ModalForm } from '../../../components'; | ||
|
||
const messages = defineMessages({ | ||
editComment: { | ||
id: 'Edit comment', | ||
defaultMessage: 'Edit comment', | ||
}, | ||
default: { | ||
id: 'Default', | ||
defaultMessage: 'Default', | ||
}, | ||
comment: { | ||
id: 'Comment', | ||
defaultMessage: 'Comment', | ||
}, | ||
}); | ||
|
||
@injectIntl | ||
@connect( | ||
state => ({ | ||
request: state.comments.edit, | ||
}), | ||
dispatch => bindActionCreators({ editComment }, dispatch), | ||
) | ||
/** | ||
* CommentEditModal class. | ||
* @class CommentEditModal | ||
* @extends Component | ||
*/ | ||
export default class CommentEditModal extends Component { | ||
/** | ||
* Property types. | ||
* @property {Object} propTypes Property types. | ||
* @static | ||
*/ | ||
static propTypes = { | ||
editComment: PropTypes.func.isRequired, | ||
id: PropTypes.string, | ||
text: PropTypes.string, | ||
request: PropTypes.shape({ | ||
loading: PropTypes.bool, | ||
loaded: PropTypes.bool, | ||
}).isRequired, | ||
open: PropTypes.bool.isRequired, | ||
onOk: PropTypes.func.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
/** | ||
* Default properties. | ||
* @property {Object} defaultProps Default properties. | ||
* @static | ||
*/ | ||
static defaultProps = { | ||
id: '', | ||
text: '', | ||
}; | ||
|
||
/** | ||
* Constructor | ||
* @method constructor | ||
* @param {Object} props Component properties | ||
* @constructs CommentEditModal | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
this.onSubmit = this.onSubmit.bind(this); | ||
} | ||
|
||
/** | ||
* Component will receive props | ||
* @method componentWillReceiveProps | ||
* @param {Object} nextProps Next properties | ||
* @returns {undefined} | ||
*/ | ||
componentWillReceiveProps(nextProps) { | ||
if (this.props.request.loading && nextProps.request.loaded) { | ||
this.props.onOk(); | ||
} | ||
} | ||
|
||
/** | ||
* Submit handler | ||
* @method onSubmit | ||
* @param {Object} data Form data | ||
* @returns {undefined} | ||
*/ | ||
onSubmit(data) { | ||
this.props.editComment(this.props.id, data.text); | ||
} | ||
|
||
/** | ||
* Render method. | ||
* @method render | ||
* @returns {string} Markup for the component. | ||
*/ | ||
render() { | ||
return ( | ||
this.props.open && ( | ||
<ModalForm | ||
open={this.props.open} | ||
onSubmit={this.onSubmit} | ||
onCancel={this.props.onCancel} | ||
formData={{ text: this.props.text }} | ||
title={this.props.intl.formatMessage(messages.editComment)} | ||
schema={{ | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: this.props.intl.formatMessage(messages.default), | ||
fields: ['text'], | ||
}, | ||
], | ||
properties: { | ||
text: { | ||
title: this.props.intl.formatMessage(messages.comment), | ||
type: 'string', | ||
description: '', | ||
}, | ||
}, | ||
required: ['text'], | ||
}} | ||
/> | ||
) | ||
); | ||
} | ||
} |
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,42 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import configureStore from 'redux-mock-store'; | ||
import { Provider } from 'react-intl-redux'; | ||
|
||
import CommentEditModal from './CommentEditModal'; | ||
|
||
const mockStore = configureStore(); | ||
|
||
jest.mock('../../manage/Form/ModalForm', () => | ||
jest.fn(() => <div id="modalform" />), | ||
); | ||
|
||
describe('CommentEditModal', () => { | ||
it('renders a comment edit modal component', () => { | ||
const store = mockStore({ | ||
comments: { | ||
edit: { | ||
loading: false, | ||
loaded: true, | ||
}, | ||
}, | ||
intl: { | ||
locale: 'en', | ||
messages: {}, | ||
}, | ||
}); | ||
const component = renderer.create( | ||
<Provider store={store}> | ||
<CommentEditModal | ||
open | ||
onOk={() => {}} | ||
onCancel={() => {}} | ||
id="someurl" | ||
text="Comment body" | ||
/> | ||
</Provider>, | ||
); | ||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.