This commit is contained in:
Chi Vinh Le
2018-01-26 01:42:46 +01:00
parent ce25cfb159
commit b638b783fe
5 changed files with 32 additions and 86 deletions
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import { compose, gql } from 'react-apollo';
import Indicator from '../../../components/Indicator';
import { withFragments } from 'plugin-api/beta/client/hocs';
import { handleIndicatorChange } from '../graphql';
import { handleIndicatorChange, subscriptionFields } from '../graphql';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import withQueueConfig from '../hoc/withQueueConfig';
@@ -131,27 +131,10 @@ IndicatorContainer.propTypes = {
queueConfig: PropTypes.object,
};
const fields = `
status
actions {
__typename
created_at
}
status_history {
type
assigned_by {
id
}
created_at
}
updated_at
created_at
`;
const COMMENT_ADDED_SUBSCRIPTION = gql`
subscription TalkAdmin_ModerationIndicator_CommentAdded {
commentAdded(statuses: null) {
${fields}
${subscriptionFields}
}
}
`;
@@ -159,7 +142,7 @@ const COMMENT_ADDED_SUBSCRIPTION = gql`
const COMMENT_FLAGGED_SUBSCRIPTION = gql`
subscription TalkAdmin_ModerationIndicator_CommentFlagged {
commentFlagged {
${fields}
${subscriptionFields}
}
}
`;
@@ -167,7 +150,7 @@ const COMMENT_FLAGGED_SUBSCRIPTION = gql`
const COMMENT_EDITED_SUBSCRIPTION = gql`
subscription TalkAdmin_ModerationIndicator_CommentEdited {
commentEdited {
${fields}
${subscriptionFields}
}
}
`;
@@ -175,7 +158,7 @@ const COMMENT_EDITED_SUBSCRIPTION = gql`
const COMMENT_ACCEPTED_SUBSCRIPTION = gql`
subscription TalkAdmin_ModerationIndicator_CommentAccepted {
commentAccepted {
${fields}
${subscriptionFields}
}
}
`;
@@ -183,7 +166,7 @@ const COMMENT_ACCEPTED_SUBSCRIPTION = gql`
const COMMENT_REJECTED_SUBSCRIPTION = gql`
subscription TalkAdmin_ModerationIndicator_CommentRejected {
commentRejected {
${fields}
${subscriptionFields}
}
}
`;
@@ -191,7 +174,7 @@ const COMMENT_REJECTED_SUBSCRIPTION = gql`
const COMMENT_RESET_SUBSCRIPTION = gql`
subscription TalkAdmin_ModerationIndicator_CommentReset {
commentReset {
${fields}
${subscriptionFields}
}
}
`;
@@ -15,6 +15,7 @@ import {
handleCommentChange,
commentBelongToQueue,
cleanUpQueue,
subscriptionFields,
} from '../graphql';
import { viewUserDetail } from '../../../actions/userDetail';
@@ -339,24 +340,6 @@ class ModerationContainer extends Component {
}
}
const subscriptionFields = `
status
actions {
__typename
created_at
}
status_history {
type
created_at
assigned_by {
id
username
}
}
created_at
updated_at
`;
const COMMENT_ADDED_SUBSCRIPTION = gql`
subscription CommentAdded($asset_id: ID){
commentAdded(asset_id: $asset_id, statuses: null){
@@ -113,7 +113,7 @@ function determineLatestChange(comment) {
let lc = null;
// Skip it when comment itself was not updated.
// We'll get use the one from the status_history instead
// We'll use the one from the status_history instead
// as they might diverge a little bit (status_history item is created
// before the comment itself)
if (comment.createdAt !== comment.updatedAt) {
@@ -138,7 +138,6 @@ function reconstructPreviousCommentState(comment) {
const history = comment.status_history;
const actions = comment.actions;
const lastChangeDate = determineLatestChange(comment);
console.log(lastChangeDate);
const previousComment = {
...comment,
status_history: history.filter(
@@ -166,7 +165,6 @@ function reconstructPreviousCommentState(comment) {
function getPreviousCommentQueues(comment, queueConfig) {
const previousCommentState = reconstructPreviousCommentState(comment);
console.log(previousCommentState, comment);
if (!previousCommentState) {
return [];
}
@@ -291,8 +289,6 @@ export function handleCommentChange(
// Queues that this comment needs to be placed.
const nextQueues = getCommentQueues(comment, queueConfig);
console.log(prevQueues, nextQueues);
let notificationShown = false;
const showNotificationOnce = () => {
if (notificationShown) {
@@ -393,6 +389,22 @@ export function handleIndicatorChange(root, comment, queueConfig) {
}
}
console.log(prevQueues, nextQueues, next);
return next;
}
export const subscriptionFields = `
status
actions {
__typename
created_at
}
status_history {
type
assigned_by {
id
}
created_at
}
updated_at
created_at
`;
@@ -1,5 +1,6 @@
import React from 'react';
import { gql } from 'react-apollo';
import { subscriptionFields } from 'coral-admin/src/routes/Moderation/graphql';
class ModIndicatorSubscription extends React.Component {
subscriptions = null;
@@ -39,28 +40,11 @@ class ModIndicatorSubscription extends React.Component {
}
}
const fields = `
status
actions {
__typename
created_at
}
status_history {
type
assigned_by {
id
}
created_at
}
updated_at
created_at
`;
const COMMENT_FEATURED_SUBSCRIPTION = gql`
subscription TalkFeaturedComments_Indicator_CommentFeatured {
commentFeatured {
comment {
${fields}
${subscriptionFields}
}
}
}
@@ -70,7 +54,7 @@ const COMMENT_UNFEATURED_SUBSCRIPTION = gql`
subscription TalkFeaturedComments_Indicator_CommentUnfeatured {
commentUnfeatured {
comment {
${fields}
${subscriptionFields}
}
}
}
@@ -5,6 +5,7 @@ import Comment from 'coral-admin/src/routes/Moderation/containers/Comment';
import { getDefinitionName } from 'coral-framework/utils';
import truncate from 'lodash/truncate';
import t from 'coral-framework/services/i18n';
import { subscriptionFields } from 'coral-admin/src/routes/Moderation/graphql';
function prepareNotificationText(text) {
return truncate(text, { length: 50 }).replace('\n', ' ');
@@ -74,29 +75,12 @@ class ModSubscription extends React.Component {
}
}
const fields = `
status
actions {
__typename
created_at
}
status_history {
type
assigned_by {
id
}
created_at
}
updated_at
created_at
`;
const COMMENT_FEATURED_SUBSCRIPTION = gql`
subscription CommentFeatured($assetId: ID){
commentFeatured(asset_id: $assetId) {
comment {
...${getDefinitionName(Comment.fragments.comment)}
${fields}
${subscriptionFields}
}
user {
id
@@ -112,7 +96,7 @@ const COMMENT_UNFEATURED_SUBSCRIPTION = gql`
commentUnfeatured(asset_id: $assetId){
comment {
...${getDefinitionName(Comment.fragments.comment)}
${fields}
${subscriptionFields}
}
user {
id