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

Allow block_order on preset #849

Merged
merged 6 commits into from
Nov 29, 2024
Merged

Allow block_order on preset #849

merged 6 commits into from
Nov 29, 2024

Conversation

miazbikowski
Copy link
Contributor

@miazbikowski miazbikowski commented Nov 22, 2024

When preset blocks are a hash, they require block_order since the order is lost (as opposed to the blocks array).

We noticed while working in theme-tools that we were getting a red highlight saying block_order property not allowed (or something to that effect). This is to fix that.

property-not-allowed

🎩

I was able to get the autocomplete for both the root and nested level blocks:
image

image

You can also tophat by opening this repo on this branch and playing with the fixtures, it should pop up the autocomplete.


Additional case: nested blocks must be the same type as their parents - blocks arrays can only contain blocks that are also arrays, block hashes can only contain blocks that have block hashes

🎩
image

@miazbikowski miazbikowski force-pushed the miaz/allow-block-order branch from a59c9e7 to 42ed549 Compare November 25, 2024 19:39
@miazbikowski miazbikowski force-pushed the miaz/allow-block-order branch from 42ed549 to 1fedd6d Compare November 25, 2024 20:28
},
{
"$ref": "#/definitions/presetWithBlocksHash"
}
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 encountered an issue where presets with only name and settings could be validated by either of these refs, so by adding blocks as required to the presetWithBlocksHash it ensured there was no such conflict. A preset with only name (and usually settings, otherwise the whole preset's kinda useless) will get validated by the presetWithBlocksArray.

Optionally, we could make blocks required in presetWithBlocksArray too and require a third option for presets with just name and settings. A trivial change, if it's preferred. I'm on the fence, myself.

Copy link
Contributor

@charlespwd charlespwd Nov 26, 2024

Choose a reason for hiding this comment

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

maybe...

"allOf": [
  { "$ref": "#/definitions/presetBase" }
  { "oneOf": [
    { "$ref": "#/definitions/presetBlocksArray" },
    { "$ref": "#/definitions/presetBlocksHash" },
  ]}
]

?

Copy link
Contributor Author

@miazbikowski miazbikowski Nov 26, 2024

Choose a reason for hiding this comment

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

So I remember when we chatted in person, we agreed it wasn't worth complicating things just to extract out name and settings - though I'd be down to do it if it solved the presets with "only" name and settings more elegantly... Although the one you posted still requires that the data fit into either presetBlocksArray and presetBlocksHash?

Wouldn't it be more like this to accommodate all 3 possible cases?

  { "oneOf": [
    { "$ref": "#/definitions/presetBase" }
    { "$ref": "#/definitions/presetBlocksArray" },
    { "$ref": "#/definitions/presetBlocksHash" },
  ]}

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean that works too so long as presetBase doesn't accept other properties and that the array/hash have blocks & blocks order required. Same same

Copy link
Contributor Author

@miazbikowski miazbikowski Nov 26, 2024

Choose a reason for hiding this comment

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

Cool. The change you proposed ended up being easier to implement - my version was giving me a hard time for a reason I can't figure out, so, if it's same same, then yours works :)

Did some tophatting locally:
image

(overall the presets autocomplete worked with blocks as arrays and blocks as hash)

@miazbikowski miazbikowski marked this pull request as ready for review November 25, 2024 20:33
@miazbikowski miazbikowski requested a review from a team as a code owner November 25, 2024 20:33
@miazbikowski miazbikowski force-pushed the miaz/allow-block-order branch from 2e05ecd to 9441dfa Compare November 26, 2024 17:08
@miazbikowski miazbikowski force-pushed the miaz/allow-block-order branch from 9441dfa to 8f7b484 Compare November 27, 2024 13:57
@charlespwd
Copy link
Contributor

Something is off:
When I have an array element with a hash child, the block_order doesn't complete 🤔
image

Comment on lines +56 to +58
"blocks": {
"$ref": "#/definitions/blocksHash"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

ezpz!

Copy link
Contributor

@charlespwd charlespwd left a comment

Choose a reason for hiding this comment

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

tophat looks good to me! We'll need to adjust the types in Shopify/theme-tools to match but we're good to go!

Copy link
Contributor

@albchu albchu left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you Mia!

Copy link

@navdeep5 navdeep5 left a comment

Choose a reason for hiding this comment

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

🎩 ed and things look good!

@miazbikowski miazbikowski merged commit f56e122 into main Nov 29, 2024
5 checks passed
@miazbikowski miazbikowski deleted the miaz/allow-block-order branch November 29, 2024 15:03
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.

4 participants