scroll import action to import section of settings page

This commit is contained in:
Ron Rennick 2019-08-14 14:35:28 -03:00
parent d3c1d34a60
commit d2b48f0fcd
2 changed files with 13 additions and 2 deletions

View File

@ -4,7 +4,7 @@
*/
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Component, Fragment } from '@wordpress/element';
import { Component, Fragment, createRef } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { partial, remove, transform } from 'lodash';
import { withDispatch } from '@wordpress/data';
@ -39,12 +39,15 @@ class Settings extends Component {
isDirty: false,
};
this.importRef = createRef();
this.handleInputChange = this.handleInputChange.bind( this );
this.warnIfUnsavedChanges = this.warnIfUnsavedChanges.bind( this );
this.scrollToImport = this.scrollToImport.bind( this );
}
componentDidMount() {
window.addEventListener( 'beforeunload', this.warnIfUnsavedChanges );
setTimeout( this.scrollToImport, 250 );
}
componentWillUnmount() {
@ -162,6 +165,13 @@ class Settings extends Component {
this.setState( { settings, isDirty: true } );
}
scrollToImport() {
const { query } = this.props;
if ( query.import === 'true' ) {
window.scrollTo( 0, this.importRef.current.offsetTop );
}
}
render() {
const { createNotice } = this.props;
const { hasError } = this.state;
@ -190,6 +200,7 @@ class Settings extends Component {
</Button>
</div>
</div>
<span ref={ this.importRef } />
<HistoricalData createNotice={ createNotice } />
</Fragment>
);

View File

@ -52,7 +52,7 @@ class WC_Admin_Notes_Historical_Data {
$note->add_action(
'get-started',
__( 'Get Started', 'woocommerce-admin' ),
'?page=wc-admin&path=/analytics/settings',
'?page=wc-admin&path=/analytics/settings&import=true',
'actioned',
true
);