From d15694041aec1057c5a11f8742622436bb7fd4a1 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 23 Jan 2018 20:27:46 +0100 Subject: [PATCH] Don't require notify property --- .../coral-admin/src/containers/BanUserDialog.js | 2 -- client/coral-admin/src/containers/UserDetail.js | 2 -- .../src/routes/Community/containers/People.js | 2 -- .../containers/RejectUsernameDialog.js | 2 -- .../routes/Configure/containers/Configure.js | 2 -- .../configure/containers/AssetStatusInfo.js | 12 ------------ .../src/tabs/configure/containers/Settings.js | 2 -- .../tabs/stream/containers/ChangeUsername.js | 15 +-------------- client/coral-framework/hocs/withMutation.js | 12 +++--------- client/coral-framework/hocs/withQuery.js | 13 ++++--------- plugin-api/beta/client/hocs/withTags.js | 7 +------ .../client/components/ModTag.js | 1 - .../client/containers/ModActionButton.js | 2 -- .../client/containers/ModTag.js | 2 -- .../client/containers/TabPane.js | 2 -- .../client/containers/ApproveCommentAction.js | 17 ++--------------- .../client/containers/BanUserDialog.js | 2 -- .../client/containers/RejectCommentAction.js | 17 ++--------------- 18 files changed, 13 insertions(+), 101 deletions(-) diff --git a/client/coral-admin/src/containers/BanUserDialog.js b/client/coral-admin/src/containers/BanUserDialog.js index 642f7f6ee..3617902ff 100644 --- a/client/coral-admin/src/containers/BanUserDialog.js +++ b/client/coral-admin/src/containers/BanUserDialog.js @@ -10,7 +10,6 @@ import { } from 'coral-framework/graphql/mutations'; import { compose } from 'react-apollo'; import t from 'coral-framework/services/i18n'; -import { notify } from 'coral-framework/actions/notification'; class BanUserDialogContainer extends Component { banUser = async () => { @@ -72,7 +71,6 @@ const mapDispatchToProps = dispatch => ({ ...bindActionCreators( { hideBanUserDialog, - notify, }, dispatch ), diff --git a/client/coral-admin/src/containers/UserDetail.js b/client/coral-admin/src/containers/UserDetail.js index 5b5c12bec..fb1508a2f 100644 --- a/client/coral-admin/src/containers/UserDetail.js +++ b/client/coral-admin/src/containers/UserDetail.js @@ -26,7 +26,6 @@ import UserDetailComment from './UserDetailComment'; import update from 'immutability-helper'; import { showBanUserDialog } from 'actions/banUserDialog'; import { showSuspendUserDialog } from 'actions/suspendUserDialog'; -import { notify } from 'coral-framework/actions/notification'; const commentConnectionFragment = gql` fragment CoralAdmin_UserDetail_CommentConnection on CommentConnection { @@ -272,7 +271,6 @@ const mapDispatchToProps = dispatch => ({ viewUserDetail, hideUserDetail, toggleSelectAllCommentInUserDetail, - notify, }, dispatch ), diff --git a/client/coral-admin/src/routes/Community/containers/People.js b/client/coral-admin/src/routes/Community/containers/People.js index d958d7378..f8271b236 100644 --- a/client/coral-admin/src/routes/Community/containers/People.js +++ b/client/coral-admin/src/routes/Community/containers/People.js @@ -16,7 +16,6 @@ import { appendNewNodes } from 'plugin-api/beta/client/utils'; import update from 'immutability-helper'; import { Spinner } from 'coral-ui'; import withQuery from 'coral-framework/hocs/withQuery'; -import { notify } from 'coral-framework/actions/notification'; class PeopleContainer extends React.Component { timer = null; @@ -132,7 +131,6 @@ const mapDispatchToProps = dispatch => viewUserDetail, showSuspendUserDialog, showBanUserDialog, - notify, }, dispatch ); diff --git a/client/coral-admin/src/routes/Community/containers/RejectUsernameDialog.js b/client/coral-admin/src/routes/Community/containers/RejectUsernameDialog.js index bf4490284..325eadfb5 100644 --- a/client/coral-admin/src/routes/Community/containers/RejectUsernameDialog.js +++ b/client/coral-admin/src/routes/Community/containers/RejectUsernameDialog.js @@ -4,7 +4,6 @@ import { hideRejectUsernameDialog } from '../../../actions/community'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { compose } from 'react-apollo'; -import { notify } from 'coral-framework/actions/notification'; const mapStateToProps = state => ({ user: state.community.user, @@ -15,7 +14,6 @@ const mapDispatchToProps = dispatch => bindActionCreators( { handleClose: hideRejectUsernameDialog, - notify, }, dispatch ); diff --git a/client/coral-admin/src/routes/Configure/containers/Configure.js b/client/coral-admin/src/routes/Configure/containers/Configure.js index 254e39d70..ce33fa1f4 100644 --- a/client/coral-admin/src/routes/Configure/containers/Configure.js +++ b/client/coral-admin/src/routes/Configure/containers/Configure.js @@ -12,7 +12,6 @@ import TechSettings from './TechSettings'; import ModerationSettings from './ModerationSettings'; import { clearPending, setActiveSection } from '../../../actions/configure'; import Configure from '../components/Configure'; -import { notify } from 'coral-framework/actions/notification'; class ConfigureContainer extends Component { savePending = async () => { @@ -83,7 +82,6 @@ const mapDispatchToProps = dispatch => { clearPending, setActiveSection, - notify, }, dispatch ); diff --git a/client/coral-embed-stream/src/tabs/configure/containers/AssetStatusInfo.js b/client/coral-embed-stream/src/tabs/configure/containers/AssetStatusInfo.js index c97d8e068..ed0746d29 100644 --- a/client/coral-embed-stream/src/tabs/configure/containers/AssetStatusInfo.js +++ b/client/coral-embed-stream/src/tabs/configure/containers/AssetStatusInfo.js @@ -7,9 +7,6 @@ import { withUpdateAssetStatus, withCloseAsset, } from 'coral-framework/graphql/mutations'; -import { notify } from 'coral-framework/actions/notification'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; class AssetStatusInfoContainer extends React.Component { openAsset = () => @@ -45,16 +42,7 @@ const withAssetStatusInfoFragments = withFragments({ `, }); -const mapDispatchToProps = dispatch => - bindActionCreators( - { - notify, - }, - dispatch - ); - const enhance = compose( - connect(null, mapDispatchToProps), withAssetStatusInfoFragments, withUpdateAssetStatus, withCloseAsset diff --git a/client/coral-embed-stream/src/tabs/configure/containers/Settings.js b/client/coral-embed-stream/src/tabs/configure/containers/Settings.js index 9bfeb149e..2058ceaa2 100644 --- a/client/coral-embed-stream/src/tabs/configure/containers/Settings.js +++ b/client/coral-embed-stream/src/tabs/configure/containers/Settings.js @@ -8,7 +8,6 @@ import { withUpdateAssetSettings } from 'coral-framework/graphql/mutations'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { clearPending, updatePending } from '../../../actions/configure'; -import { notify } from 'coral-framework/actions/notification'; const slots = ['streamSettings']; @@ -129,7 +128,6 @@ const mapDispatchToProps = dispatch => { clearPending, updatePending, - notify, }, dispatch ); diff --git a/client/coral-embed-stream/src/tabs/stream/containers/ChangeUsername.js b/client/coral-embed-stream/src/tabs/stream/containers/ChangeUsername.js index 098513aaf..cc0b84f02 100644 --- a/client/coral-embed-stream/src/tabs/stream/containers/ChangeUsername.js +++ b/client/coral-embed-stream/src/tabs/stream/containers/ChangeUsername.js @@ -1,18 +1,5 @@ import { compose } from 'react-apollo'; import { withChangeUsername } from 'coral-framework/graphql/mutations'; import ChangeUsername from '../components/ChangeUsername'; -import { notify } from 'coral-framework/actions/notification'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; -const mapDispatchToProps = dispatch => - bindActionCreators( - { - notify, - }, - dispatch - ); - -export default compose(connect(null, mapDispatchToProps), withChangeUsername)( - ChangeUsername -); +export default compose(withChangeUsername)(ChangeUsername); diff --git a/client/coral-framework/hocs/withMutation.js b/client/coral-framework/hocs/withMutation.js index d30598cf0..dae38071f 100644 --- a/client/coral-framework/hocs/withMutation.js +++ b/client/coral-framework/hocs/withMutation.js @@ -13,6 +13,7 @@ import PropTypes from 'prop-types'; import t from 'coral-framework/services/i18n'; import hoistStatics from 'recompose/hoistStatics'; import union from 'lodash/union'; +import { notify } from 'coral-framework/actions/notification'; class ResponseErrors extends Error { constructor(errors) { @@ -55,14 +56,7 @@ const createHOC = (document, config, { notifyOnError = true }) => } notifyErrors(messages) { - if (this.props.notify) { - this.props.notify('error', messages); - } else { - console.error( - '`notifyOnError` is set to `true` but missing `notify` property' - ); - console.error(messages); - } + this.context.store.dispatch(notify('error', messages)); } resolveDocument(documentOrCallback) { @@ -240,7 +234,7 @@ const createHOC = (document, config, { notifyOnError = true }) => * * The returned HOC accepts a settings object with the following properties: * notifyOnError: show a notification to the user when an error occured. - * Defaults to true, requires the `notify` action to be mounted. + * Defaults to true. */ export default (document, config = {}) => settingsOrComponent => { if (typeof settingsOrComponent === 'function') { diff --git a/client/coral-framework/hocs/withQuery.js b/client/coral-framework/hocs/withQuery.js index ec5433609..c4b9074b4 100644 --- a/client/coral-framework/hocs/withQuery.js +++ b/client/coral-framework/hocs/withQuery.js @@ -10,6 +10,7 @@ import hoistStatics from 'recompose/hoistStatics'; import { getOperationName } from 'apollo-client/queries/getFromAST'; import throttle from 'lodash/throttle'; import get from 'lodash/get'; +import { notify } from 'coral-framework/actions/notification'; const withSkipOnErrors = reducer => (prev, action, ...rest) => { if ( @@ -49,6 +50,7 @@ const createHOC = (document, config, { notifyOnError = true }) => eventEmitter: PropTypes.object, graphql: PropTypes.object, client: PropTypes.object, + store: PropTypes.object, }; static propTypes = { @@ -169,14 +171,7 @@ const createHOC = (document, config, { notifyOnError = true }) => }; notifyErrors(messages) { - if (this.props.notify) { - this.props.notify('error', messages); - } else { - console.error( - '`notifyOnError` is set to `true` but missing `notify` property' - ); - console.error(messages); - } + this.context.store.dispatch(notify('error', messages)); } nextData(data) { @@ -349,7 +344,7 @@ const createHOC = (document, config, { notifyOnError = true }) => * * The returned HOC accepts a settings object with the following properties: * notifyOnError: show a notification to the user when an error occured. - * Defaults to true, requires the `notify` action to be mounted. + * Defaults to true. */ export default (document, config = {}) => settingsOrComponent => { if (typeof settingsOrComponent === 'function') { diff --git a/plugin-api/beta/client/hocs/withTags.js b/plugin-api/beta/client/hocs/withTags.js index 469718ef9..958028a4b 100644 --- a/plugin-api/beta/client/hocs/withTags.js +++ b/plugin-api/beta/client/hocs/withTags.js @@ -1,12 +1,10 @@ import React from 'react'; import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; import { compose, gql } from 'react-apollo'; import { getDisplayName } from 'coral-framework/helpers/hoc'; import { capitalize } from 'coral-framework/helpers/strings'; import { withAddTag, withRemoveTag } from 'coral-framework/graphql/mutations'; import withFragments from 'coral-framework/hocs/withFragments'; -import { notify } from 'coral-framework/actions/notification'; import { isTagged } from 'coral-framework/utils'; import hoistStatics from 'recompose/hoistStatics'; import { getDefinitionName } from '../utils'; @@ -112,9 +110,6 @@ export default (tag, options = {}) => user: state.auth.user, }); - const mapDispatchToProps = dispatch => - bindActionCreators({ notify }, dispatch); - const enhance = compose( withFragments({ ...fragments, @@ -144,7 +139,7 @@ export default (tag, options = {}) => }), withAddTag, withRemoveTag, - connect(mapStateToProps, mapDispatchToProps) + connect(mapStateToProps, null) ); WithTags.displayName = `WithTags(${getDisplayName(WrappedComponent)})`; diff --git a/plugins/talk-plugin-featured-comments/client/components/ModTag.js b/plugins/talk-plugin-featured-comments/client/components/ModTag.js index 420ee9417..659b2cea4 100644 --- a/plugins/talk-plugin-featured-comments/client/components/ModTag.js +++ b/plugins/talk-plugin-featured-comments/client/components/ModTag.js @@ -64,7 +64,6 @@ export default class ModTag extends React.Component { ModTag.propTypes = { alreadyTagged: PropTypes.bool, deleteTag: PropTypes.func, - notify: PropTypes.func, openFeaturedDialog: PropTypes.func, comment: PropTypes.object, asset: PropTypes.object, diff --git a/plugins/talk-plugin-featured-comments/client/containers/ModActionButton.js b/plugins/talk-plugin-featured-comments/client/containers/ModActionButton.js index ea20bddec..7c8f94fb3 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/ModActionButton.js +++ b/plugins/talk-plugin-featured-comments/client/containers/ModActionButton.js @@ -3,12 +3,10 @@ import { bindActionCreators } from 'redux'; import ModActionButton from '../components/ModActionButton'; import { withTags, connect } from 'plugin-api/beta/client/hocs'; import { closeMenu } from 'plugins/talk-plugin-moderation-actions/client/actions'; -import { notify } from 'plugin-api/beta/client/actions/notification'; const mapDispatchToProps = dispatch => bindActionCreators( { - notify, closeMenu, }, dispatch diff --git a/plugins/talk-plugin-featured-comments/client/containers/ModTag.js b/plugins/talk-plugin-featured-comments/client/containers/ModTag.js index f120e6f1a..42c653418 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/ModTag.js +++ b/plugins/talk-plugin-featured-comments/client/containers/ModTag.js @@ -3,12 +3,10 @@ import { withTags, connect } from 'plugin-api/beta/client/hocs'; import { gql, compose } from 'react-apollo'; import { bindActionCreators } from 'redux'; import { openFeaturedDialog } from '../actions'; -import { notify } from 'plugin-api/beta/client/actions/notification'; const mapDispatchToProps = dispatch => bindActionCreators( { - notify, openFeaturedDialog, }, dispatch diff --git a/plugins/talk-plugin-featured-comments/client/containers/TabPane.js b/plugins/talk-plugin-featured-comments/client/containers/TabPane.js index 5bf92fb0a..297f5aedf 100644 --- a/plugins/talk-plugin-featured-comments/client/containers/TabPane.js +++ b/plugins/talk-plugin-featured-comments/client/containers/TabPane.js @@ -4,7 +4,6 @@ import { compose, gql } from 'react-apollo'; import TabPane from '../components/TabPane'; import { withFragments, connect } from 'plugin-api/beta/client/hocs'; import Comment from '../containers/Comment'; -import { notify } from 'plugin-api/beta/client/actions/notification'; import { viewComment } from 'coral-embed-stream/src/actions/stream'; import { appendNewNodes, @@ -81,7 +80,6 @@ const mapDispatchToProps = dispatch => bindActionCreators( { viewComment, - notify, }, dispatch ); diff --git a/plugins/talk-plugin-moderation-actions/client/containers/ApproveCommentAction.js b/plugins/talk-plugin-moderation-actions/client/containers/ApproveCommentAction.js index 83402115b..1f7bed3bb 100644 --- a/plugins/talk-plugin-moderation-actions/client/containers/ApproveCommentAction.js +++ b/plugins/talk-plugin-moderation-actions/client/containers/ApproveCommentAction.js @@ -1,9 +1,7 @@ import React from 'react'; import { compose } from 'react-apollo'; -import { bindActionCreators } from 'redux'; -import { notify } from 'plugin-api/beta/client/actions/notification'; import ApproveCommentAction from '../components/ApproveCommentAction'; -import { connect, withSetCommentStatus } from 'plugin-api/beta/client/hocs'; +import { withSetCommentStatus } from 'plugin-api/beta/client/hocs'; class ApproveCommentActionContainer extends React.Component { approveComment = async () => { @@ -27,17 +25,6 @@ class ApproveCommentActionContainer extends React.Component { } } -const mapDispatchToProps = dispatch => - bindActionCreators( - { - notify, - }, - dispatch - ); - -const enhance = compose( - connect(null, mapDispatchToProps), - withSetCommentStatus -); +const enhance = compose(withSetCommentStatus); export default enhance(ApproveCommentActionContainer); diff --git a/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js b/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js index fc7117298..8dd3cce7d 100644 --- a/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js +++ b/plugins/talk-plugin-moderation-actions/client/containers/BanUserDialog.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import { compose } from 'react-apollo'; import { bindActionCreators } from 'redux'; import { closeBanDialog, closeMenu } from '../actions'; -import { notify } from 'plugin-api/beta/client/actions/notification'; import { connect, withSetCommentStatus, @@ -64,7 +63,6 @@ const mapStateToProps = ({ talkPluginModerationActions: state }) => ({ const mapDispatchToProps = dispatch => bindActionCreators( { - notify, closeBanDialog, closeMenu, }, diff --git a/plugins/talk-plugin-moderation-actions/client/containers/RejectCommentAction.js b/plugins/talk-plugin-moderation-actions/client/containers/RejectCommentAction.js index 498eae0f5..54ca0420d 100644 --- a/plugins/talk-plugin-moderation-actions/client/containers/RejectCommentAction.js +++ b/plugins/talk-plugin-moderation-actions/client/containers/RejectCommentAction.js @@ -1,9 +1,7 @@ import React from 'react'; import { compose } from 'react-apollo'; -import { bindActionCreators } from 'redux'; -import { notify } from 'plugin-api/beta/client/actions/notification'; import RejectCommentAction from '../components/RejectCommentAction'; -import { connect, withSetCommentStatus } from 'plugin-api/beta/client/hocs'; +import { withSetCommentStatus } from 'plugin-api/beta/client/hocs'; class RejectCommentActionContainer extends React.Component { rejectComment = async () => { @@ -22,17 +20,6 @@ class RejectCommentActionContainer extends React.Component { } } -const mapDispatchToProps = dispatch => - bindActionCreators( - { - notify, - }, - dispatch - ); - -const enhance = compose( - connect(null, mapDispatchToProps), - withSetCommentStatus -); +const enhance = compose(withSetCommentStatus); export default enhance(RejectCommentActionContainer);