Skip to content

Curate queries within a block #530

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

Open
wants to merge 88 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
48e710d
Attempting to port code from PR405 into here
ingeniumed May 7, 2025
7b90e48
Add support for multiple display queries
ingeniumed May 8, 2025
5854bb4
Clean up the code and add in validation framework
ingeniumed May 8, 2025
3d2828d
Merge branch 'trunk' of github.com:Automattic/remote-data-blocks into…
ingeniumed May 9, 2025
716415b
Stop crashes for the old query way, and remove the deprecated buttong…
ingeniumed May 9, 2025
790215f
Abstract away the query selection to another level and show query nam…
ingeniumed May 9, 2025
f5bb77f
Merge branch 'trunk' of github.com:Automattic/remote-data-blocks into…
ingeniumed May 12, 2025
9385d73
Simplify the query configuration
ingeniumed May 12, 2025
22349fe
Simplify the query_configuration schema
ingeniumed May 12, 2025
f8363d7
Pop in more configuration at the query level
ingeniumed May 12, 2025
bc7208b
Attempting to use the type instead of the query key for display queries
ingeniumed May 13, 2025
14ce52a
Bug: look at the console log and you'll see the wrong query is always…
ingeniumed May 13, 2025
b130ff2
Comment away everything that initializes remote data with teh wrong q…
ingeniumed May 14, 2025
74699d7
Attempting to move just the remote data lgic to another component, le…
ingeniumed May 14, 2025
d67ccb2
Load the queryKey and queryInputs from state if they are available
ingeniumed May 14, 2025
de3a742
Attempting to redo the whole queries system
ingeniumed May 15, 2025
dda2bdd
Group selectors by query
ingeniumed May 15, 2025
d5e40e4
Got the UI working finally, with the exception of pattern selection b…
ingeniumed May 15, 2025
330c959
Fix the pattern selection bug
ingeniumed May 15, 2025
49ece05
Fix the bug related to the query group and query key not being picked…
ingeniumed May 16, 2025
5cbf9d9
Fix the query input schema for a non-display query being wrong
ingeniumed May 16, 2025
4228e43
Fix more bugs
ingeniumed May 16, 2025
df8e1b6
Another bug fix and some debuggers
ingeniumed May 16, 2025
d13b991
Port the missing caching fix
ingeniumed May 16, 2025
9958984
Fix the merge conflicts from trunk. Still need to port the new Edit c…
ingeniumed May 18, 2025
c1b79c8
Adding ToDos for pending work for this PR
ingeniumed May 18, 2025
0d16b94
Fix the reset block function and remove the unnecessary code
ingeniumed May 19, 2025
eac246f
Fix shortcode selection
ingeniumed May 19, 2025
88681d9
Remove the remaining ToDos
ingeniumed May 19, 2025
4369c29
Implement the skeleton migrate config method, and add in validation m…
ingeniumed May 19, 2025
50086ac
Add a migration pathway for the older format. The query input panel i…
ingeniumed May 20, 2025
fd831c2
Remove last remaining todo/fixmes
ingeniumed May 20, 2025
0e86399
Reverting unnecessary changes, and re-adding the max width for the co…
ingeniumed May 20, 2025
9e823fe
Remove the deprecated notices
ingeniumed May 20, 2025
54e69ae
Functions are called with the brackets, otherwise they aren't called …
ingeniumed May 20, 2025
8460688
Solve the test failures
ingeniumed May 20, 2025
3ec1eec
Fix all the integration tests
ingeniumed May 20, 2025
ba6ef35
Merge branch 'trunk' of github.com:Automattic/remote-data-blocks into…
ingeniumed May 20, 2025
5ce7cf8
Re-write the config processing to be in one go, and be well documented
ingeniumed May 21, 2025
d3b1219
Add a check to make sure a display query is defined
ingeniumed May 21, 2025
a3d7fea
Fix existing data breaking, and change the name of the conference eve…
ingeniumed May 22, 2025
4eee95e
Add in a fallback query key, and update the tests to remove workaroun…
ingeniumed May 22, 2025
3351e6e
Attempting to make the Art Institute block backwards compatible
ingeniumed May 22, 2025
4f4e40a
More comments and bug fixes
ingeniumed May 22, 2025
3b354f1
Got block bindings working with multiple output schemas. Inline bindi…
ingeniumed May 23, 2025
5bdd833
Get inline binding working for multiple display queries
ingeniumed May 27, 2025
726959b
Fix the linting
ingeniumed May 27, 2025
1c608f4
Fix the block binding tests based on the new format
ingeniumed May 27, 2025
50ed548
I did indeed forget to run prettier
ingeniumed May 27, 2025
952ad64
Change the schema to use display_queries, and infer types as much as …
ingeniumed May 29, 2025
6a6121b
Finish migration, fix bug in user supplied patterns not showing up an…
ingeniumed May 29, 2025
bd65475
Add guards from the tests
ingeniumed May 29, 2025
cfb5bf0
update from trunk and fix the merge conflicts
ingeniumed May 30, 2025
7e8bcf1
Fix all errors
ingeniumed May 30, 2025
364e638
Tweak the function name
ingeniumed May 30, 2025
cf8a99d
Minor code review points
ingeniumed May 30, 2025
ab4cd35
Remove more unecessary lines
ingeniumed May 30, 2025
4f01da2
Add Extra tests
ingeniumed May 30, 2025
43715f4
Fix the merge conflict with the config schema
ingeniumed Jun 3, 2025
7e1205d
Fix merge conflicts
ingeniumed Jun 3, 2025
830a0d3
Merge branch 'trunk' into add/multiple-queries-to-single-block
chriszarate Jun 4, 2025
82b3054
Add RemoteDataBlock serializable config
chriszarate Jun 4, 2025
3ec4f57
Merge branch 'trunk' of github.com:Automattic/remote-data-blocks into…
ingeniumed Jun 4, 2025
ff81040
Remove unused code
ingeniumed Jun 4, 2025
84196d8
Switch from using display queries to placeholder
ingeniumed Jun 6, 2025
19ff3b4
Get the case working when no placeholders are provided
ingeniumed Jun 6, 2025
f852297
Add support for a query being a display, and
ingeniumed Jun 10, 2025
2eb260b
Drop selectorQueryKey and attempt to fix errors in happy path
ingeniumed Jun 10, 2025
805f4ad
Backport a bug fix from trunk into my branch
ingeniumed Jun 10, 2025
426671b
Re-enable inline-bindings with hardcoded display query
ingeniumed Jun 10, 2025
4b54f34
Add a display query selector for new inline bindings
ingeniumed Jun 10, 2025
5995b71
Got inline bindings to fully function. Assumed the first display quer…
ingeniumed Jun 10, 2025
97bfd42
Added in the name property, and cleaned up the frontend code as a result
ingeniumed Jun 11, 2025
f6904c6
tweak the inline bindings to re-use the existing method
ingeniumed Jun 11, 2025
a75a78b
Add a quick comment
ingeniumed Jun 11, 2025
2bc60cc
Fix merge conflicts
ingeniumed Jun 11, 2025
4518af7
Fixing some linting errors. There's still a bug with Google Sheets
ingeniumed Jun 11, 2025
0aa9510
Add an extra filter to fix the memory caching bug
ingeniumed Jun 11, 2025
ef0d3e9
Fix the psalm erro
ingeniumed Jun 11, 2025
d62c56a
Fix psalm again
ingeniumed Jun 11, 2025
5ea6dbd
Merge branch 'add/bug-fix-for-google-sheets' of github.com:Automattic…
ingeniumed Jun 11, 2025
e823cc8
Fix all the tests
ingeniumed Jun 11, 2025
af45470
Fix js test
ingeniumed Jun 11, 2025
f6dcba5
Migrate the config of the example blocks, and fix the lack of error b…
ingeniumed Jun 11, 2025
110c547
Merge branch 'trunk' into add/multiple-queries-to-single-block
ingeniumed Jun 11, 2025
852581c
Merge branch 'trunk' of github.com:Automattic/remote-data-blocks into…
ingeniumed Jun 12, 2025
d8eef25
Revert new config changes to the example blocks
ingeniumed Jun 12, 2025
0394f70
Merge branch 'trunk' into add/multiple-queries-to-single-block
ingeniumed Jul 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions inc/Config/Block/RemoteDataBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php declare(strict_types = 1);

