Skip to content
This repository was archived by the owner on Dec 22, 2020. It is now read-only.

Fix/111895 event venue separation logic presentation #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This plugin is our first attempt at integrating the Event post type with the Gut
#### 0.2.7-alpha - TBD

* Tweak - Use event timezone as default value
* Tweak - Separate logic and presentation in event venue block
* Fix - Allow removal of organizers from classic block if the organizer block is removed

#### 0.2.6-alpha - 2018-08-10
Expand Down
80 changes: 80 additions & 0 deletions src/modules/blocks/event-venue/container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';
import { compose, bindActionCreators } from 'redux';

/**
* Internal dependencies
*/
import EventVenue from './template';
import { toVenue } from 'elements';
import { withStore, withSaveData, withDetails, withForm } from 'editor/hoc';
import { actions, selectors } from 'data/blocks/venue';
import { VENUE } from 'editor/post-types';

const setVenue = ( dispatch ) => ( id ) => {
const { setVenue, setShowMap, setShowMapLink } = actions;
dispatch( setVenue( id ) );
dispatch( setShowMap( true ) );
dispatch( setShowMapLink( true ) );
};

const onFormComplete = ( dispatch, ownProps ) => ( body ) => {
const { setDetails } = ownProps;
const { id } = body;
setDetails( id, body );
setVenue( dispatch )( id );
};

const onFormSubmit = ( dispatch, ownProps ) => ( fields ) => (
ownProps.sendForm( toVenue( fields ), onFormComplete( dispatch, ownProps ) )
);

const onItemSelect = ( dispatch ) => setVenue( dispatch );

const onCreateNew = ( ownProps ) => ( title ) => ownProps.createDraft( {
title: {
rendered: title,
},
} );

// TODO: need to remove the use of "maybe" functions as they hold logic they
// ultimately should not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be ideal to add in expand on this comment a bit on what's specific set of logic the comment is referring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a general comment for all maybe functions, the logic in each one differs. In this case, it's the maybeRemoveEntry() function which has checks for empty details. We should be doing this check outside the function instead (or simply check for venue id as the id and details should exist together) and call removeEntry(). The maybe obscures the logic and makes the code difficult to follow.

I've created a ticket here for this: https://central.tri.be/issues/112316

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Great thanks for the heads up just wanted to make sure it's clear in case someone else works on this.

const removeVenue = ( dispatch, ownProps ) => () => {
const { volatile, maybeRemoveEntry, details } = ownProps;

dispatch( actions.removeVenue() );
if ( volatile ) {
maybeRemoveEntry( details );
}
};

const editVenue = ( ownProps ) => () => {
const { details, editEntry } = ownProps;
editEntry( details );
};

const mapStateToProps = ( state ) => ( {
venue: selectors.getVenue( state ),
showMapLink: selectors.getshowMapLink( state ),
showMap: selectors.getshowMap( state ),
} );

const mapDispatchToProps = ( dispatch, ownProps ) => ( {
...bindActionCreators( actions, dispatch ),
onFormSubmit: onFormSubmit( dispatch, ownProps ),
onItemSelect: onItemSelect( dispatch ),
onCreateNew: onCreateNew( ownProps ),
removeVenue: removeVenue( dispatch, ownProps ),
editVenue: editVenue( ownProps ),
} );

export default compose(
withStore( { postType: VENUE } ),
connect( mapStateToProps ),
withDetails( 'venue' ),
withForm( ( props ) => props.name ),
connect( null, mapDispatchToProps ),
withSaveData(),
)( EventVenue );
6 changes: 2 additions & 4 deletions src/modules/blocks/event-venue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import EventVenue from './block';
import { withStore } from 'editor/hoc';
import EventVenue from './container';
import { Icons } from 'elements';
import { VENUE } from 'editor/post-types';

/**
* Module Code
Expand Down Expand Up @@ -50,7 +48,7 @@ export default {
},
},

edit: withStore( { postType: VENUE } )( EventVenue ),
edit: EventVenue,

save( props ) {
return null;
Expand Down
Loading