Introduce adminCommentLabels and implement Toxic comment label

This commit is contained in:
Chi Vinh Le
2017-09-19 23:14:34 +07:00
parent b0219948a0
commit 7a4aae93b4
11 changed files with 70 additions and 11 deletions
@@ -0,0 +1,8 @@
import React from 'react';
import {FlagLabel} from 'plugin-api/beta/client/components/ui';
const ToxicLabel = () => (
<FlagLabel iconName="add_box">Toxic</FlagLabel>
);
export default ToxicLabel;
@@ -0,0 +1,24 @@
import {compose, gql} from 'react-apollo';
import {withFragments, excludeIf} from 'plugin-api/beta/client/hocs';
import ToxicLabel from '../components/ToxicLabel';
function isToxic(actions) {
return actions.some((action) => action.__typename === 'FlagAction' && action.reason === 'TOXIC_COMMENT');
}
const enhance = compose(
withFragments({
comment: gql`
fragment TalkToxicComments_Comment on Comment {
actions {
__typename
... on FlagAction {
reason
}
}
}`,
}),
excludeIf(({comment: {actions}}) => !isToxic(actions)),
);
export default enhance(ToxicLabel);
@@ -1,9 +1,11 @@
import translations from './translations.yml';
import CheckToxicityHook from './containers/CheckToxicityHook';
import ToxicLabel from './containers/ToxicLabel';
export default {
translations,
slots: {
commentInputDetailArea: [CheckToxicityHook],
adminCommentLabels: [ToxicLabel],
},
};