namespace RemoteDataBlocks\Config\Block;

use RemoteDataBlocks\Config\ArraySerializable;
use RemoteDataBlocks\Editor\BlockManagement\ConfigRegistry;
use RemoteDataBlocks\Validation\ConfigSchemas;
use WP_Error;

/**
* RemoteDataBlock class
*
* Represents the block configuration for a remote data block.
*/
class RemoteDataBlock extends ArraySerializable {
protected const DEPRECATED_RENDER_QUERY_KEY = 'render_query';
protected const DEPRECATED_SELECTION_QUERIES_KEY = 'selection_queries';

/**
* @inheritDoc
*/
public static function get_config_schema(): array {
return ConfigSchemas::get_remote_data_block_config_schema();
}

/**
* @inheritDoc
*/
public static function migrate_config( array $config = [] ): array|WP_Error {
// Nothing to migrate, return the block config as is.
if ( isset( $config[ ConfigRegistry::QUERIES_KEY ] ) ) {
return $config;
}

$queries = [];
$placeholders = [];

if ( isset( $config[ self::DEPRECATED_RENDER_QUERY_KEY ]['query'] ) ) {
$queries[ ConfigRegistry::DEPRECATED_DISPLAY_QUERY_KEY ] = $config[ self::DEPRECATED_RENDER_QUERY_KEY ]['query'];
$placeholders[] = [
'name' => 'Display',
'query_key' => ConfigRegistry::DEPRECATED_DISPLAY_QUERY_KEY,
];
unset( $config[ self::DEPRECATED_RENDER_QUERY_KEY ] );
}

if ( isset( $config[ self::DEPRECATED_SELECTION_QUERIES_KEY ] ) ) {
// Get the selection queries, inflate them, and add them to the queries array using the type as the key.
foreach ( $config[ self::DEPRECATED_SELECTION_QUERIES_KEY ] as $selection_query ) {
$queries[ $selection_query['type'] ] = $selection_query['query'];
}

unset( $config[ self::DEPRECATED_SELECTION_QUERIES_KEY ] );
}

// Set queries.
$config[ ConfigRegistry::QUERIES_KEY ] = $queries;
$config[ ConfigRegistry::PLACEHOLDERS_KEY ] = $placeholders;

return $config;
}
}
41 changes: 27 additions & 14 deletions inc/Editor/BlockManagement/BlockRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use RemoteDataBlocks\Telemetry\Telemetry;
use RemoteDataBlocks\Editor\BlockPatterns\BlockPatterns;
use RemoteDataBlocks\REST\RemoteDataController;

