From d2b48f0fcd3bccc9e9e487803753ce6f6e477793 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 14 Aug 2019 14:35:28 -0300 Subject: [PATCH] scroll import action to import section of settings page --- .../client/analytics/settings/index.js | 13 ++++++++++++- .../src/Notes/WC_Admin_Notes_Historical_Data.php | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/settings/index.js b/plugins/woocommerce-admin/client/analytics/settings/index.js index ca1843a547d..07211acd2d1 100644 --- a/plugins/woocommerce-admin/client/analytics/settings/index.js +++ b/plugins/woocommerce-admin/client/analytics/settings/index.js @@ -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 { + ); diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php index 0bb6c70c9e8..b5b3a58bed6 100644 --- a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Historical_Data.php @@ -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 );