From 6e338290a1ebeb286221f040fef147b600a013ff Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Tue, 28 Feb 2017 02:31:02 +0800 Subject: [PATCH] addCommentTag mutation works --- .eslintrc.json | 1 + client/coral-embed-stream/src/Comment.js | 4 +- .../graphql/mutations/addCommentTag.graphql | 15 +- .../graphql/mutations/index.js | 3 +- client/coral-plugin-best/BestButton.js | 12 +- graph/mutators/comment.js | 15 +- graph/resolvers/root_mutation.js | 3 + graph/typeDefs.graphql | 10 + models/user.js | 3 +- package.json | 1 + services/comments.js | 53 +- test/e2e/tests/Moderator/BestCommentTest.js | 11 +- test/graph/mutations/addCommentTag.js | 42 ++ test/mocha.opts | 1 + test/services/comments.js | 47 +- yarn.lock | 681 +++++++++--------- 16 files changed, 523 insertions(+), 379 deletions(-) create mode 100644 test/graph/mutations/addCommentTag.js diff --git a/.eslintrc.json b/.eslintrc.json index 34b46b83b..eca2dda1f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,6 +3,7 @@ "es6": true, "node": true }, + "parser": "babel-eslint", "extends": "eslint:recommended", "rules": { "indent": ["error", diff --git a/client/coral-embed-stream/src/Comment.js b/client/coral-embed-stream/src/Comment.js index e4ca10743..47fd86cc8 100644 --- a/client/coral-embed-stream/src/Comment.js +++ b/client/coral-embed-stream/src/Comment.js @@ -112,11 +112,11 @@ class Comment extends React.Component { // @TODO(bengo) Would be best to only create these funcs on prop change const addBestTag = () => addCommentTag({ - comment_id: comment.id, + id: comment.id, tag: BEST_TAG, }); const removeBestTag = () => removeCommentTag({ - comment_id: comment.id, + id: comment.id, tag: BEST_TAG, }); diff --git a/client/coral-framework/graphql/mutations/addCommentTag.graphql b/client/coral-framework/graphql/mutations/addCommentTag.graphql index 27d369775..5fd63868e 100644 --- a/client/coral-framework/graphql/mutations/addCommentTag.graphql +++ b/client/coral-framework/graphql/mutations/addCommentTag.graphql @@ -1,10 +1,11 @@ -mutation AddCommentTag ($comment_id: ID!, $tag: String!) { - addCommentTag(comment_id:$comment_id, tag:$tag) { - comment { - tags { - name - } - } +mutation AddCommentTag ($id: ID!, $tag: String!) { + addCommentTag(id:$id, tag:$tag) { + comment { + id + tags { + name + } + } errors { translation_key } diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index b65a6a339..6f6cdc04b 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -127,9 +127,10 @@ export const deleteAction = graphql(DELETE_ACTION, { export const addCommentTag = graphql(ADD_COMMENT_TAG, { props: ({mutate}) => ({ - addCommentTag: (tag) => { + addCommentTag: ({id, tag}) => { return mutate({ variables: { + id, tag } }); diff --git a/client/coral-plugin-best/BestButton.js b/client/coral-plugin-best/BestButton.js index 9af8b1638..52367c4e0 100644 --- a/client/coral-plugin-best/BestButton.js +++ b/client/coral-plugin-best/BestButton.js @@ -5,7 +5,10 @@ import classnames from 'classnames'; // tag string for best comments export const BEST_TAG = 'BEST'; -export const commentIsBest = ({tags} = {}) => Array.isArray(tags) && tags.some(t => t === BEST_TAG); +export const commentIsBest = ({tags} = {}) => { + const isBest = Array.isArray(tags) && tags.some(t => t.name === BEST_TAG); + return isBest; +}; const name = 'coral-plugin-best'; const lang = new I18n(translations); @@ -38,10 +41,6 @@ export class BestButton extends Component { removeBest: PropTypes.func.isRequired, } - state = { - best: false - } - constructor(props) { super(props); this.onClickAddBest = this.onClickAddBest.bind(this); @@ -75,8 +74,7 @@ export class BestButton extends Component { // @TODO(bengo) Consider adding the comment__action classes to other buttons to add cursor:pointer and never wrap the icons // @TODO(bengo) Should I reuse another element like coral-ui button? Just doing what LikeButton does for now // Oh. I think that's styled for the admin. Don't use coral-ui button until the whole comment bottom bar does. - let {isBest} = this.state; - const {addBest, removeBest} = this.props; + const {isBest, addBest, removeBest} = this.props; return