use function register_block_type;

class BlockRegistration {
Expand Down Expand Up @@ -83,24 +84,40 @@ public static function register_block_configuration( array $config ): array {
$block_path = REMOTE_DATA_BLOCKS__PLUGIN_DIRECTORY . '/build/blocks/remote-data-container';

// Set available bindings from the display query output mappings.
$available_bindings = [];
$output_schema = $config['queries'][ ConfigRegistry::DISPLAY_QUERY_KEY ]->get_output_schema();
foreach ( $output_schema['type'] ?? [] as $key => $mapping ) {
$available_bindings[ $key ] = [
'name' => $mapping['name'],
'type' => $mapping['type'],
];
$available_bindings_for_queries = [];
$display_queries_to_selectors = $config['display_queries_to_selectors'] ?? [];

$patterns = $config['patterns'] ?? [];

// Using array_keys here triggers a psalm error, so it's set to $_ instead.
// Supressing the psalm error is a not a good idea, so instead this is the better solution.
// ToDo: Fix the psalm error, and see if array_keys could be used here again.
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 haven't been able to solve a psalm error that complains about the types being invalidated and the key being unused, when array_keys was used for the loop. So I gave up, and instead just changed the name of the unused selectors to be such that psalm ignores it. If anyone knows this error, feel free to suggest a fix.

foreach ( $display_queries_to_selectors as $display_query_key => $_ ) {
$display_query = $config['queries'][ $display_query_key ];
$available_bindings_for_query = [];
$output_schema = $display_query->get_output_schema();
foreach ( $output_schema['type'] ?? [] as $key => $mapping ) {
$available_bindings_for_query[ $key ] = [
'name' => $mapping['name'],
'type' => $mapping['type'],
];
}

$available_bindings_for_queries[ $display_query_key ] = $available_bindings_for_query;

$default_pattern_name = BlockPatterns::register_default_block_pattern( $block_name, $config['title'], $display_query_key, $display_query );
$patterns[ $display_query_key ] = $default_pattern_name;
}

// Create the localized data that will be used by our block editor script.
$block_config = [
'availableBindings' => $available_bindings,
'availableBindings' => $available_bindings_for_queries,
'availableOverrides' => $config['overrides'] ?? [],
'instructions' => $config['instructions'],
'name' => $block_name,
'dataSourceType' => ConfigStore::get_data_source_type( $block_name ),
'patterns' => $config['patterns'],
'selectors' => $config['selectors'],
'patterns' => $patterns,
'displayQueriesToSelectors' => $display_queries_to_selectors,
'settings' => [
'category' => self::$block_category['slug'],
'icon' => $config['icon'] ?? 'cloud',
Expand All @@ -117,10 +134,6 @@ public static function register_block_configuration( array $config ): array {

$script_handle = $block_type->editor_script_handles[0] ?? '';

// Register a default pattern that simply displays the available data.
$default_pattern_name = BlockPatterns::register_default_block_pattern( $block_name, $config['title'], $config['queries'][ ConfigRegistry::DISPLAY_QUERY_KEY ] );
$block_config['patterns']['default'] = $default_pattern_name;

return [ $block_config, $script_handle ];
}
}
Loading
Loading