This repository was archived by the owner on Dec 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Fix/111895 event venue separation logic presentation #238
Merged
paulmskim
merged 5 commits into
master
from
fix/111895-event-venue-separation-logic-presentation
Aug 14, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
82a15c5
initial separation of container and template
paulmskim 73cf169
move onFormSubmit and onItemSelect functions to container
paulmskim efb9b79
move onCreateNew and removeVenue to container
paulmskim c9b0763
move editVenue to container
paulmskim 89c00d6
changelog
paulmskim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 themaybeRemoveEntry()
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 callremoveEntry()
. Themaybe
obscures the logic and makes the code difficult to follow.I've created a ticket here for this: https://central.tri.be/issues/112316
There was a problem hiding this comment.
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.