From 22dd58114b8883d267a4f061e71f6faffad31d2c Mon Sep 17 00:00:00 2001 From: xavcz Date: Tue, 22 Nov 2016 18:39:50 -0500 Subject: [PATCH] get rid of nova:base-containers, move graphql vote-related code to nova:voting, undo mistake on some user fields --- .meteor/packages | 1 - .meteor/versions | 1 - packages/nova-apollo/lib/schema.js | 13 -- .../nova-base-components/lib/common/App.jsx | 4 +- .../nova-base-components/lib/common/Vote.jsx | 4 +- .../lib/users/UsersEditForm.jsx | 4 +- .../lib/users/UsersProfile.jsx | 4 +- packages/nova-base-containers/README.md | 1 - packages/nova-base-containers/lib/client.js | 7 -- packages/nova-base-containers/lib/server.js | 7 -- packages/nova-base-containers/package.js | 24 ---- .../nova-notifications/lib/custom_fields.js | 112 +++++++++--------- packages/nova-voting/lib/client.js | 4 +- .../lib/containers/withVote.js} | 12 +- packages/nova-voting/lib/graphql.js | 44 +++++++ packages/nova-voting/lib/modules.js | 7 +- packages/nova-voting/lib/schema.js | 29 ----- packages/nova-voting/lib/server.js | 4 +- 18 files changed, 121 insertions(+), 161 deletions(-) delete mode 100644 packages/nova-base-containers/README.md delete mode 100644 packages/nova-base-containers/lib/client.js delete mode 100644 packages/nova-base-containers/lib/server.js delete mode 100644 packages/nova-base-containers/package.js rename packages/{nova-base-containers/lib/mutations/withVoteMutation.js => nova-voting/lib/containers/withVote.js} (62%) create mode 100644 packages/nova-voting/lib/graphql.js delete mode 100644 packages/nova-voting/lib/schema.js diff --git a/.meteor/packages b/.meteor/packages index c38fa0ca9..8a0f8343a 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -28,7 +28,6 @@ nova:apollo # do not remove! ############ Customizable Packages ############ -nova:base-containers # default data containers nova:base-components # default ui components nova:base-styles # default styling nova:base-routes # default routes diff --git a/.meteor/versions b/.meteor/versions index 2bd1ff706..3aeab0b44 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -66,7 +66,6 @@ mongo-id@1.0.6 nova:api@0.27.4-nova nova:apollo@0.27.4-nova nova:base-components@0.27.4-nova -nova:base-containers@0.27.4-nova nova:base-routes@0.27.4-nova nova:base-styles@0.27.4-nova nova:categories@0.27.4-nova diff --git a/packages/nova-apollo/lib/schema.js b/packages/nova-apollo/lib/schema.js index 4b3bf94ce..99c76582d 100644 --- a/packages/nova-apollo/lib/schema.js +++ b/packages/nova-apollo/lib/schema.js @@ -1,18 +1,5 @@ import Telescope from 'meteor/nova:lib'; -console.log(` - ${Telescope.graphQL.getCollectionsSchemas()} - ${Telescope.graphQL.getAdditionalSchemas()} - - type Query { - ${Telescope.graphQL.queries.join('\n')} - } - - type Mutation { - ${Telescope.graphQL.mutations.join('\n')} - } -`); - const generateTypeDefs = () => [` ${Telescope.graphQL.getCollectionsSchemas()} ${Telescope.graphQL.getAdditionalSchemas()} diff --git a/packages/nova-base-components/lib/common/App.jsx b/packages/nova-base-components/lib/common/App.jsx index d4ddc4176..89bbaab55 100644 --- a/packages/nova-base-components/lib/common/App.jsx +++ b/packages/nova-base-components/lib/common/App.jsx @@ -82,8 +82,8 @@ const currentUserContainer = graphql( __htmlBio __karma __newsletter_subscribeToNewsletter - #__notifications_users - #__notifications_posts + __notifications_users + __notifications_posts __postCount __slug __twitterUsername diff --git a/packages/nova-base-components/lib/common/Vote.jsx b/packages/nova-base-components/lib/common/Vote.jsx index cdfa2893c..574c448e6 100644 --- a/packages/nova-base-components/lib/common/Vote.jsx +++ b/packages/nova-base-components/lib/common/Vote.jsx @@ -4,7 +4,7 @@ import classNames from 'classnames'; import Users from 'meteor/nova:users'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; -import { withVoteMutation } from 'meteor/nova:base-containers'; +import withVote from 'meteor/nova:voting'; import { withCurrentUser } from 'meteor/nova:core'; class Vote extends Component { @@ -87,4 +87,4 @@ Vote.contextTypes = { const mapStateToProps = state => ({ messages: state.messages }); const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch); -Telescope.registerComponent('Vote', Vote, withCurrentUser, connect(mapStateToProps, mapDispatchToProps), withVoteMutation); \ No newline at end of file +Telescope.registerComponent('Vote', Vote, withCurrentUser, connect(mapStateToProps, mapDispatchToProps), withVote); \ No newline at end of file diff --git a/packages/nova-base-components/lib/users/UsersEditForm.jsx b/packages/nova-base-components/lib/users/UsersEditForm.jsx index 18e2f8cf5..d7ce326ae 100644 --- a/packages/nova-base-components/lib/users/UsersEditForm.jsx +++ b/packages/nova-base-components/lib/users/UsersEditForm.jsx @@ -4,7 +4,7 @@ import { FormattedMessage, intlShape } from 'react-intl'; import { Row, Col } from 'react-bootstrap'; import NovaForm from "meteor/nova:forms"; import Users from 'meteor/nova:users'; -import { withUsersSingle } from 'meteor/nova:base-containers'; +import { withSingle } from 'meteor/nova:core'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; @@ -57,4 +57,4 @@ UsersEditForm.displayName = "UsersEditForm"; const mapStateToProps = state => ({ messages: state.messages, }); const mapDispatchToProps = dispatch => bindActionCreators(Telescope.actions.messages, dispatch); -Telescope.registerComponent('UsersEditForm', UsersEditForm, connect(mapStateToProps, mapDispatchToProps)/*, withUsersSingle*/); \ No newline at end of file +Telescope.registerComponent('UsersEditForm', UsersEditForm, connect(mapStateToProps, mapDispatchToProps)/*, withSingle*/); \ No newline at end of file diff --git a/packages/nova-base-components/lib/users/UsersProfile.jsx b/packages/nova-base-components/lib/users/UsersProfile.jsx index 1f90159a0..d2d530255 100644 --- a/packages/nova-base-components/lib/users/UsersProfile.jsx +++ b/packages/nova-base-components/lib/users/UsersProfile.jsx @@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl'; import Posts from "meteor/nova:posts"; import Users from 'meteor/nova:users'; import { Link } from 'react-router'; -import { withUsersSingle } from 'meteor/nova:base-containers'; +import { withSingle } from 'meteor/nova:core'; const UsersProfile = (props) => { console.log(props) @@ -44,4 +44,4 @@ UsersProfile.propTypes = { UsersProfile.displayName = "UsersProfile"; -Telescope.registerComponent('UsersProfile', UsersProfile/*, withUsersSingle*/); +Telescope.registerComponent('UsersProfile', UsersProfile/*, withSingle*/); diff --git a/packages/nova-base-containers/README.md b/packages/nova-base-containers/README.md deleted file mode 100644 index 9fdfee4a7..000000000 --- a/packages/nova-base-containers/README.md +++ /dev/null @@ -1 +0,0 @@ -Nova basic React containers: they fetch data thanks to Apollo and give them back to React components in `nova:base-components`. \ No newline at end of file diff --git a/packages/nova-base-containers/lib/client.js b/packages/nova-base-containers/lib/client.js deleted file mode 100644 index 874fde7a3..000000000 --- a/packages/nova-base-containers/lib/client.js +++ /dev/null @@ -1,7 +0,0 @@ -import withVoteMutation from './mutations/withVoteMutation.js'; - -export { - - // mutation containers - withVoteMutation, -} diff --git a/packages/nova-base-containers/lib/server.js b/packages/nova-base-containers/lib/server.js deleted file mode 100644 index 874fde7a3..000000000 --- a/packages/nova-base-containers/lib/server.js +++ /dev/null @@ -1,7 +0,0 @@ -import withVoteMutation from './mutations/withVoteMutation.js'; - -export { - - // mutation containers - withVoteMutation, -} diff --git a/packages/nova-base-containers/package.js b/packages/nova-base-containers/package.js deleted file mode 100644 index 52fddccd7..000000000 --- a/packages/nova-base-containers/package.js +++ /dev/null @@ -1,24 +0,0 @@ -Package.describe({ - name: "nova:base-containers", - summary: "Telescope containers package", - version: "0.27.4-nova", - git: "https://github.com/TelescopeJS/Telescope.git" -}); - -Package.onUse(function (api) { - - api.versionsFrom(['METEOR@1.0']); - - api.use([ - // Nova packages - 'nova:core@0.27.4-nova', - 'nova:posts@0.27.4-nova', - 'nova:users@0.27.4-nova', - 'nova:comments@0.27.4-nova', - 'nova:categories@0.27.4-nova', - ]); - - api.mainModule("lib/server.js", "server"); - api.mainModule("lib/client.js", "client"); - -}); diff --git a/packages/nova-notifications/lib/custom_fields.js b/packages/nova-notifications/lib/custom_fields.js index 3a2614082..77149215a 100644 --- a/packages/nova-notifications/lib/custom_fields.js +++ b/packages/nova-notifications/lib/custom_fields.js @@ -11,60 +11,60 @@ const canInsert = user => Users.canDo(user, "users.new"); const canEdit = Users.canEdit; // Add notifications options to user profile settings -// Users.addField([ -// { -// fieldName: '__notifications_users', -// fieldSchema: { -// label: 'New users', -// type: Boolean, -// optional: true, -// defaultValue: false, -// control: "checkbox", -// insertableIf: Users.isAdmin, -// editableIf: Users.isAdmin, -// group: notificationsGroup -// } -// }, -// { -// fieldName: '__notifications_posts', -// fieldSchema: { -// label: 'New posts', -// type: Boolean, -// optional: true, -// defaultValue: false, -// control: "checkbox", -// insertableIf: canInsert, -// editableIf: canEdit, -// group: notificationsGroup -// } -// } -// ]); +Users.addField([ + { + fieldName: '__notifications_users', + fieldSchema: { + label: 'New users', + type: Boolean, + optional: true, + defaultValue: false, + control: "checkbox", + insertableIf: Users.isAdmin, + editableIf: Users.isAdmin, + group: notificationsGroup + } + }, + { + fieldName: '__notifications_posts', + fieldSchema: { + label: 'New posts', + type: Boolean, + optional: true, + defaultValue: false, + control: "checkbox", + insertableIf: canInsert, + editableIf: canEdit, + group: notificationsGroup + } + } +]); -// if (typeof Comments !== "undefined") { -// Users.addField([ -// { -// fieldName: '__notifications_comments', -// fieldSchema: { -// label: 'Comments on my posts', -// type: Boolean, -// optional: true, -// defaultValue: true, -// control: "checkbox", -// insertableIf: canInsert, -// editableIf: canEdit -// } -// }, -// { -// fieldName: '__notifications_replies', -// fieldSchema: { -// label: 'Replies to my comments', -// type: Boolean, -// optional: true, -// defaultValue: true, -// control: "checkbox", -// insertableIf: canInsert, -// editableIf: canEdit -// } -// } -// ]); -// } +if (typeof Comments !== "undefined") { + Users.addField([ + { + fieldName: '__notifications_comments', + fieldSchema: { + label: 'Comments on my posts', + type: Boolean, + optional: true, + defaultValue: true, + control: "checkbox", + insertableIf: canInsert, + editableIf: canEdit + } + }, + { + fieldName: '__notifications_replies', + fieldSchema: { + label: 'Replies to my comments', + type: Boolean, + optional: true, + defaultValue: true, + control: "checkbox", + insertableIf: canInsert, + editableIf: canEdit + } + } + ]); +} diff --git a/packages/nova-voting/lib/client.js b/packages/nova-voting/lib/client.js index c17539021..79744cd0e 100644 --- a/packages/nova-voting/lib/client.js +++ b/packages/nova-voting/lib/client.js @@ -1 +1,3 @@ -import './modules'; \ No newline at end of file +import withVote from './modules'; + +export default withVote; \ No newline at end of file diff --git a/packages/nova-base-containers/lib/mutations/withVoteMutation.js b/packages/nova-voting/lib/containers/withVote.js similarity index 62% rename from packages/nova-base-containers/lib/mutations/withVoteMutation.js rename to packages/nova-voting/lib/containers/withVote.js index 706032ea9..a3bfc9c8e 100644 --- a/packages/nova-base-containers/lib/mutations/withVoteMutation.js +++ b/packages/nova-voting/lib/containers/withVote.js @@ -3,16 +3,8 @@ import React, { PropTypes, Component } from 'react'; import { graphql } from 'react-apollo'; import gql from 'graphql-tag'; -// to be moved in nova:voting -// Telescope.graphQL.addMutation('postsVote(documentId: String, voteType: String) : Post'); -// postsVote(root, {documentId, voteType}, context) { -// Meteor._sleepForMs(2000); // wait 2 seconds for demonstration purpose -// console.log("sleep done"); -// const post = Posts.findOne(documentId); -// return context.Users.canDo(context.currentUser, `posts.${voteType}`) ? Telescope.operateOnItem(context.Posts, post, context.currentUser, voteType) : false; -// }, - -export default function withVoteMutation (component, options) { +// to adapt like withNew? or withSingle? +export default function withVote(component) { return graphql(gql` mutation postsVote($documentId: String, $voteType: String) { postsVote(documentId: $documentId, voteType: $voteType) { diff --git a/packages/nova-voting/lib/graphql.js b/packages/nova-voting/lib/graphql.js new file mode 100644 index 000000000..8ef13d1ba --- /dev/null +++ b/packages/nova-voting/lib/graphql.js @@ -0,0 +1,44 @@ +import Telescope from 'meteor/nova:lib'; + +/** + * @summary Vote schema + * @type {SimpleSchema} + */ +Telescope.schemas.votes = new SimpleSchema({ + itemId: { + type: String + }, + power: { + type: Number, + optional: true + }, + votedAt: { + type: Date, + optional: true + } +}); + +const voteSchema = ` + type Vote { + itemId: String + power: Float + votedAt: String + } +`; + +Telescope.graphQL.addSchema(voteSchema); + +Telescope.graphQL.addMutation('postsVote(documentId: String, voteType: String) : Post'); + +const voteResolver = { + Mutation: { + postsVote(root, {documentId, voteType}, context) { + Meteor._sleepForMs(2000); // wait 2 seconds for demonstration purpose + console.log("sleep done"); + const post = Posts.findOne(documentId); + return context.Users.canDo(context.currentUser, `posts.${voteType}`) ? Telescope.operateOnItem(context.Posts, post, context.currentUser, voteType) : false; + }, + }, +}; + +Telescope.graphQL.addResolvers(voteResolver); \ No newline at end of file diff --git a/packages/nova-voting/lib/modules.js b/packages/nova-voting/lib/modules.js index 910d98845..0ff504660 100644 --- a/packages/nova-voting/lib/modules.js +++ b/packages/nova-voting/lib/modules.js @@ -1,3 +1,6 @@ -import './schema.js'; +import './graphql.js'; import './custom_fields.js'; -import './vote.js'; \ No newline at end of file +import './vote.js'; +import withVote from './containers/withVote.js'; + +export default withVote; \ No newline at end of file diff --git a/packages/nova-voting/lib/schema.js b/packages/nova-voting/lib/schema.js deleted file mode 100644 index e975ed963..000000000 --- a/packages/nova-voting/lib/schema.js +++ /dev/null @@ -1,29 +0,0 @@ -import Telescope from 'meteor/nova:lib'; - -/** - * @summary Vote schema - * @type {SimpleSchema} - */ -Telescope.schemas.votes = new SimpleSchema({ - itemId: { - type: String - }, - power: { - type: Number, - optional: true - }, - votedAt: { - type: Date, - optional: true - } -}); - -const voteSchema = ` - type Vote { - itemId: String - power: Float - votedAt: String - } -`; - -Telescope.graphQL.addSchema(voteSchema); \ No newline at end of file diff --git a/packages/nova-voting/lib/server.js b/packages/nova-voting/lib/server.js index a621e9e27..3dec38eeb 100644 --- a/packages/nova-voting/lib/server.js +++ b/packages/nova-voting/lib/server.js @@ -1,4 +1,6 @@ import './server/scoring.js'; import './server/cron.js'; -import './modules.js'; \ No newline at end of file +import withVote from './modules'; + +export default withVote; \ No newline at end of file