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

Expose inputs for loop blocks #418

Open
wants to merge 17 commits into
base: trunk
Choose a base branch
from
Open

Expose inputs for loop blocks #418

wants to merge 17 commits into from

Conversation

brookewp
Copy link
Contributor

@brookewp brookewp commented Mar 13, 2025

This might be replaced by the work in #405, but it's a small step towards the goals there.

This adds a special type ui:input and loop type selector when loop: true so we can use that to show inputs when relevant.

Returning all results filtered by an input (e.g., categories/collections) is a common use case, so examples of this have been added for Shopify and Salesforce. I also added an example in the Art Institute to set the number of results returned. A visual example of all three of these can be seen here:

Screen.Recording.2025-03-12.at.6.16.52.PM.mov

Updated to include input in the query panel to update any selection:

Screen.Recording.2025-03-19.at.11.09.41.AM.mov

Note

I ran into a few things that we will want to consider when setting up queries, relating to the UI. One thing is a way to add text to the placeholder, as the generic text won't work in all cases and might not be the same as a block description. So for now, in this PR, I've added instructions, but this could change with #405. Also open to alternative suggestions here!

Testing steps

  • Try new block(s) and add input

    • Salesforce: Products By Category with category ID
    • Shopify: Products by Collection with collection ID
    • Art Institute of Chicago Loop
  • Select the parent block and edit the ID in the block inspector panel

    • Edit multiple IDs (Shopify will have single inputs per ID, and Airtable/Art Insitute will have a separate list).

@brookewp brookewp marked this pull request as ready for review March 19, 2025 19:25
@brookewp brookewp requested a review from alecgeatches March 19, 2025 19:25
Copy link

Test this PR in WordPress Playground.

@alecgeatches
Copy link
Contributor

@brookewp This looks great! I'm excited for both the filter options and the easy retargeting a block to a new ID. Testing now.

@alecgeatches
Copy link
Contributor

alecgeatches commented Mar 20, 2025

@brookewp Noticed an odd bug that happens after you pick an item from the Art Institute block, and then pick another one on the same page:

Screen.Recording.2025-03-20.at.12.38.19.PM.mov

Reproduction steps

  1. At the bottom of the root plugin file remote-data-blocks.php , add this line to enable the Art Institute example:

    require_once __DIR__ . '/example/rest-api/art-institute/art-institute.php';
    
  2. Create a new post, insert the "Art Institute of Chicago" block.

  3. Click the "Choose" button and select an art piece.

  4. Click "Choose a pattern" and select the default pattern.

  5. Delete the block, and re-insert an "Art Institute of Chicago" block.

  6. Select an art piece.

  7. Click "Choose a pattern", but see that the page is blank this time.

Notes

  • I can't seem to reproduce this in trunk (but I'm not 100% sure this is your problem)
  • I can't reproduce this in the current branch (try/loop-with-input) with a Salesforce block, so it seems specific to the art institute block for now.
  • There aren't any console logs to help

register_remote_data_block( [
'title' => 'Art Institute of Chicago Loop',
'icon' => 'art',
'instructions' => 'This block displays a set amount of artworks based on the provided limit.',
Copy link
Contributor

@alecgeatches alecgeatches Mar 20, 2025

Choose a reason for hiding this comment

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

I like this! Here's what just this looks like for anyone interested:

image

Copy link
Contributor

@alecgeatches alecgeatches left a comment

Choose a reason for hiding this comment

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

With the exception of that one pattern issue (that I'm not 100% sure is related to this feature), this works great! Feel free to merge if you fix the pattern issue or determine it to be unrelated.

@brookewp
Copy link
Contributor Author

Thanks @alecgeatches! I can replicate the issue you found in trunk after rebuilding my env. I'll open an issue/PR for that separately.

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.

2 participants