From 521082eb3eef8725c74d84e684e6b3d1de216a6b Mon Sep 17 00:00:00 2001 From: riley Date: Fri, 28 Apr 2017 11:39:37 -0600 Subject: [PATCH 01/11] add new query for counts --- .../src/graphql/fragments/counts.graphql | 22 +++++++++++++++++++ .../graphql/queries/getQueueCounts.graphql | 5 +++++ .../coral-admin/src/graphql/queries/index.js | 12 ++++++++++ .../src/graphql/queries/modQueueQuery.graphql | 22 ++----------------- 4 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 client/coral-admin/src/graphql/fragments/counts.graphql create mode 100644 client/coral-admin/src/graphql/queries/getQueueCounts.graphql diff --git a/client/coral-admin/src/graphql/fragments/counts.graphql b/client/coral-admin/src/graphql/fragments/counts.graphql new file mode 100644 index 000000000..eb00be4da --- /dev/null +++ b/client/coral-admin/src/graphql/fragments/counts.graphql @@ -0,0 +1,22 @@ +fragment counts on RootQuery { + allCount: commentCount(query: { + asset_id: $asset_id + }) + acceptedCount: commentCount(query: { + statuses: [ACCEPTED], + asset_id: $asset_id + }) + premodCount: commentCount(query: { + statuses: [PREMOD], + asset_id: $asset_id + }) + rejectedCount: commentCount(query: { + statuses: [REJECTED], + asset_id: $asset_id + }) + flaggedCount: commentCount(query: { + action_type: FLAG, + asset_id: $asset_id, + statuses: [NONE, PREMOD] + }) +} diff --git a/client/coral-admin/src/graphql/queries/getQueueCounts.graphql b/client/coral-admin/src/graphql/queries/getQueueCounts.graphql new file mode 100644 index 000000000..a527c2538 --- /dev/null +++ b/client/coral-admin/src/graphql/queries/getQueueCounts.graphql @@ -0,0 +1,5 @@ +#import "../fragments/counts.graphql" + +query Counts ($asset_id: ID) { + ...counts +} diff --git a/client/coral-admin/src/graphql/queries/index.js b/client/coral-admin/src/graphql/queries/index.js index 53113558b..09da07bc0 100644 --- a/client/coral-admin/src/graphql/queries/index.js +++ b/client/coral-admin/src/graphql/queries/index.js @@ -4,6 +4,7 @@ import MOD_QUEUE_QUERY from './modQueueQuery.graphql'; import MOD_QUEUE_LOAD_MORE from './loadMore.graphql'; import MOD_USER_FLAGGED_QUERY from './modUserFlaggedQuery.graphql'; import METRICS from './metricsQuery.graphql'; +import GET_QUEUE_COUNTS from './getQueueCounts.graphql'; export const modQueueQuery = graphql(MOD_QUEUE_QUERY, { options: ({params: {id = null}}) => { @@ -90,3 +91,14 @@ export const modQueueResort = (id, fetchMore) => (sort) => { updateQuery: (oldData, {fetchMoreResult:{data}}) => data }); }; + +export const getQueueCounts = graphql(GET_QUEUE_COUNTS, { + options: ({params: {id = null}}) => { + return { + pollInterval: 5000, + variables: { + asset_id: id + } + }; + } +}); diff --git a/client/coral-admin/src/graphql/queries/modQueueQuery.graphql b/client/coral-admin/src/graphql/queries/modQueueQuery.graphql index 80dec5ff7..9250ba793 100644 --- a/client/coral-admin/src/graphql/queries/modQueueQuery.graphql +++ b/client/coral-admin/src/graphql/queries/modQueueQuery.graphql @@ -1,4 +1,5 @@ #import "../fragments/commentView.graphql" +#import "../fragments/counts.graphql" query ModQueue ($asset_id: ID, $sort: SORT_ORDER) { all: comments(query: { @@ -42,24 +43,5 @@ query ModQueue ($asset_id: ID, $sort: SORT_ORDER) { title url } - allCount: commentCount(query: { - asset_id: $asset_id - }) - acceptedCount: commentCount(query: { - statuses: [ACCEPTED], - asset_id: $asset_id - }) - premodCount: commentCount(query: { - statuses: [PREMOD], - asset_id: $asset_id - }) - rejectedCount: commentCount(query: { - statuses: [REJECTED], - asset_id: $asset_id - }) - flaggedCount: commentCount(query: { - action_type: FLAG, - asset_id: $asset_id, - statuses: [NONE, PREMOD] - }) + ...counts } From 41d4bd10126653e17757c80d9d3ed95dcd7f5114 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Fri, 28 Apr 2017 11:52:07 -0600 Subject: [PATCH 02/11] counts update --- .../src/containers/ModerationQueue/ModerationContainer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js b/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js index eb59f369e..7a3aab909 100644 --- a/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js +++ b/client/coral-admin/src/containers/ModerationQueue/ModerationContainer.js @@ -5,7 +5,7 @@ import key from 'keymaster'; import isEqual from 'lodash/isEqual'; import styles from './components/styles.css'; -import {modQueueQuery} from '../../graphql/queries'; +import {modQueueQuery, getQueueCounts} from '../../graphql/queries'; import {banUser, setCommentStatus} from '../../graphql/mutations'; import {fetchSettings} from 'actions/settings'; @@ -220,6 +220,7 @@ const mapDispatchToProps = dispatch => ({ export default compose( connect(mapStateToProps, mapDispatchToProps), setCommentStatus, + getQueueCounts, modQueueQuery, banUser )(ModerationContainer); From 8293408c52e56d81e71bc28aca2e326173dfced5 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Mon, 1 May 2017 10:22:11 -0600 Subject: [PATCH 03/11] pull some custom code out of ActionButton --- .../src/components/ActionButton.js | 5 ++--- .../ModerationQueue/components/Comment.js | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/client/coral-admin/src/components/ActionButton.js b/client/coral-admin/src/components/ActionButton.js index ae75b829e..3651ee939 100644 --- a/client/coral-admin/src/components/ActionButton.js +++ b/client/coral-admin/src/components/ActionButton.js @@ -3,9 +3,8 @@ import styles from './ModerationList.css'; import {Button} from 'coral-ui'; import {menuActionsMap} from '../containers/ModerationQueue/helpers/moderationQueueActionsMap'; -const ActionButton = ({type = '', status, ...props}) => { +const ActionButton = ({type = '', active, ...props}) => { const typeName = type.toLowerCase(); - const active = ((type === 'REJECT' && status === 'REJECTED') || (type === 'APPROVE' && status === 'ACCEPTED')); let text = menuActionsMap[type].text; if (text === 'Approve' && active) { @@ -25,7 +24,7 @@ const ActionButton = ({type = '', status, ...props}) => { }; ActionButton.propTypes = { - status: PropTypes.string + active: PropTypes.bool }; export default ActionButton; diff --git a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js index 0fdf435bd..4b4430192 100644 --- a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js +++ b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js @@ -66,14 +66,18 @@ const Comment = ({actions = [], comment, ...props}) => {
{links ? Contains Link : null}
- {actions.map((action, i) => - props.acceptComment({commentId: comment.id})} - rejectComment={() => props.rejectComment({commentId: comment.id})} - /> + {actions.map((action, i) => { + const active = (action === 'REJECT' && comment.status === 'REJECTED') || + (action === 'APPROVE' && comment.status === 'ACCEPTED'); + return ( props.acceptComment({commentId: comment.id})} + rejectComment={() => props.rejectComment({commentId: comment.id})} + />); + } )}
From 32dd554331c73ba55145e06c73644b9d19e428e8 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Mon, 1 May 2017 10:30:18 -0600 Subject: [PATCH 04/11] load more comments if the mod has moderated them all and there are more availabile --- .../ModerationQueue/ModerationQueue.js | 106 ++++++++++-------- .../ModerationQueue/components/Comment.js | 8 +- .../ModerationQueue/components/LoadMore.js | 11 +- 3 files changed, 71 insertions(+), 54 deletions(-) diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js index f986b947b..c4bf0f85c 100644 --- a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js +++ b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js @@ -9,51 +9,67 @@ import translations from 'coral-admin/src/translations'; import LoadMore from './components/LoadMore'; const lang = new I18n(translations); -const ModerationQueue = ({comments, selectedIndex, commentCount, singleView, loadMore, activeTab, sort, ...props}) => { - return ( -
-
    - { - comments.length - ? comments.map((comment, i) => { - const status = comment.action_summaries ? 'FLAGGED' : comment.status; - return ; - }) - : {lang.t('modqueue.emptyqueue')} - } -
- -
- ); -}; +class ModerationQueue extends React.Component { -ModerationQueue.propTypes = { - bannedWords: PropTypes.arrayOf(PropTypes.string).isRequired, - suspectWords: PropTypes.arrayOf(PropTypes.string).isRequired, - currentAsset: PropTypes.object, - showBanUserDialog: PropTypes.func.isRequired, - rejectComment: PropTypes.func.isRequired, - acceptComment: PropTypes.func.isRequired, - comments: PropTypes.array.isRequired -}; + static propTypes = { + bannedWords: PropTypes.arrayOf(PropTypes.string).isRequired, + suspectWords: PropTypes.arrayOf(PropTypes.string).isRequired, + currentAsset: PropTypes.object, + showBanUserDialog: PropTypes.func.isRequired, + rejectComment: PropTypes.func.isRequired, + acceptComment: PropTypes.func.isRequired, + comments: PropTypes.array.isRequired + } + + componentDidUpdate (prev) { + const {loadMore, comments, commentCount, sort, activeTab: tab, assetId: asset_id} = this.props; + + // if the user just moderated the last (visible) comment + // AND there are more comments available on the server, + // go ahead and load more comments + if (prev.comments.length > 0 && comments.length === 0 && commentCount > 0) { + loadMore({sort, tab, asset_id}); + } + } + + render () { + const {comments, selectedIndex, commentCount, singleView, loadMore, activeTab, sort, ...props} = this.props; + + return ( +
+
    + { + comments.length + ? comments.map((comment, i) => { + const status = comment.action_summaries ? 'FLAGGED' : comment.status; + return ; + }) + : {lang.t('modqueue.emptyqueue')} + } +
+ +
+ ); + } +} export default ModerationQueue; diff --git a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js index 4b4430192..e5afd9726 100644 --- a/client/coral-admin/src/containers/ModerationQueue/components/Comment.js +++ b/client/coral-admin/src/containers/ModerationQueue/components/Comment.js @@ -69,16 +69,14 @@ const Comment = ({actions = [], comment, ...props}) => { {actions.map((action, i) => { const active = (action === 'REJECT' && comment.status === 'REJECTED') || (action === 'APPROVE' && comment.status === 'ACCEPTED'); - return ( props.acceptComment({commentId: comment.id})} - rejectComment={() => props.rejectComment({commentId: comment.id})} - />); - } - )} + rejectComment={() => props.rejectComment({commentId: comment.id})} />; + })} diff --git a/client/coral-admin/src/containers/ModerationQueue/components/LoadMore.js b/client/coral-admin/src/containers/ModerationQueue/components/LoadMore.js index f16635486..c90d3cd14 100644 --- a/client/coral-admin/src/containers/ModerationQueue/components/LoadMore.js +++ b/client/coral-admin/src/containers/ModerationQueue/components/LoadMore.js @@ -7,13 +7,16 @@ const LoadMore = ({comments, loadMore, sort, tab, assetId, showLoadMore}) => { showLoadMore && } From b7d311367780246c203f3700ba8cb6371b6fb0ff Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 2 May 2017 15:18:48 -0600 Subject: [PATCH 05/11] apparently you can't make a fragment on RootQuery --- .../src/containers/Dashboard/FlagWidget.js | 2 +- .../fragments/assetMetricsView.graphql | 1 - .../src/graphql/fragments/counts.graphql | 22 ------------------ .../graphql/queries/getQueueCounts.graphql | 23 ++++++++++++++++--- .../src/graphql/queries/modQueueQuery.graphql | 22 ++++++++++++++++-- .../src/services/fragmentMatcher.js | 2 ++ test/server/graph/loaders/metrics.js | 1 - 7 files changed, 43 insertions(+), 30 deletions(-) delete mode 100644 client/coral-admin/src/graphql/fragments/counts.graphql diff --git a/client/coral-admin/src/containers/Dashboard/FlagWidget.js b/client/coral-admin/src/containers/Dashboard/FlagWidget.js index 92de6c4d2..ea72cddc6 100644 --- a/client/coral-admin/src/containers/Dashboard/FlagWidget.js +++ b/client/coral-admin/src/containers/Dashboard/FlagWidget.js @@ -21,7 +21,7 @@ const FlagWidget = ({assets}) => { ? assets.map(asset => { let flagSummary = null; if (asset.action_summaries) { - flagSummary = asset.action_summaries.find(s => s.type === 'FlagAssetActionSummary'); + flagSummary = asset.action_summaries.find(s => s.__typename === 'FlagAssetActionSummary'); } return ( diff --git a/client/coral-admin/src/graphql/fragments/assetMetricsView.graphql b/client/coral-admin/src/graphql/fragments/assetMetricsView.graphql index c77fbc32b..726194143 100644 --- a/client/coral-admin/src/graphql/fragments/assetMetricsView.graphql +++ b/client/coral-admin/src/graphql/fragments/assetMetricsView.graphql @@ -6,7 +6,6 @@ fragment metrics on Asset { created_at commentCount action_summaries { - type: __typename actionCount actionableItemCount } diff --git a/client/coral-admin/src/graphql/fragments/counts.graphql b/client/coral-admin/src/graphql/fragments/counts.graphql deleted file mode 100644 index eb00be4da..000000000 --- a/client/coral-admin/src/graphql/fragments/counts.graphql +++ /dev/null @@ -1,22 +0,0 @@ -fragment counts on RootQuery { - allCount: commentCount(query: { - asset_id: $asset_id - }) - acceptedCount: commentCount(query: { - statuses: [ACCEPTED], - asset_id: $asset_id - }) - premodCount: commentCount(query: { - statuses: [PREMOD], - asset_id: $asset_id - }) - rejectedCount: commentCount(query: { - statuses: [REJECTED], - asset_id: $asset_id - }) - flaggedCount: commentCount(query: { - action_type: FLAG, - asset_id: $asset_id, - statuses: [NONE, PREMOD] - }) -} diff --git a/client/coral-admin/src/graphql/queries/getQueueCounts.graphql b/client/coral-admin/src/graphql/queries/getQueueCounts.graphql index a527c2538..4a7c00d87 100644 --- a/client/coral-admin/src/graphql/queries/getQueueCounts.graphql +++ b/client/coral-admin/src/graphql/queries/getQueueCounts.graphql @@ -1,5 +1,22 @@ -#import "../fragments/counts.graphql" - query Counts ($asset_id: ID) { - ...counts + allCount: commentCount(query: { + asset_id: $asset_id + }) + acceptedCount: commentCount(query: { + statuses: [ACCEPTED], + asset_id: $asset_id + }) + premodCount: commentCount(query: { + statuses: [PREMOD], + asset_id: $asset_id + }) + rejectedCount: commentCount(query: { + statuses: [REJECTED], + asset_id: $asset_id + }) + flaggedCount: commentCount(query: { + action_type: FLAG, + asset_id: $asset_id, + statuses: [NONE, PREMOD] + }) } diff --git a/client/coral-admin/src/graphql/queries/modQueueQuery.graphql b/client/coral-admin/src/graphql/queries/modQueueQuery.graphql index 9250ba793..80dec5ff7 100644 --- a/client/coral-admin/src/graphql/queries/modQueueQuery.graphql +++ b/client/coral-admin/src/graphql/queries/modQueueQuery.graphql @@ -1,5 +1,4 @@ #import "../fragments/commentView.graphql" -#import "../fragments/counts.graphql" query ModQueue ($asset_id: ID, $sort: SORT_ORDER) { all: comments(query: { @@ -43,5 +42,24 @@ query ModQueue ($asset_id: ID, $sort: SORT_ORDER) { title url } - ...counts + allCount: commentCount(query: { + asset_id: $asset_id + }) + acceptedCount: commentCount(query: { + statuses: [ACCEPTED], + asset_id: $asset_id + }) + premodCount: commentCount(query: { + statuses: [PREMOD], + asset_id: $asset_id + }) + rejectedCount: commentCount(query: { + statuses: [REJECTED], + asset_id: $asset_id + }) + flaggedCount: commentCount(query: { + action_type: FLAG, + asset_id: $asset_id, + statuses: [NONE, PREMOD] + }) } diff --git a/client/coral-admin/src/services/fragmentMatcher.js b/client/coral-admin/src/services/fragmentMatcher.js index afb87d445..c825ff5b5 100644 --- a/client/coral-admin/src/services/fragmentMatcher.js +++ b/client/coral-admin/src/services/fragmentMatcher.js @@ -37,6 +37,7 @@ const fm = new IntrospectionFragmentMatcher({ kind: 'INTERFACE', name: 'Action', possibleTypes: [ + {name: 'DefaultAction'}, {name: 'FlagAction'}, {name: 'LikeAction'}, {name: 'DontAgreeAction'} @@ -46,6 +47,7 @@ const fm = new IntrospectionFragmentMatcher({ kind: 'INTERFACE', name: 'ActionSummary', possibleTypes: [ + {name: 'DefaultActionSummary'}, {name: 'FlagActionSummary'}, {name: 'LikeActionSummary'}, {name: 'DontAgreeActionSummary'} diff --git a/test/server/graph/loaders/metrics.js b/test/server/graph/loaders/metrics.js index f095e201f..2e2408615 100644 --- a/test/server/graph/loaders/metrics.js +++ b/test/server/graph/loaders/metrics.js @@ -78,7 +78,6 @@ describe('graph.loaders.Metrics', () => { fragment metrics on Asset { id action_summaries { - type: __typename actionCount actionableItemCount } From e60bcb9cafe59172be7874c4cc1135ae51e70675 Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 2 May 2017 15:58:57 -0600 Subject: [PATCH 06/11] make sure load more on approve/reject queues doesn't cause a bug --- client/coral-admin/src/graphql/queries/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/coral-admin/src/graphql/queries/index.js b/client/coral-admin/src/graphql/queries/index.js index 64bf096ba..7b6985cba 100644 --- a/client/coral-admin/src/graphql/queries/index.js +++ b/client/coral-admin/src/graphql/queries/index.js @@ -63,13 +63,21 @@ export const loadMore = (fetchMore) => ({limit, cursor, sort, tab, asset_id}) => asset_id }, updateQuery: (oldData, {fetchMoreResult:{comments}}) => { - return { + const updatedData = { ...oldData, [tab]: [ ...oldData[tab], ...comments ] }; + + // if we're not in the all tab, put the new comments in there anyway + // this way the acceptComment and rejectComment mutations don't break + if (tab !== 'all') { + updatedData.all = [...updatedData.all, ...comments]; + } + + return updatedData; } }); }; From 324e82c070aa41f34d7095c89bd27552ff615a29 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Wed, 3 May 2017 10:20:03 -0600 Subject: [PATCH 07/11] not pretty, but it works --- .../src/graphql/mutations/index.js | 30 +++++++++++++++++-- .../coral-admin/src/graphql/queries/index.js | 6 ---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/client/coral-admin/src/graphql/mutations/index.js b/client/coral-admin/src/graphql/mutations/index.js index 4d62201d1..684a60372 100644 --- a/client/coral-admin/src/graphql/mutations/index.js +++ b/client/coral-admin/src/graphql/mutations/index.js @@ -54,7 +54,20 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - const comment = oldData.all.find(c => c.id === commentId); + let comment = oldData.all.find(c => c.id === commentId); + + if (!comment) { + comment = oldData.premod.find(c => c.id === commentId); + } + + if (!comment) { + comment = oldData.flagged.find(c => c.id === commentId); + } + + if (!comment) { + comment = oldData.rejected.find(c => c.id === commentId); + } + let accepted; let acceptedCount = oldData.acceptedCount; @@ -97,7 +110,20 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - const comment = oldData.all.find(c => c.id === commentId); + let comment = oldData.all.find(c => c.id === commentId); + + if (!comment) { + comment = oldData.premod.find(c => c.id === commentId); + } + + if (!comment) { + comment = oldData.flagged.find(c => c.id === commentId); + } + + if (!comment) { + comment = oldData.accepted.find(c => c.id === commentId); + } + let rejected; let rejectedCount = oldData.rejectedCount; diff --git a/client/coral-admin/src/graphql/queries/index.js b/client/coral-admin/src/graphql/queries/index.js index 7b6985cba..c251e5759 100644 --- a/client/coral-admin/src/graphql/queries/index.js +++ b/client/coral-admin/src/graphql/queries/index.js @@ -71,12 +71,6 @@ export const loadMore = (fetchMore) => ({limit, cursor, sort, tab, asset_id}) => ] }; - // if we're not in the all tab, put the new comments in there anyway - // this way the acceptComment and rejectComment mutations don't break - if (tab !== 'all') { - updatedData.all = [...updatedData.all, ...comments]; - } - return updatedData; } }); From c78e00711a61f3e9e2426328d5e63d688105b7ee Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Wed, 3 May 2017 10:54:52 -0600 Subject: [PATCH 08/11] remove if statements --- .../src/graphql/mutations/index.js | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/client/coral-admin/src/graphql/mutations/index.js b/client/coral-admin/src/graphql/mutations/index.js index 684a60372..9c72d184a 100644 --- a/client/coral-admin/src/graphql/mutations/index.js +++ b/client/coral-admin/src/graphql/mutations/index.js @@ -54,20 +54,12 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - let comment = oldData.all.find(c => c.id === commentId); - - if (!comment) { - comment = oldData.premod.find(c => c.id === commentId); - } - - if (!comment) { - comment = oldData.flagged.find(c => c.id === commentId); - } - - if (!comment) { - comment = oldData.rejected.find(c => c.id === commentId); - } - + let comment = [ + ...oldData.all, + ...oldData.premod, + ...oldData.flagged, + ...oldData.rejected + ].find(c => c.id === commentId); let accepted; let acceptedCount = oldData.acceptedCount; @@ -110,19 +102,12 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - let comment = oldData.all.find(c => c.id === commentId); - - if (!comment) { - comment = oldData.premod.find(c => c.id === commentId); - } - - if (!comment) { - comment = oldData.flagged.find(c => c.id === commentId); - } - - if (!comment) { - comment = oldData.accepted.find(c => c.id === commentId); - } + let comment = [ + ...oldData.all, + ...oldData.premod, + ...oldData.flagged, + ...oldData.accepted + ].find(c => c.id === commentId); let rejected; let rejectedCount = oldData.rejectedCount; From 354b51b4fe51f0670834af3c50d9c31149170be4 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 3 May 2017 11:14:21 -0600 Subject: [PATCH 09/11] use a reduce instead --- .../src/graphql/mutations/index.js | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/client/coral-admin/src/graphql/mutations/index.js b/client/coral-admin/src/graphql/mutations/index.js index 9c72d184a..fdb82db9a 100644 --- a/client/coral-admin/src/graphql/mutations/index.js +++ b/client/coral-admin/src/graphql/mutations/index.js @@ -44,6 +44,7 @@ export const suspendUser = graphql(SUSPEND_USER, { }) }); +const views = ['all', 'premod', 'flagged', 'accepted', 'rejected']; export const setCommentStatus = graphql(SET_COMMENT_STATUS, { props: ({mutate}) => ({ acceptComment: ({commentId}) => { @@ -54,12 +55,9 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - let comment = [ - ...oldData.all, - ...oldData.premod, - ...oldData.flagged, - ...oldData.rejected - ].find(c => c.id === commentId); + const comment = views.reduce((comment, view) => { + return comment ? comment : oldData[view].find(c => c.id === commentId); + }, null); let accepted; let acceptedCount = oldData.acceptedCount; @@ -102,13 +100,9 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { }, updateQueries: { ModQueue: (oldData) => { - let comment = [ - ...oldData.all, - ...oldData.premod, - ...oldData.flagged, - ...oldData.accepted - ].find(c => c.id === commentId); - + const comment = views.reduce((comment, view) => { + return comment ? comment : oldData[view].find(c => c.id === commentId); + }, null); let rejected; let rejectedCount = oldData.rejectedCount; From 39bd0eca6f143b73f574abdd8a90eb1359d7d793 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 3 May 2017 12:45:49 -0600 Subject: [PATCH 10/11] remove pointless change --- client/coral-admin/src/graphql/queries/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/coral-admin/src/graphql/queries/index.js b/client/coral-admin/src/graphql/queries/index.js index c251e5759..64bf096ba 100644 --- a/client/coral-admin/src/graphql/queries/index.js +++ b/client/coral-admin/src/graphql/queries/index.js @@ -63,15 +63,13 @@ export const loadMore = (fetchMore) => ({limit, cursor, sort, tab, asset_id}) => asset_id }, updateQuery: (oldData, {fetchMoreResult:{comments}}) => { - const updatedData = { + return { ...oldData, [tab]: [ ...oldData[tab], ...comments ] }; - - return updatedData; } }); }; From 3c6391e741631c7758d377ceb1b5b8a19bb24031 Mon Sep 17 00:00:00 2001 From: riley Date: Wed, 3 May 2017 12:49:22 -0600 Subject: [PATCH 11/11] count should never be less than 0 --- .../coral-admin/src/graphql/mutations/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/coral-admin/src/graphql/mutations/index.js b/client/coral-admin/src/graphql/mutations/index.js index fdb82db9a..6b21c8421 100644 --- a/client/coral-admin/src/graphql/mutations/index.js +++ b/client/coral-admin/src/graphql/mutations/index.js @@ -79,10 +79,10 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { return { ...oldData, - premodCount, - flaggedCount, - acceptedCount, - rejectedCount, + premodCount: Math.max(0, premodCount), + flaggedCount: Math.max(0, flaggedCount), + acceptedCount: Math.max(0, acceptedCount), + rejectedCount: Math.max(0, rejectedCount), premod, flagged, accepted, @@ -124,10 +124,10 @@ export const setCommentStatus = graphql(SET_COMMENT_STATUS, { return { ...oldData, - premodCount, - flaggedCount, - acceptedCount, - rejectedCount, + premodCount: Math.max(0, premodCount), + flaggedCount: Math.max(0, flaggedCount), + acceptedCount: Math.max(0, acceptedCount), + rejectedCount: Math.max(0, rejectedCount), premod, flagged, accepted,