Skip to content
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

Add hiive html attributes to ftc #20678

Merged
merged 38 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0be2bfc
Move steps names here and introduce HIIVE_STEPS_NAMES
pls78 Sep 19, 2023
9b61693
Refactor to pass stepId and build id later in the buttons
pls78 Sep 19, 2023
1b9acd9
Refactor to build buttons ids and hiive attributes
pls78 Sep 19, 2023
42ec4c2
Add hiive data attributes
pls78 Sep 19, 2023
04b6cca
Add filters to trigger event dispatching
pls78 Sep 22, 2023
6f57b11
Refactor method to fetch old values. Add a mapping function to change…
pls78 Sep 25, 2023
8b14974
Add two new events
pls78 Sep 25, 2023
9bb9a87
Changed hook param value
pls78 Sep 25, 2023
7a39acd
Add hooks documentation
pls78 Sep 25, 2023
0041fb2
Fix cs
pls78 Sep 25, 2023
805aec5
Move Hiive-specific code to Newfold data module plugin
pls78 Sep 26, 2023
67da3e9
Fix tests
pls78 Sep 26, 2023
63659a6
Fix cs
pls78 Sep 26, 2023
6c3064f
Fix inwanted import
pls78 Sep 26, 2023
d8c0dd9
Fixed capitalisation
pls78 Oct 6, 2023
cd3ab76
Add some more hiive attributes
pls78 Oct 6, 2023
b3e5795
Remove useless curly brackets
pls78 Oct 6, 2023
b8a9741
Add missing Hiive attribute.
pls78 Oct 6, 2023
19dba25
Update src/actions/configuration/first-time-configuration-action.php
pls78 Oct 9, 2023
447dab2
Update src/actions/configuration/first-time-configuration-action.php
pls78 Oct 9, 2023
7a93fca
Update src/actions/configuration/first-time-configuration-action.php
pls78 Oct 9, 2023
5616de8
Moved constants to FTC root folder
pls78 Oct 9, 2023
e7c7032
Update constants import
pls78 Oct 9, 2023
6247a50
Uniform buttons components props
pls78 Oct 9, 2023
73de897
Update packages/js/src/first-time-configuration/tailwind-components/c…
pls78 Oct 10, 2023
d881210
Update packages/js/src/first-time-configuration/tailwind-components/c…
pls78 Oct 10, 2023
afeadba
Update packages/js/src/first-time-configuration/tailwind-components/c…
pls78 Oct 10, 2023
54811af
Update packages/js/src/first-time-configuration/tailwind-components/c…
pls78 Oct 10, 2023
317a3aa
Update packages/js/src/first-time-configuration/tailwind-components/s…
pls78 Oct 10, 2023
042c33a
Use the right hook name
pls78 Oct 11, 2023
565f3c8
Add @internal annotation to hooks
pls78 Oct 11, 2023
388d887
Do not filter $old_values.
pls78 Oct 11, 2023
dbbaabb
Simplify "Site representation step".
pls78 Oct 11, 2023
7ef5da3
Fix event name
pls78 Oct 11, 2023
457253b
Fix event name in case of replaced image
pls78 Oct 11, 2023
c9ee2d4
Enforce type checking
pls78 Oct 11, 2023
576dd23
Correct order of operations
pls78 Oct 12, 2023
a76b3ea
Fix tests
pls78 Oct 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ import IndexationStep from "./tailwind-components/steps/indexation/indexation-st
import SiteRepresentationStep from "./tailwind-components/steps/site-representation/site-representation-step";
import PersonalPreferencesStep from "./tailwind-components/steps/personal-preferences/personal-preferences-step";
import FinishStep from "./tailwind-components/steps/finish/finish-step";

const STEPS = {
optimizeSeoData: "optimizeSeoData",
siteRepresentation: "siteRepresentation",
socialProfiles: "socialProfiles",
personalPreferences: "personalPreferences",
};
import { STEPS } from "./tailwind-components/steps/constants";
pls78 marked this conversation as resolved.
Show resolved Hide resolved

/* eslint-disable complexity */

