charCount ? `${name}-char-max` : ''}`}>
- {
- charCount &&
- `${charCount - length} ${lang.t('characters-remaining')}`
- }
+ {charCount && `${charCount - length} ${lang.t('characters-remaining')}`}
+
{
isReply && (
)
}
{ authorId && (
)
@@ -129,6 +185,20 @@ class CommentBox extends Component {
}
}
-export default CommentBox;
+CommentBox.propTypes = {
+ commentPostedHandler: PropTypes.func,
+ postItem: PropTypes.func.isRequired,
+ cancelButtonClicked: PropTypes.func,
+ assetId: PropTypes.string.isRequired,
+ parentId: PropTypes.string,
+ authorId: PropTypes.string.isRequired,
+ isReply: PropTypes.bool.isRequired,
+ canPost: PropTypes.bool,
+ currentUser: PropTypes.object
+};
+
+const mapStateToProps = ({commentBox}) => ({commentBox});
+
+export default connect(mapStateToProps, null)(CommentBox);
const lang = new I18n(translations);
diff --git a/client/coral-plugin-commentbox/actions.js b/client/coral-plugin-commentbox/actions.js
new file mode 100644
index 000000000..46bcf4b1b
--- /dev/null
+++ b/client/coral-plugin-commentbox/actions.js
@@ -0,0 +1,9 @@
+export const addTag = tag => ({
+ type: 'ADD_TAG',
+ tag
+});
+
+export const removeTag = idx => ({
+ type: 'REMOVE_TAG',
+ idx
+});
diff --git a/client/coral-plugin-commentbox/constants.js b/client/coral-plugin-commentbox/constants.js
new file mode 100644
index 000000000..b1290f02e
--- /dev/null
+++ b/client/coral-plugin-commentbox/constants.js
@@ -0,0 +1,2 @@
+export const ADD_TAG = 'ADD_TAG';
+export const REMOVE_TAG = 'REMOVE_TAG';
diff --git a/client/coral-plugin-commentbox/index.js b/client/coral-plugin-commentbox/index.js
new file mode 100644
index 000000000..9f166caeb
--- /dev/null
+++ b/client/coral-plugin-commentbox/index.js
@@ -0,0 +1,5 @@
+import reducer from './reducer';
+
+export default {
+ reducer
+};
diff --git a/client/coral-plugin-commentbox/reducer.js b/client/coral-plugin-commentbox/reducer.js
new file mode 100644
index 000000000..d9065fe87
--- /dev/null
+++ b/client/coral-plugin-commentbox/reducer.js
@@ -0,0 +1,25 @@
+import {ADD_TAG, REMOVE_TAG} from './constants';
+
+const initialState = {
+ tags: []
+};
+
+export default function commentBox (state = initialState, action) {
+ switch (action.type) {
+ case ADD_TAG :
+ return {
+ ...state,
+ tags: [...state.tags, action.tag]
+ };
+ case REMOVE_TAG :
+ return {
+ ...state,
+ tags: [
+ ...state.tags.slice(0, action.idx),
+ ...state.tags.slice(action.idx + 1)
+ ]
+ };
+ default :
+ return state;
+ }
+}
diff --git a/client/coral-plugin-commentbox/styles.css b/client/coral-plugin-commentbox/styles.css
new file mode 100644
index 000000000..d0f851f18
--- /dev/null
+++ b/client/coral-plugin-commentbox/styles.css
@@ -0,0 +1,6 @@
+.slot {
+ display: inline-block;
+ div {
+ display: inline-block;
+ }
+}
diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js
index 728603ae2..982f7ade7 100644
--- a/graph/mutators/comment.js
+++ b/graph/mutators/comment.js
@@ -16,11 +16,14 @@ const Wordlist = require('../../services/wordlist');
* @param {String} [status='NONE'] the status of the new comment
* @return {Promise} resolves to the created comment
*/
-const createComment = ({user, loaders: {Comments}}, {body, asset_id, parent_id = null}, status = 'NONE') => {
+const createComment = ({user, loaders: {Comments}}, {body, asset_id, parent_id = null, tags = []}, status = 'NONE') => {
- let tags = [];
+ // Building array of tags
+ tags = tags.map(tag => ({name: tag}));
+
+ // If admin or moderator, adding STAFF tag
if (user.hasRoles('ADMIN') || user.hasRoles('MODERATOR')) {
- tags = [{name: 'STAFF'}];
+ tags.push({name: 'STAFF'});
}
return CommentsService.publicCreate({
diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js
index 38183bff6..661cc9f96 100644
--- a/graph/resolvers/root_mutation.js
+++ b/graph/resolvers/root_mutation.js
@@ -2,8 +2,8 @@ const wrapResponse = require('../helpers/response');
const CommentsService = require('../../services/comments');
const RootMutation = {
- createComment(_, {asset_id, parent_id, body}, {mutators: {Comment}}) {
- return wrapResponse('comment')(Comment.create({asset_id, parent_id, body}));
+ createComment(_, {comment}, {mutators: {Comment}}) {
+ return wrapResponse('comment')(Comment.create(comment));
},
createLike(_, {like: {item_id, item_type}}, {mutators: {Action}}) {
return wrapResponse('like')(Action.create({item_id, item_type, action_type: 'LIKE'}));
diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql
index ef6ff5937..0a067b49c 100644
--- a/graph/typeDefs.graphql
+++ b/graph/typeDefs.graphql
@@ -602,6 +602,26 @@ input CreateLikeInput {
item_type: ACTION_ITEM_TYPE!
}
+enum TAG_TYPE {
+ STAFF
+}
+
+input CreateCommentInput {
+
+ # The asset id
+ asset_id: ID!
+
+ # The id of the parent comment
+ parent_id: ID
+
+ # The body of the comment
+ body: String!
+
+ # Tags
+ tags: [TAG_TYPE]
+
+}
+
type CreateLikeResponse implements Response {
# The like that was created.
@@ -728,7 +748,7 @@ type StopIgnoringUserResponse implements Response {
type RootMutation {
# Creates a comment on the asset.
- createComment(asset_id: ID!, parent_id: ID, body: String!): CreateCommentResponse
+ createComment(comment: CreateCommentInput!): CreateCommentResponse
# Creates a like on an entity.
createLike(like: CreateLikeInput!): CreateLikeResponse
diff --git a/out.gif b/out.gif
new file mode 100644
index 000000000..e69de29bb
diff --git a/plugins/coral-plugin-offtopic/client/.babelrc b/plugins/coral-plugin-offtopic/client/.babelrc
new file mode 100644
index 000000000..60be246eb
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/client/.babelrc
@@ -0,0 +1,14 @@
+{
+ "presets": [
+ "es2015"
+ ],
+ "plugins": [
+ "add-module-exports",
+ "transform-class-properties",
+ "transform-decorators-legacy",
+ "transform-object-assign",
+ "transform-object-rest-spread",
+ "transform-async-to-generator",
+ "transform-react-jsx"
+ ]
+}
\ No newline at end of file
diff --git a/plugins/coral-plugin-offtopic/client/.eslintrc.json b/plugins/coral-plugin-offtopic/client/.eslintrc.json
new file mode 100644
index 000000000..9fe56bd14
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/client/.eslintrc.json
@@ -0,0 +1,23 @@
+{
+ "env": {
+ "browser": true,
+ "es6": true,
+ "mocha": true
+ },
+ "parserOptions": {
+ "sourceType": "module",
+ "ecmaFeatures": {
+ "experimentalObjectRestSpread": true,
+ "jsx": true
+ }
+ },
+ "parser": "babel-eslint",
+ "plugins": [
+ "react"
+ ],
+ "rules": {
+ "react/jsx-uses-react": "error",
+ "react/jsx-uses-vars": "error",
+ "no-console": ["warn", { "allow": ["warn", "error"] }]
+ }
+}
diff --git a/plugins/coral-plugin-offtopic/client/components/OffTopicCheckbox.js b/plugins/coral-plugin-offtopic/client/components/OffTopicCheckbox.js
new file mode 100644
index 000000000..4e7ef7adf
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/client/components/OffTopicCheckbox.js
@@ -0,0 +1,38 @@
+import React from 'react';
+import {connect} from 'react-redux';
+import {bindActionCreators} from 'redux';
+import {addTag, removeTag} from 'coral-plugin-commentbox/actions';
+import styles from './styles.css';
+
+class OffTopicCheckbox extends React.Component {
+
+ label = 'OFF_TOPIC';
+
+ handleChange = (e) => {
+ if (e.target.checked) {
+ this.props.addTag(this.label)
+ } else {
+ const idx = this.props.commentBox.tags.indexOf(this.label);
+ this.props.removeTag(idx);
+ }
+ }
+
+ render() {
+ return (
+
+
+
+ )
+ }
+}
+
+
+const mapStateToProps = ({commentBox}) => ({commentBox});
+
+const mapDispatchToProps = dispatch =>
+ bindActionCreators({addTag, removeTag}, dispatch);
+
+export default connect(mapStateToProps, mapDispatchToProps)(OffTopicCheckbox);
diff --git a/plugins/coral-plugin-offtopic/client/components/OffTopicTag.js b/plugins/coral-plugin-offtopic/client/components/OffTopicTag.js
new file mode 100644
index 000000000..73e2372ed
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/client/components/OffTopicTag.js
@@ -0,0 +1,18 @@
+import React from 'react';
+import styles from './styles.css';
+
+const isOffTopic = (tags) => {
+ return !!tags.filter(tag => tag.name === 'OFF_TOPIC').length
+}
+
+export default (props) => (
+
+ {
+ isOffTopic(props.comment.tags) ? (
+
+ Off-topic
+
+ ) : null
+ }
+
+);
diff --git a/plugins/coral-plugin-offtopic/client/components/styles.css b/plugins/coral-plugin-offtopic/client/components/styles.css
new file mode 100644
index 000000000..f3e290b09
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/client/components/styles.css
@@ -0,0 +1,18 @@
+.offTopic {
+ height: 100%;
+}
+
+.offTopicLabel {
+ padding: 10px 20px;
+ display: block;
+}
+
+.tag {
+ background: rgba(245, 188, 168, 0.6);
+ display: inline-block;
+ margin: 0px 5px;
+ padding: 5px 5px;
+ border-radius: 2px;
+}
+
+
diff --git a/plugins/coral-plugin-offtopic/client/index.js b/plugins/coral-plugin-offtopic/client/index.js
new file mode 100644
index 000000000..c006c9a9e
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/client/index.js
@@ -0,0 +1,9 @@
+import OffTopicCheckbox from './components/OffTopicCheckbox';
+import OffTopicTag from './components/OffTopicTag';
+
+export default {
+ slots: {
+ commentBoxDetail: [OffTopicCheckbox],
+ commentInfoBar: [OffTopicTag]
+ }
+};
diff --git a/plugins/coral-plugin-offtopic/index.js b/plugins/coral-plugin-offtopic/index.js
new file mode 100644
index 000000000..51ad1c24e
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/index.js
@@ -0,0 +1,6 @@
+const {readFileSync} = require('fs');
+const path = require('path');
+
+module.exports = {
+ typeDefs: readFileSync(path.join(__dirname, 'server/typeDefs.graphql'), 'utf8')
+};
diff --git a/plugins/coral-plugin-offtopic/server/typeDefs.graphql b/plugins/coral-plugin-offtopic/server/typeDefs.graphql
new file mode 100644
index 000000000..48ba577cf
--- /dev/null
+++ b/plugins/coral-plugin-offtopic/server/typeDefs.graphql
@@ -0,0 +1,4 @@
+## Extending TAG_TYPE by adding OFF_TOPIC Tag
+enum TAG_TYPE {
+ OFF_TOPIC
+}
diff --git a/plugins/coral-plugin-respect/client/index.js b/plugins/coral-plugin-respect/client/index.js
index 2caa6611b..a336786d6 100644
--- a/plugins/coral-plugin-respect/client/index.js
+++ b/plugins/coral-plugin-respect/client/index.js
@@ -1,4 +1,5 @@
import RespectButton from './containers/RespectButton';
+
export default {
slots: {
commentDetail: [RespectButton],
diff --git a/services/comments.js b/services/comments.js
index 75b53873a..7e9cca20f 100644
--- a/services/comments.js
+++ b/services/comments.js
@@ -3,10 +3,10 @@ const CommentModel = require('../models/comment');
const ActionModel = require('../models/action');
const ActionsService = require('./actions');
-const ALLOWED_TAGS = [
- {name: 'STAFF'},
- {name: 'BEST'},
-];
+// const ALLOWED_TAGS = [
+// {name: 'STAFF'},
+// {name: 'BEST'},
+// ];
const STATUSES = [
'ACCEPTED',
@@ -53,9 +53,10 @@ module.exports = class CommentsService {
*/
static addTag(id, name, assigned_by) {
- if (ALLOWED_TAGS.find((t) => t.name === name) == null) {
- return Promise.reject(new Error('tag not allowed'));
- }
+ // Disabling allowed tags until we are able to extend them
+ // if (ALLOWED_TAGS.find((t) => t.name === name) == null) {
+ // return Promise.reject(new Error('tag not allowed'));
+ // }
const filter = {
id,
diff --git a/test/server/graph/mutations/createComment.js b/test/server/graph/mutations/createComment.js
index b3bdd459a..cf8481094 100644
--- a/test/server/graph/mutations/createComment.js
+++ b/test/server/graph/mutations/createComment.js
@@ -12,8 +12,8 @@ describe('graph.mutations.createComment', () => {
beforeEach(() => SettingsService.init());
const query = `
- mutation CreateComment($body: String = "Here's my comment!") {
- createComment(asset_id: "123", body: $body) {
+ mutation CreateComment($comment: CreateCommentInput = {asset_id: 123, body: "Here's my comment!"}) {
+ createComment(comment: $comment) {
comment {
id
status
@@ -170,7 +170,10 @@ describe('graph.mutations.createComment', () => {
const context = new Context({user: new UserModel({status: 'ACTIVE'})});
return graphql(schema, query, {}, context, {
- body
+ comment: {
+ asset_id: '123',
+ body
+ }
})
.then(({data, errors}) => {
expect(errors).to.be.undefined;
diff --git a/test/graph/mutations/ignoreUser.js b/test/server/graph/mutations/ignoreUser.js
similarity index 93%
rename from test/graph/mutations/ignoreUser.js
rename to test/server/graph/mutations/ignoreUser.js
index c5633bfb4..54d6305a1 100644
--- a/test/graph/mutations/ignoreUser.js
+++ b/test/server/graph/mutations/ignoreUser.js
@@ -1,10 +1,10 @@
const expect = require('chai').expect;
const {graphql} = require('graphql');
-const schema = require('../../../graph/schema');
-const Context = require('../../../graph/context');
-const UsersService = require('../../../services/users');
-const SettingsService = require('../../../services/settings');
+const schema = require('../../../../graph/schema');
+const Context = require('../../../../graph/context');
+const UsersService = require('../../../../services/users');
+const SettingsService = require('../../../../services/settings');
const ignoreUserMutation = `
mutation ignoreUser ($id: ID!) {
@@ -94,7 +94,7 @@ describe('graph.mutations.stopIgnoringUser', () => {
if (response.errors && response.errors.length) {
console.error(response.errors);
}
- expect(response.errors).to.be.empty;
+ expect(response.errors).to.be.empty;
});
const stopIgnoringUserMutation = `
@@ -112,7 +112,7 @@ describe('graph.mutations.stopIgnoringUser', () => {
if (stopIgnoringUserResponse.errors && stopIgnoringUserResponse.errors.length) {
console.error(stopIgnoringUserResponse.errors);
}
- expect(stopIgnoringUserResponse.errors).to.be.empty;
+ expect(stopIgnoringUserResponse.errors).to.be.empty;
// now check my ignored users
const myIgnoredUsersResponse = await graphql(schema, getMyIgnoredUsersQuery, {}, context, {});
diff --git a/test/graph/queries/asset.js b/test/server/graph/queries/asset.js
similarity index 88%
rename from test/graph/queries/asset.js
rename to test/server/graph/queries/asset.js
index ba31fe330..79abeda0e 100644
--- a/test/graph/queries/asset.js
+++ b/test/server/graph/queries/asset.js
@@ -1,12 +1,12 @@
const expect = require('chai').expect;
const {graphql} = require('graphql');
-const schema = require('../../../graph/schema');
-const Context = require('../../../graph/context');
-const UsersService = require('../../../services/users');
-const SettingsService = require('../../../services/settings');
-const Asset = require('../../../models/asset');
-const CommentsService = require('../../../services/comments');
+const schema = require('../../../../graph/schema');
+const Context = require('../../../../graph/context');
+const UsersService = require('../../../../services/users');
+const SettingsService = require('../../../../services/settings');
+const Asset = require('../../../../models/asset');
+const CommentsService = require('../../../../services/comments');
describe('graph.queries.asset', () => {
beforeEach(async () => {
@@ -87,7 +87,7 @@ describe('graph.queries.asset', () => {
`;
const assetCommentsResponse = await graphql(schema, assetCommentsWithoutIgnoredQuery, {}, context, {assetId, assetUrl, excludeIgnored: true});
const comments = assetCommentsResponse.data.asset.comments;
- expect(comments.length).to.equal(2);
+ expect(comments.length).to.equal(2);
});
});