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

Clean up messaging around unlinked storefronts when running CLI commands #1937

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

aswamy
Copy link
Contributor

@aswamy aswamy commented Apr 2, 2024

WHY are these changes introduced?

  • Cleaning up Hydrogen CLI link command and messaging around linked storefront

WHAT is this pull request doing?

Changes:

  • We will show a warning (not error) when you run a Hydrogen CLI command on a storefront that isn't linked to a storefront on Admin.
  • If you don't have a storefront to link to on Admin, we will just ask you to create a storefront instead of displaying an option list of size 1.
  • If you deleted a storefront on Admin, we will try to relink your storefront when running a Hydrogen CLI command.

HOW to test your changes?

  • Checkout this repo and build it
    • npm ci
    • cd packages/cli && npm run build
    • If it doesn't build, you might also need to run npm run build inside the other packages
  • Create a storefront using h2 init and link it
    • You can run this command by navigating to the packages/cli directory of the project

Testing deleted storefront && unlinked storefront banner

  • Go to the directory of your newly created storefront
    • Edit the .shopify/project.json file so storefront: {}
  • In hydrogen/packages/cli, run h2 deploy --path=<path-to-project>
    • It should prompt you to link a storefront using the warning severity
    • also try h2 env list, h2 env pull, h2 env push__unstable commands to see the banner

Testing no storefronts on Admin

  • Ensure you have Hydrogen App installed on your shop, but no storefronts
  • In hydrogen/packages/cli, run h2 init
    • Try to link a storefront
    • Instead of prompting you to select a storefront, it will assume you want to create the storefront and ask you its name

image

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor

shopify bot commented Apr 2, 2024

Oxygen deployed a preview of your cli-consistency-2 branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
subscriptions ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2024 5:22 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2024 5:22 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2024 5:22 PM
optimistic-cart-ui ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2024 5:22 PM
skeleton ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2024 5:22 PM
vite ✅ Successful (Logs) Preview deployment Inspect deployment April 17, 2024 5:22 PM

Learn more about Hydrogen's GitHub integration.

packages/cli/src/lib/get-oxygen-deployment-data.ts Outdated Show resolved Hide resolved
packages/cli/src/lib/get-oxygen-deployment-data.ts Outdated Show resolved Hide resolved

Clean up messaging around unlinked storefronts when running CLI commands

- We will show a warning (not error) when you run a Hydrogen CLI command on a storefront that isn't linked to a storefront on Admin.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's clarify here that it's only for Admin related links somehow? I.e. this doesn't affect dev/build commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, i'm going to update the code so it's for env push, env pull, env list, deploy. Do we not already show an error when we run h2 dev on unlinked storefronts?

@aswamy aswamy marked this pull request as draft April 3, 2024 16:40
@aswamy aswamy self-assigned this Apr 3, 2024
@aswamy aswamy marked this pull request as ready for review April 3, 2024 20:40
@aswamy
Copy link
Contributor Author

aswamy commented Apr 3, 2024

Force push

  • If you run h2 env push__unstable, h2 env pull, h2 env list, or h2 deploy, we will verify
    • you have linked your storefront on Admin
    • if the existing storefront you've connected still exists on Admin (or has been deleted)
  • moved verify-linked-storefront into a separate file for consistency and so we can easily test it
    • other Hydrogen CLI commands will call this method to ensure we have linked a storefront
  • As Fran recommended, linkStorefront now takes an optional list of storefronts so we don't have to fetch it 2x

@aswamy aswamy force-pushed the cli-consistency-2 branch 2 times, most recently from 6171756 to 30acde7 Compare April 4, 2024 21:01
@aswamy
Copy link
Contributor Author

aswamy commented Apr 4, 2024

Force push

  • Removing user-confirmation on h2 deploy when user selects a preview environment, user passes in preview env handle, or user provides --preview flag

Copy link
Contributor

@graygilmore graygilmore left a comment

Choose a reason for hiding this comment

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

🎩 went well, just a couple of questions


if (!configStorefront) return;
config.storefront = linkedStorefront;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by the use of config.storefront = X in this PR. Should we be using setStorefront from shopify-config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So setStorefront sets your shopify project.json file to have the linked storefront's data.

verifyLinkedStorefront just checks the following:

  • checks to make sure you have any storefront linked in your project.json file
  • talks to Admin and ensures that storefront still exists
    • this prevents the yucky GraphQL error you would get if you deleted your storefront on Admin

@@ -284,6 +284,10 @@ export async function handleStorefrontSelection(
})),
];

if (choices.length === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this clear enough that we're launching them into the creation flow? I wonder if we should be printing some text like "No storefronts found on . Create a new one to continue"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah i think an extra message here saying that we're creating the storefront is fine.

Before:
image

After:
image

@mynameisadamf any issues with that? I know your original design merged those two banners. However, the first banner message must appear before you choose to run h2 link, where the latter message appear after.

Choose a reason for hiding this comment

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

@aswamy We decided on the implicit approach, which if they were to run h2 deploy we would put them in the link flow w/o prompting. Would be this:

user input: h2 deploy

Info banner:
You haven’t linked your project to a storefront yet.

Prompt: If existing storefronts

Select a Hydrogen storefront to link:

  • Create a new storefront
  • [storefront]
  • [storefront]

Prompt: If no existing storefronts
Create a Hydrogen storefront
[input]

relates to env pull https://github.com/Shopify/custom-storefronts/issues/352#issuecomment-2009983378

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided on the implicit approach, which if they were to run h2 deploy we would put them in the link flow w/o prompting.

Should this follow this for all other admin commands like env push, env list, env pull?

Choose a reason for hiding this comment

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

Yes. This pattern will apply anywhere being linked to a store is required.

@aswamy aswamy force-pushed the cli-consistency-2 branch 2 times, most recently from 2d3d8cb to 4bd1e91 Compare April 5, 2024 20:57
@aswamy
Copy link
Contributor Author

aswamy commented Apr 5, 2024

Force push

  • Updated the "not linked" banner when running env push, env pull, env list, or deploy command without linking a storefront on Admin
  • Remove the user-prompt to link a storefront if it isn't linked

@aswamy
Copy link
Contributor Author

aswamy commented Apr 10, 2024

Force Push

  • Rebased with main

Copy link

@martinamarien martinamarien left a comment

Choose a reason for hiding this comment

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

🎩 went well and matched expected output.
I just have two questions around the use of !

Comment on lines +481 to +484
let chosenEnvironment = findEnvironmentByBranchOrThrow(
deploymentData!.environments!,
config.environmentTag!,
);

Choose a reason for hiding this comment

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

In this case, do we know definitively that these arguments will not be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, had to scroll up but confirmed deploymentData HAS to be defined or an early return would occur.
config.environmentTag has to be defined if one of the items userProvidedEnvironmentTag or userChosenEnvironmentTag is defined.

const storefronts = await getStorefronts(session);

let configuredStorefront = config.storefront?.id
? storefronts.find(({id}) => id === config.storefront!.id)

Choose a reason for hiding this comment

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

Same here, can we guarantee that the config.storefront exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, you can only get into this conditional statement if config.storefront AND config.storefront.id is truthy.

Choose a reason for hiding this comment

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

Thanks Alok. Frustrating that typescript can't infer that the config.storefront.id is defined inside of the find method.

@aswamy aswamy merged commit b4dfda3 into main Apr 18, 2024
15 checks passed
@aswamy aswamy deleted the cli-consistency-2 branch April 18, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants