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 block rename handler (replace old->new everywhere!) #655

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

charlespwd
Copy link
Contributor

@charlespwd charlespwd commented Dec 5, 2024

What are you adding in this PR?

When a theme block gets renamed, old references will be workspace edited to the new name in all the following locations:

  • section schemas
  • block schemas
  • content_for "block", type: "old-name"
  • templates/*.json files
  • sections/*.json files
on-block-rename.mp4

Before you deploy

  • I included a minor bump changeset

@charlespwd charlespwd linked an issue Dec 5, 2024 that may be closed by this pull request
@charlespwd charlespwd force-pushed the feature/block-rename-handling branch from 9b21030 to 15cf74e Compare December 6, 2024 16:37
@albchu albchu self-requested a review December 9, 2024 21:13
@albchu
Copy link
Contributor

albchu commented Dec 9, 2024

Going to try and get the jsonc PR #656 merged as soon as we can here before assessing what kind of assistance we can apply to this PR before CP returns from holiday break.

@charlespwd charlespwd force-pushed the feature/block-rename-handling branch 2 times, most recently from ae65e1f to f40aba4 Compare January 6, 2025 19:48
@charlespwd
Copy link
Contributor Author

charlespwd commented Jan 6, 2025

I'm picking this back up with Navdeep's first stab at the tests. Couldn't figure out what his email is for the correct co-author to appear on the commit.

Co-authored-by: Navdeep Singh <[email protected]>

Whenever a block gets renamed, the following will now happen:
  1. References in files with a {% schema %} will be changed
  2. References in template files will be changed
  3. References in section groups will be changed
  4. References in {% content_for "block", type: "oldName" %} will be changed
@charlespwd charlespwd force-pushed the feature/block-rename-handling branch from f40aba4 to 51fe22e Compare January 7, 2025 13:41
@charlespwd charlespwd marked this pull request as ready for review January 7, 2025 13:46
@charlespwd charlespwd requested a review from a team as a code owner January 7, 2025 13:46
@charlespwd charlespwd force-pushed the feature/block-rename-handling branch from 634e83f to c99d769 Compare January 8, 2025 13:16
Copy link
Contributor

@aswamy aswamy left a comment

Choose a reason for hiding this comment

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

1 weird hiccup during tophat 🎩

  • When i renamed blocks/text to blocks/poetry, i noticed blocks/accordion's schema still had it as "text"
    • I assumed it was because it had some syntax errors. I fixed those errors, and i ran "rename" again
    • When i did the rename, it only changed accordion's reference, but not the other files

Without changing accordion (everything works as expected)

Screen.Recording.2025-01-08.at.10.03.44.AM.mov

After changing accordion (only it's reference is updated)

Screen.Recording.2025-01-08.at.10.04.47.AM.mov

@charlespwd
Copy link
Contributor Author

I opened #692 in response to the behaviour above. Workspace operations that don't go through textEdit/did{open,change,close} don't update the document manager (e.g. a git revert or a git checkout).

As for syntax errors, that's a tough one. I think the example we have above is tricky because we're working of a theme that is doing internal explorations of features. It's technically not valid in the wild... But the space between "might be vaild" and "not valid" is pretty large. I'm not sure it's worth looking into?

Copy link
Contributor

@aswamy aswamy left a comment

Choose a reason for hiding this comment

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

Minor comments, but looks good

* 4. References in {% content_for "block", type: "oldName" %} must be changed
*
* Things we're not doing:
* 5. If isPublic(oldName) && isPrivate(newName) && "schema.blocks" accepts "@theme",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really good catch - didn't think we'd be doing it but good to explicitly have this written out

}

private getSchemaChanges(
sectionsWithLocalBlocks: Set<unknown>,
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of passing in this set as an arg and modifying it in this function, could we just create the set and return from within the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function already returns a function though, not sure how I feel about returning a bunch of things (à la useState)

Which would make this invocation kind of awkward require two calls anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moreover, the object would only be full after the promise resolves... Doesn't that make it more complicated?

    // We need to keep track of sections that have local blocks, because we
    // shouldn't rename those. Only uses of "@theme" or specifically named blocks
    // should be renamed when the blocks/*.liquid file is renamed.
    const [sectionsWithLocalBlocks, getSchemaChanges] = this.getSchemaChanges(oldBlockName, newBlockName);

    // sectionWithLocalBlocks is empty right now
    const sectionAndBlocksChanges: (DocumentChange | null)[] = await Promise.all(sectionsAndBlocks.map(getSchemaChanges));
    // sectionWithLocalBlocks is full
    ```

Copy link
Contributor

Choose a reason for hiding this comment

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

This function already returns a function though, not sure how I feel about returning a bunch of things (à la useState)

👍

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.

Renaming a block should update old references
4 participants