-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Site Settings Export components #7347
Conversation
} = this.props; | ||
const exportAll = () => this.props.startExport( siteId ); | ||
const exportSelectedItems = () => this.props.startExport( siteId, { exportAll: false } ); | ||
const fetchStatus = () => this.props.exportStatusFetch( siteId ); |
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.
I feel like you can get rid of these three function variables and the need to get this.props.siteId
if you add them to mapDispatchToProps
and just pass them as this.props.exportAll
, this.props.exportSelectedItems
and this.props.fetchStatus
. Then mapDispatchToProps
would look something like:
function dispatchStartExportEvent( dispatch, siteId, options ) {
analytics.tracks.recordEvent( 'calypso_export_start_button_click', {
scope: ( options && options.exportAll === false ) ? 'selected' : 'all'
} );
dispatch( startExport( siteId, options ) );
}
function mapDispatchToProps( dispatch, ownProps ) {
const { siteId } = ownProps;
const exportStatusFetch = flowRight( dispatch, exportStatusFetch );
return {
advancedSettingsFetch: flowRight( dispatch, advancedSettingsFetch ),
setPostType: flowRight( dispatch, setPostType ),
exportAll: () => dispatchStartExportEvent( dispatch, siteId ),
exportSelectedItems: () => dispatchStartExportEvent( dispatch, siteId, { exportAll: false } ),
fetchStatus: () => exportStatusFetch( siteId ),
};
}
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.
I like this idea and agree the functions seemed superfluous, but went a slightly different direction. In 1449623 I moved the analytics recording out from the connect statement and into the component. Generally I prefer to keep the connect
to the minimum required logic to connect what's needed with Redux. That way, anything non-Redux related isn't dependant on Redux logic and can live inside the component.
Btw, in the example above siteId
won't actually be passed in via ownProps
, as connect
won't include props from the mapStateToProps
. It's possible to add a third parameter to the connect
statement (mergeProps
) which combines the two, but generally it makes more sense to move the logic into the React component, or, as In this case, move the siteId
to the parent component so that it does get passed in via ownProps
.
@jordwest I commented on some of the code though I know some of it was probably already there and you just moved it around. I didn't actually test the branch yet but I will a bit later today and comment on my experience if I find anything weird. |
Thanks for taking a look @omarjackman! I've made some changes and left inline replies |
* External dependencies | ||
*/ | ||
import { localize } from 'i18n-calypso'; | ||
import flowRight from 'lodash/flowRight'; |
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.
we're now importing directly from lodash
due to a babel transform that pulls out the modular components for us, so you can now comfortably do this…
import {
flowRight
} from 'lodash';
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.
Fixed in ea32d98
d730b40
to
1dd4622
Compare
nice changes @jordwest - I don't know about you, but I like the way that analytics calling looks now better than mixed into the component. |
Thanks for the tip @dmsnell. I didn't even realize we had analytics in Redux, and I like the composability :) Currently it seems to have broken exporting though, will look into that and then mark it for review again |
This arranges the export and guided transfer component files into a heirarchy more closely matching the way they are displayed on the page, and improves separation of concerns. Prior to this change, the export component and guided transfer state were intermingled with a long list of props. This separates the two and adds Redux connectors where necessary to ensure each card only has access to the state it requires.
a738f64
to
000c172
Compare
The components under
client/my-sites/exporter
had grown over time and the structure was becoming confusing. This arranges the export and guided transfer component files into a heirarchy more closely matching the way they are displayed on the page, and improves separation of concerns.Prior to this change, the export component and guided transfer state were intermingled with a long list of props. This separates the two and adds Redux connectors where necessary to ensure each card only has access to the state it requires.
Before
After
How to test
Test live: https://calypso.live/?branch=update/exporter/reorganize-components