mutations: form HOC type based on the document prop & fix collection.edit.validate cb by assigning it to the modifier

This commit is contained in:
xavcz 2016-11-17 09:46:35 +01:00
parent 29585b2e9f
commit 3c913c437b
3 changed files with 9 additions and 7 deletions

View file

@ -13,14 +13,15 @@ export default function withEdit(WrappedComponent, options) {
}
render() {
const { mutationName, fragment, resultQuery, collection } = this.props
// if the mutation given to NovaForm isn't about editing an existing document, do nothing
if (mutationName.indexOf('Edit') === -1) {
// if the NovaForm mutation isn't about editing an existing document (it doesn't have one), do nothing
if (!this.props.document) {
return <WrappedComponent {...this.props} />
} else {
const { mutationName, fragment, resultQuery, collection } = this.props;
const collectionName = collection._name;

View file

@ -12,15 +12,16 @@ export default function withNew(WrappedComponent, options) {
}
render() {
const { mutationName, fragment, resultQuery, collection } = this.props
// if the mutation given to NovaForm isn't about creating a new document, do nothing
if (mutationName.indexOf('New') === -1) {
// if the NovaForm mutation isn't about creating a new document (it already has one), do nothing
if (this.props.document) {
return <WrappedComponent {...this.props} />
} else {
const { mutationName, fragment, resultQuery, collection } = this.props;
const collectionName = collection._name;
const ComponentWithMutation = graphql(gql`

View file

@ -131,7 +131,7 @@ const editMutation = ({ action, collection, documentId, set, unset, currentUser,
collection.simpleSchema().namedContext(`${collectionName}.edit`).validate(modifier, {modifier: true});
// run validation callbacks
document = Telescope.callbacks.run(`${collectionName}.edit.validate`, modifier, document, currentUser);
modifier = Telescope.callbacks.run(`${collectionName}.edit.validate`, modifier, document, currentUser);
}
// run sync callbacks (on mongo modifier)