Expand Down Expand Up @@ -501,7 +495,7 @@ export default function FirstTimeConfigurationSteps() {
isFinished={ isIndexationStepFinished }
>
<EditButton
id={ `button-${ STEPS.optimizeSeoData }-edit` }
stepId={ STEPS.optimizeSeoData }
beforeGo={ beforeEditing }
isVisible={ showEditButton }
additionalClasses={ "yst-ml-auto" }
Expand All @@ -512,7 +506,7 @@ export default function FirstTimeConfigurationSteps() {
<Step.Content>
<IndexationStep setIndexingState={ setIndexingState } indexingState={ indexingState } showRunIndexationAlert={ showRunIndexationAlert } isStepperFinished={ isStepperFinished } />
<ContinueButton
id={ `button-${ STEPS.optimizeSeoData }-continue` }
stepId={ STEPS.optimizeSeoData }
additionalClasses="yst-mt-12"
beforeGo={ beforeContinueIndexationStep }
destination={ stepperFinishedOnce ? "last" : 1 }
Expand All @@ -527,7 +521,7 @@ export default function FirstTimeConfigurationSteps() {
isFinished={ isStep2Finished }
>
<EditButton
id={ `button-${ STEPS.siteRepresentation }-edit` }
stepId={ STEPS.siteRepresentation }
beforeGo={ beforeEditing }
isVisible={ showEditButton }
additionalClasses={ "yst-ml-auto" }
Expand Down Expand Up @@ -557,7 +551,7 @@ export default function FirstTimeConfigurationSteps() {
isFinished={ isStep3Finished }
>
<EditButton
id={ `button-${ STEPS.socialProfiles }-edit` }
stepId={ STEPS.socialProfiles }
beforeGo={ beforeEditing }
isVisible={ showEditButton }
additionalClasses={ "yst-ml-auto" }
Expand All @@ -582,7 +576,7 @@ export default function FirstTimeConfigurationSteps() {
isFinished={ isStep4Finished }
>
<EditButton
id={ `button-${ STEPS.personalPreferences }-edit` }
stepId={ STEPS.personalPreferences }
beforeGo={ beforeEditing }
isVisible={ showEditButton }
additionalClasses={ "yst-ml-auto" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default function ImageSelect( {
className={ imageClassName }
onClick={ onSelectImageClick }
type="button"
data-hiive-event-name="clicked_select_image"
>
{ renderPreview() }
</button>
Expand All @@ -79,6 +80,7 @@ export default function ImageSelect( {
id={ url ? id + "__replace-image" : id + "__select-image" }
className="yst-button yst-button yst-button--secondary yst-mr-2"
onClick={ onSelectImageClick }
data-hiive-event-name="clicked_select_image"
Copy link
Member

Choose a reason for hiding this comment

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

I suppose by the difference clicked_select_image knows if it is a replace or not 🤔
But it could be a separate event too, as you could argue the same for remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

>
{ url ? __( "Replace image", "admin-ui" ) : __( "Select image", "admin-ui" ) }
</button>
Expand All @@ -88,6 +90,7 @@ export default function ImageSelect( {
id={ id + "__remove-image" }
className="yst-button--remove"
onClick={ onRemoveImageClick }
data-hiive-event-name="clicked_remove_image"
>
{ __( "Remove image", "admin-ui" ) }
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from "prop-types";
import { Step } from "./stepper";
import { stepperTimingClasses } from "../stepper-helper";
import classNames from "classnames";
import { HIIVE_STEPS_NAMES } from "../tailwind-components/steps/constants";
pls78 marked this conversation as resolved.
Show resolved Hide resolved

/**
* A ContinueButton that always goes to the next step.
Expand All @@ -13,18 +14,21 @@ import classNames from "classnames";
*
* @returns {WPElement} The ContinueButton, that always goes to the next step.
*/
export function ContinueButton( { beforeGo, children, additionalClasses, ...restProps } ) {
export function ContinueButton( { stepId, beforeGo, children, additionalClasses, ...restProps } ) {
return ( <Step.GoButton
id={ `button-${ stepId }-continue` }
className={ `yst-button yst-button--primary ${ additionalClasses }` }
destination={ 1 }
beforeGo={ beforeGo }
data-hiive-event-name={ `clicked_continue | ${ HIIVE_STEPS_NAMES[ stepId ] }` }
{ ...restProps }
>
{ children }
</Step.GoButton> );
}

ContinueButton.propTypes = {
stepId: PropTypes.string.isRequired,
additionalClasses: PropTypes.string,
beforeGo: PropTypes.func,
children: PropTypes.node,
Expand All @@ -44,27 +48,30 @@ ContinueButton.defaultProps = {
*
* @returns {WPElement} The EditButton, that always goes to the step it is placed in.
*/
export function EditButton( { beforeGo, isVisible, children, additionalClasses, ...restProps } ) {
export function EditButton( { stepId, beforeGo, isVisible, children, additionalClasses, ...restProps } ) {
const transitionClasses = `yst-transition-opacity ${stepperTimingClasses.slideDuration} yst-ease-out ${ isVisible
? "yst-opacity-100"
: `${stepperTimingClasses.delayBeforeOpening} yst-opacity-0 yst-pointer-events-none yst-hidden` }`;


return ( <Step.GoButton
id={ `button-${ stepId }-edit` }
className={ classNames(
"yst-button yst-button--secondary yst-button--small",
transitionClasses,
additionalClasses
) }
destination={ 0 }
beforeGo={ beforeGo }
data-hiive-event-name={ `clicked_edit | ${ HIIVE_STEPS_NAMES[ stepId ] }` }
{ ...restProps }
>
{ children }
</Step.GoButton> );
}

EditButton.propTypes = {
stepId: PropTypes.string.isRequired,
additionalClasses: PropTypes.string,
isVisible: PropTypes.bool,
beforeGo: PropTypes.func,
Expand Down Expand Up @@ -123,8 +130,22 @@ BackButton.defaultProps = {
*/
export function StepButtons( { stepId, beforeContinue, continueLabel, beforeBack, backLabel } ) {
return <div className="yst-mt-12">
<ContinueButton id={ `button-${ stepId }-continue` } beforeGo={ beforeContinue }>{ continueLabel }</ContinueButton>
<BackButton id={ `button-${ stepId }-back` } additionalClasses="yst-ml-3" beforeGo={ beforeBack }>{ backLabel }</BackButton>
<ContinueButton
id={ `button-${ stepId }-continue` }
beforeGo={ beforeContinue }
data-hiive-event-name={ `clicked_continue | ${ HIIVE_STEPS_NAMES[ stepId ] }` }

pls78 marked this conversation as resolved.
Show resolved Hide resolved
>
{ continueLabel }
</ContinueButton>
<BackButton
id={ `button-${ stepId }-back` }
additionalClasses="yst-ml-3"
beforeGo={ beforeBack }
data-hiive-event-name={ `clicked_back | ${ HIIVE_STEPS_NAMES[ stepId ] }` }
>
{ backLabel }
</BackButton>
pls78 marked this conversation as resolved.
Show resolved Hide resolved
</div>;
}

Expand Down Expand Up @@ -165,7 +186,12 @@ export function ConfigurationStepButtons( { stepId, stepperFinishedOnce, saveFun
} );
pls78 marked this conversation as resolved.
Show resolved Hide resolved

if ( stepperFinishedOnce ) {
return <Step.GoButton id={ `button-${ stepId }-go` } className="yst-button yst-button--primary yst-mt-12" destination="last" beforeGo={ onSaveClick }>
return <Step.GoButton
id={ `button-${ stepId }-go` }
className="yst-button yst-button--primary yst-mt-12"
destination="last"beforeGo={ onSaveClick }
pls78 marked this conversation as resolved.
Show resolved Hide resolved
data-hiive-event-name={ `clicked_save changes | ${ HIIVE_STEPS_NAMES[ stepId ] }` }
pls78 marked this conversation as resolved.
Show resolved Hide resolved
>
{ __( "Save changes", "wordpress-seo" ) }
</Step.GoButton>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const STEPS = {
optimizeSeoData: "optimizeSeoData",
siteRepresentation: "siteRepresentation",
socialProfiles: "socialProfiles",
personalPreferences: "personalPreferences",
};
export const HIIVE_STEPS_NAMES = {
[ STEPS.optimizeSeoData ]: "data optimization",
[ STEPS.siteRepresentation ]: "site representation",
[ STEPS.socialProfiles ]: "social profiles",
[ STEPS.personalPreferences ]: "personal preferences",
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function FinishStep() {
id="button-webinar-seo-dashboard"
href={ webinarIntroFirstTimeConfigUrl }
target="_blank"
data-hiive-event-name="clicked_to_onboarding_page"
>
{ sprintf(
/* translators: 1: Yoast SEO. */
Expand All @@ -51,6 +52,7 @@ export default function FinishStep() {
<Link
id="link-webinar-register"
onClick={ goToSEODashboard }
data-hiive-event-name="clicked_seo_dashboard"
>
{ __( "Or go to your SEO dashboard", "wordpress-seo" ) }
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class Indexation extends Component {
className="yst-button yst-button--secondary"
onClick={ this.startIndexing }
id="indexation-data-optimization"
data-hiive-event-name="clicked_start_data_optimization"
>
{ __( "Start SEO data optimization", "wordpress-seo" ) }
</button>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export function NewsletterSignup( { gdprLink } ) {
className="yst-button yst-button--primary yst-h-[45px] yst-items-center yst-mt-[27.5px] yst-shrink-0"
onClick={ onSignUpClick }
disabled={ signUpState === "loading" }
data-hiive-event-name="clicked_signup | personal preferences"

pls78 marked this conversation as resolved.
Show resolved Hide resolved
>
{ __( "Sign up!", "wordpress-seo" ) }
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SocialFieldArray = ( { items, onAddProfile, onRemoveProfile, onChangeProfi
id="add-profile"
className="yst-button yst-button--secondary yst-items-center yst-mt-8"
onClick={ onAddProfile }
data-hiive-event-name="clicked_add_profile"
>
<PlusIcon className="yst-w-5 yst-h-5 yst-mr-1 yst-text-slate-400" />
{ addButtonChildren }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export default function SocialProfilesStep( { state, dispatch, setErrorFields }
"</a>"

),
{ // eslint-disable-next-line jsx-a11y/anchor-has-content
{ // eslint-disable-next-line jsx-a11y/anchor-has-content
a: <a
id="yoast-configuration-person-social-profiles-user-link"
href={ window.wpseoScriptData.userEditUrl.replace( "{user_id}", state.personId ) }
target="_blank" rel="noopener noreferrer"
data-hiive-event-name="clicked_update_or_add_profile | social profiles"
pls78 marked this conversation as resolved.
Show resolved Hide resolved
/>,
} );

Expand Down
8 changes: 7 additions & 1 deletion packages/js/src/installation-success.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function InstallationSuccessPage() {
id="installation-successful-configuration-link"
href={ window.wpseoInstallationSuccess.firstTimeConfigurationUrl }
className="yst-inline-flex yst-items-center yst-w-full yst-justify-center yst-no-underline yst-px-6 yst-py-3 yst-border yst-border-transparent yst-text-base yst-font-medium yst-rounded-md yst-shadow-none yst-text-primary-500 yst-bg-white hover:yst-bg-gray-50 focus:yst-outline-none focus:yst-ring-2 focus:yst-ring-offset-2 focus:yst-ring-white yst-ring-offset-2 yst-ring-offset-primary-500"
data-hiive-event-name="clicked_start_first_time_configuration"
>
{ __( "Start first-time configuration!", "wordpress-seo" ) }
<svg
Expand All @@ -117,7 +118,12 @@ function InstallationSuccessPage() {
</a>
</div>
</div>
<a id="installation-success-skip-link" className="yst-bottom-12 yst-right-0 yst-mr-5 yst-self-end yst-text-base md:yst-absolute" href={ "/wp-admin/admin.php?page=wpseo_dashboard" }>
<a
id="installation-success-skip-link"
className="yst-bottom-12 yst-right-0 yst-mr-5 yst-self-end yst-text-base md:yst-absolute"
href={ "/wp-admin/admin.php?page=wpseo_dashboard" }
data-hiive-event-name="clicked_skip_button | installation successful screen"
pls78 marked this conversation as resolved.
Show resolved Hide resolved
>
{
/* translators: %s expands to ' »'. */
sprintf( __( "Skip%s", "wordpress-seo" ), " »" )
pls78 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
60 changes: 58 additions & 2 deletions src/actions/configuration/first-time-configuration-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ public function __construct( Options_Helper $options_helper, Social_Profiles_Hel
* @return object The response object.
*/
public function set_site_representation( $params ) {
$failures = [];
$failures = [];
$old_values = $this->get_old_values( self::SITE_REPRESENTATION_FIELDS );

// This field seems to be not used anymore.
$old_values = \array_filter(
$old_values,
static function( $key ) {
return $key !== 'description';
},
\ARRAY_FILTER_USE_KEY
);
Copy link
Member

Choose a reason for hiding this comment

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

Why not remove it from SITE_REPRESENTATION_FIELDS?

It seems to be a remnant from when we had a field for the blogdescription? Below there is the if/else to update that. And following what we send to the route in /packages/js/src/first-time-configuration/first-time-configuration-steps.js' updateSiteRepresentation - it is indeed not there.

So unless I'm missing something, you could remove that instead of filtering?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I know (hence the comment there), this was just my super-cautious nature kicking in and the will to contain scope creep! 😅
Anyway, I removed the filter and the if/else related to the that field now.


foreach ( self::SITE_REPRESENTATION_FIELDS as $field_name ) {
if ( isset( $params[ $field_name ] ) ) {
Expand All @@ -81,6 +91,15 @@ public function set_site_representation( $params ) {
$this->options_helper->set( 'company_logo_meta', false );
$this->options_helper->set( 'person_logo_meta', false );

/**
* Action: 'wpseo_post_update_site_representation' - Allows for Hiive event tracking.
*
* @api array The options new values.
* @api array The options old values.
* @api array The options that failed to be saved.
pls78 marked this conversation as resolved.
Show resolved Hide resolved
*/
\do_action( 'wpseo_post_update_site_representation', $params, $old_values, $failures );
Copy link
Member

Choose a reason for hiding this comment

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

  • You used in the add_action wpseo_ftc_post_update_site_representation elsewhere!
  • Maybe signal this as @internal? Or create documentation PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


if ( \count( $failures ) === 0 ) {
return (object) [
'success' => true,
Expand All @@ -104,7 +123,17 @@ public function set_site_representation( $params ) {
* @return object The response object.
*/
public function set_social_profiles( $params ) {
$failures = $this->social_profiles_helper->set_organization_social_profiles( $params );
$failures = $this->social_profiles_helper->set_organization_social_profiles( $params );
$old_values = $this->get_old_values( \array_keys( $this->social_profiles_helper->get_organization_social_profile_fields() ) );
Copy link
Member

Choose a reason for hiding this comment

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

  • I'm noticing that the get_organization_social_profile_fields uses but does not check if the filtered return value. Maybe add a safety (array) there to ensure this keeps working?
  • Also, I see this is the same as for person (with get_person_social_profile_fields), but you haven't changed that code in your PR (set_person_social_profiles method). Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

The first point has been addressed.
About the second point, set_person_social_profiles is dead code, I'm creating a tech debt issue to address that too. 🙂


/**
* Action: 'wpseo_post_update_social_profiles' - Allows for Hiive event tracking.
*
* @api array The options new values.
* @api array The options old values.
* @api array The options that failed to be saved.
pls78 marked this conversation as resolved.
Show resolved Hide resolved
*/
\do_action( 'wpseo_post_update_social_profiles', $params, $old_values, $failures );
Copy link
Member

Choose a reason for hiding this comment

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

  • You used in the add_action wpseo_ftc_post_update_social_profiles elsewhere!
  • Maybe signal this as @internal? Or create documentation PR?

Copy link
Member Author

@pls78 pls78 Oct 11, 2023

Choose a reason for hiding this comment

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

Done.


if ( empty( $failures ) ) {
return (object) [
Expand Down Expand Up @@ -186,6 +215,16 @@ public function set_enable_tracking( $params ) {
$success = $this->options_helper->set( 'tracking', $params['tracking'] );
}

/**
* Action: 'wpseo_post_update_enable_tracking' - Allows for Hiive event tracking.
*
* @api array The new value.
* @api array The old value.
* @api bool Whether the option failed to be stored.
pls78 marked this conversation as resolved.
Show resolved Hide resolved
*/
// $success is negated to be aligned with the other two actions which pass $failures.
\do_action( 'wpseo_post_update_enable_tracking', $params['tracking'], $option_value, ! $success );
Copy link
Member

Choose a reason for hiding this comment

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

  • You used in the add_action wpseo_ftc_post_update_enable_tracking elsewhere!
  • Maybe signal this as @internal? Or create documentation PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


if ( $success ) {
return (object) [
'success' => true,
Expand Down Expand Up @@ -295,4 +334,21 @@ public function get_configuration_state() {
private function can_edit_profile( $person_id ) {
return \current_user_can( 'edit_user', $person_id );
}

/**
* Gets the old values for the given fields.
*
* @param array $fields_names The fields to get the old values for.
*
* @return array The old values.
*/
private function get_old_values( $fields_names ) : array {
Copy link
Member

Choose a reason for hiding this comment

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

If you're adding the return type hinting, why not also the argument?

(then I noticed the filters and missing type checks 😅 -- still, might want to make those safer instead)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

$old_values = [];

foreach ( $fields_names as $field_name ) {
$old_values[ $field_name ] = $this->options_helper->get( $field_name );
}

return $old_values;
}
}
Loading