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
@@ -1,4 +1,18 @@
.root {
display: flex;
justify-content: flex-end;
}
.coreLabels {
> *:not(:last-child) {
margin-right: 3px;
}
}
.slot {
&:not(:empty) {
padding-left: 3px;
}
> *:not(:last-child) {
margin-right: 3px;
}
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import Label from './Label';
import FlagLabel from './FlagLabel';
import Label from 'coral-ui/components/Label';
import Slot from 'coral-framework/components/Slot';
import FlagLabel from 'coral-ui/components/FlagLabel';
import cn from 'classnames';
import styles from './CommentLabels.css';
@@ -17,14 +18,17 @@ function hasHistoryFlag(actions) {
return actions.some((action) => action.__typename === 'FlagAction' && action.reason === 'TRUST');
}
const CommentLabels = ({comment: {className, status, actions, hasParent}}) => {
const CommentLabels = ({comment, comment: {className, status, actions, hasParent}}) => {
return (
<div className={cn(className, styles.root)}>
{hasParent && <Label iconName="reply" className={styles.replyLabel}>reply</Label>}
{status === 'PREMOD' && <Label iconName="query_builder" className={styles.premodLabel}>Pre-Mod</Label>}
{isUserFlagged(actions) && <FlagLabel iconName="person">User</FlagLabel>}
{hasSuspectedWords(actions) && <FlagLabel iconName="sms_failed">Suspect</FlagLabel>}
{hasHistoryFlag(actions) && <FlagLabel iconName="sentiment_very_dissatisfied">History</FlagLabel>}
<div className={styles.coreLabels}>
{hasParent && <Label iconName="reply" className={styles.replyLabel}>reply</Label>}
{status === 'PREMOD' && <Label iconName="query_builder" className={styles.premodLabel}>Pre-Mod</Label>}
{isUserFlagged(actions) && <FlagLabel iconName="person">User</FlagLabel>}
{hasSuspectedWords(actions) && <FlagLabel iconName="sms_failed">Suspect</FlagLabel>}
{hasHistoryFlag(actions) && <FlagLabel iconName="sentiment_very_dissatisfied">History</FlagLabel>}
</div>
<Slot className={styles.slot} fill="adminCommentLabels" queryData={{comment}} />
</div>
);
};
@@ -1,6 +1,11 @@
import {gql} from 'react-apollo';
import CommentLabels from '../components/CommentLabels';
import withFragments from 'coral-framework/hocs/withFragments';
import {getSlotFragmentSpreads} from 'coral-framework/utils';
const slots = [
'adminCommentLabels',
];
export default withFragments({
comment: gql`
@@ -16,6 +21,7 @@ export default withFragments({
id
}
}
${getSlotFragmentSpreads(slots, 'comment')}
}
`
})(CommentLabels);
@@ -4,9 +4,9 @@ import styles from './Label.css';
import {Icon} from 'coral-ui';
import cn from 'classnames';
const Label = ({iconName, children, className, isFlag}) => {
const Label = ({iconName, children, className}) => {
return (
<span className={cn(className, styles.root, {[styles.isFlag]: isFlag})}>
<span className={cn(className, styles.root)}>
<Icon name={iconName} className={styles.icon} /> {children}
</span>
);
@@ -14,7 +14,6 @@ const Label = ({iconName, children, className, isFlag}) => {
Label.propTypes = {
className: PropTypes.string,
isFlag: PropTypes.bool,
children: PropTypes.node.isRequired,
iconName: PropTypes.string,
};
+2
View File
@@ -26,3 +26,5 @@ export {default as Option} from './components/Option';
export {default as SnackBar} from './components/SnackBar';
export {default as TextArea} from './components/TextArea';
export {default as Drawer} from './components/Drawer';
export {default as Label} from './components/Label';
export {default as FlagLabel} from './components/FlagLabel';
@@ -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],
},
};