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

Fix issue where queries with no input still show block placeholder #304

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

maxschmeling
Copy link
Contributor

@maxschmeling maxschmeling commented Jan 17, 2025

When a block is registered for a query that doesn't have any inputs, it still shows the placeholder and requires you to provide "empty" input before it will run the query and render the block.
https://github.com/user-attachments/assets/556d5a30-cb8a-4e27-b27e-74b55bf3672a

Steps to test
Use the following plugin code and add a "Joke" block to a page.

<?php declare(strict_types = 1);

/**
* Plugin Name: Joke RDB Example
* Description: Displays a joke.
 * Author: WPVIP
 * Author URI: https://remotedatablocks.com/
 * Text Domain: remote-data-blocks
 * Version: 1.0.0
 * Requires Plugins: remote-data-blocks
*/

namespace RemoteDataBlocks\Example\Joke;

use RemoteDataBlocks\Config\DataSource\HttpDataSource;
use RemoteDataBlocks\Config\Query\HttpQuery;
use function add_query_arg;

function register_joke_block(): void {
	$joke_data_source = HttpDataSource::from_array( [
		'service_config' => [
			'__version' => 1,
			'display_name' => 'Jokes',
			'endpoint' => 'https://official-joke-api.appspot.com/random_joke',
			'request_headers' => [
				'Content-Type' => 'application/json',
			],
		],
	] );

	$get_joke_query = HttpQuery::from_array( [
		'data_source' => $joke_data_source,
		'endpoint' => $joke_data_source->get_endpoint(),
		'input_schema' => [ ],
		'output_schema' => [
			'is_collection' => false,
			'type' => [
        'id' => [
					'name' => 'Joke ID',
          'path' => '$["id"]',
					'type' => 'id',
				],
				'setup' => [
					'name' => 'Setup',
          'path' => '$["setup"]',
					'type' => 'string',
				],
				'punchline' => [
					'name' => 'Punchline',
          'path' => '$["punchline"]',
					'type' => 'string',
				],
			],
		],
    'cache_ttl' => -1,
	] );

	register_remote_data_block( [
		'title' => 'Joke',
		'render_query' => [
			'query' => $get_joke_query,
		],
	] );
}
add_action( 'init', __NAMESPACE__ . '\\register_joke_block' );

@maxschmeling maxschmeling merged commit e1b6b7a into trunk Jan 17, 2025
10 checks passed
@maxschmeling maxschmeling deleted the fix/placeholder-on-no-input-required branch January 17, 2025 22:56
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