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

Site Migration: Enable to manage when the site migration key will be loaded #90086

Merged
merged 4 commits into from
Apr 30, 2024

Conversation

gabrielcaires
Copy link
Contributor

@gabrielcaires gabrielcaires commented Apr 30, 2024

Part of #89760

Proposed Changes

It is part of #89760 where we need to control a sequence of requests to ensure a site is ready to run the migrate-guru migration.

I am going to use this feature in further PRs.

  • Introduce the enable prop on the use-site-migration-key hook to manage when we want to start fetching the key.
  • Fix the typo on the file name

Testing Instructions

@gabrielcaires gabrielcaires changed the title Site Migration: Manage site migration key hook Site Migration: Enable to manage when the site migration key will be loaded Apr 30, 2024
@gabrielcaires gabrielcaires marked this pull request as ready for review April 30, 2024 08:29
@gabrielcaires gabrielcaires requested a review from a team April 30, 2024 08:30
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 30, 2024
@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@gabrielcaires gabrielcaires added the [Feature] Site Migration Features related to site migrations to WPcom label Apr 30, 2024
export const useSiteMigrationKey = ( siteId?: number ) => {
type Options = Pick< UseQueryOptions, 'enabled' >;

export const useSiteMigrationKey = ( siteId?: number, options?: Options ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's confusing for the Options type to be UseQueryOptions. Looking at this hook from another programmer POV, I would expect to configure the whole query via this options parameter given it's type (like queryKey, queryFn, etc), but I can only affect retry and enabled in some special circumstances.

Since it looks like it will only be used to control retry & enabled I think a custom type for only those two things would be more clear.

Copy link
Contributor Author

@gabrielcaires gabrielcaires Apr 30, 2024

Choose a reason for hiding this comment

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

@andres-blanco

I am not sure if I understood.

In this case, I'm just reusing the enabled type definition instead of being an "UseQueryOption type".

Are you suggesting something like:

interface Options {
 enabled: boolean?
}

Or are you suggesting open to receiving all useQueryOption attributes?

Using the Pick we can't pass all other attributes.
The idea is not to enable configuring the other parts because it is not generic and it can break the usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I didn't explain myself correctly. Basically I don't see the value of picking from the UseQueryOption type since it is not going to affect the query directly, making the semantics slightly different.

Say you have the following code:
useSiteMigrationKey( null, { enabled: true } )

I would expect for the actual API call to be made, because I enabled it and it's a UseQueryOption pick, so it would be reasonable to override default behaviour. But it is not made because siteId is null.
If we had a custom type for this hook, say something like:

interface Options {
   stalling: boolean?
}

This purpose of this call useSiteMigrationKey( null, { stalling: true } ) would be clearer to me, because I wouldn't have an expectation about the inner implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I gotcha, you won't to create false expectations by saying this enabled will not work exactly in a similar way to the original one.

I have mixed feelings, so I would like to think more.

Do you mind if I create a separate issue just to give me more time to think about it and not block it?

Copy link
Contributor

@andres-blanco andres-blanco Apr 30, 2024

Choose a reason for hiding this comment

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

I gotcha, you won't to create false expectations by saying this enabled will not work exactly in a similar way to the original one.

In my mind, the expectation is created by the enabled being picked from UseQueryOption not from it being called enabled.

Do you mind if I create a separate issue just to give me more time to think about it and not block it?

yup, go ahead! I'll approve all of this

@gabrielcaires gabrielcaires merged commit 398b039 into trunk Apr 30, 2024
13 checks passed
@gabrielcaires gabrielcaires deleted the update/manage-site-migration-key-hook branch April 30, 2024 15:04
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Migration Features related to site migrations to WPcom
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants