Skip to content

Commit

Permalink
Additional beta docs improvements (#300)
Browse files Browse the repository at this point in the history
* initial changes

* adding strengths and weaknesses

* edits and renaming

* another name change and airtable stuff

* updating google sheets

* adding screen shot

* adding screen shot

* adding shopify and Salesforce skeleton

* final first-pass updates to tutorials

* Airtable tutorial grammatical fixes

Signed-off-by: brookewp <[email protected]>

* Google sheets tutorial grammatical fixes

Signed-off-by: brookewp <[email protected]>

* Salesforce tutorial grammatical fixes

Signed-off-by: brookewp <[email protected]>

* Shopify tutorial grammatical fixes

Signed-off-by: brookewp <[email protected]>

* HTTP tutorial grammatical fixes

Signed-off-by: brookewp <[email protected]>

* Concepts grammatical fixes and formatting

Signed-off-by: brookewp <[email protected]>

* Tutorial docs formatting

Signed-off-by: brookewp <[email protected]>

* Remaining proof-read docs

Signed-off-by: brookewp <[email protected]>

* adding block-bindings document

* cleaning up final changes from Workflows to Tutorials

* Add links from concepts index page

* Fix formatting

* Reordering to reflect sequence of events and utility

* Flesh out block registration options

* small updates

* updates to query

* settings forms fixes (#297)

* allow undefined values for handleOnChange to match allowed undefined in state values

* allow adding invalid string in google credentials input

* reset google spreadsheet and sheet inputs on credentials change

* reset airtable base and tables on token change

* update the register blocks function names in airtable conference event block registration

* url encode sheet name to fix invalid endpoint error (#298)

* url encode sheet name to fix invalid endpoint error

* use bracket notation for defining JSON path for Google Sheets

* Remove example glue code and example access tokens

* Update "Conference events" example

* Fix formatting

* adding better type documentation

* Fix README typo

* Slight rewording in Block Bindings docs

* Slight rewording in Airtable tutorial

* Reorder tutorials list to be alphabetical

* Add more detail to the HTTP tutorial

* Add Shopify steps for setting up API access

* Formatting fixes

* Move warning and use GitHub notice style

* Remove outdated instructions

* Remove link

* Promote Next Steps

* Remove footer (it's duplicated on remotedatablocks.com)

* Fix tutorial links

* Update code example links

* Fix tutorials link

* Small grammar fix

* Update link to LICENSE (not a Markdown file)

* Use absolute image references

* query examples

* finishing up output schema revisions

* grammer stuff

* Start of a Quickstart

* extending extending

* grammer changes

* update to block patterns

* fixing typo

* start work on block registration

* More content in the quickstart

* Auto formatting

---------

Signed-off-by: brookewp <[email protected]>
Co-authored-by: Jacob Wayne Smith <[email protected]>
Co-authored-by: brookewp <[email protected]>
Co-authored-by: chriszarate <[email protected]>
Co-authored-by: Shekhar Wagh <[email protected]>
  • Loading branch information
5 people authored Jan 18, 2025
1 parent e1b6b7a commit f6968bb
Show file tree
Hide file tree
Showing 23 changed files with 457 additions and 259 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- Contributors should review the WordPress [PHP coding standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/), [JavaScript coding standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/), and [accessibility coding standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/accessibility/). Accessibility in particular should be top of mind and thoroughly tested.

- You maintain copyright over any contribution you make. By submitting a pull request, you agree to release that code under [our license](LICENSE).
- You maintain copyright over any contribution you make. By submitting a pull request, you agree to release that code under [our license](https://github.com/Automattic/remote-data-blocks/blob/trunk/LICENSE).

- When contributing to this repository, please first discuss the change you wish to make via an issue or discussion.

Expand Down
65 changes: 11 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,20 @@
---
### :warning: This plugin is currently in Beta. Breaking changes could occur with any update. Please test each release thoroughly before updating.
---

# Remote Data Blocks

**Remote Data Blocks** is a WordPress plugin that makes it easy to combine content and remote data in the block editor. Easily register blocks that load data from Airtable, Google Sheets, Shopify, GitHub, or any other API. Your data stays in sync. Built-in caching ensures performance and reliability.
> [!WARNING]
> This plugin is currently in Beta. Breaking changes could occur with any update. Please test each release thoroughly before updating.
Remote Data Blocks lets you take tabular data, stored elsewhere and display it as headings, paragraphs, images and buttons in WordPress. Either as a list of all the rows in your table or as a single entry. [Read more about well supported use cases](docs/concepts/index.md#supported-use-cases).
**Remote Data Blocks** is a WordPress plugin that makes it easy to combine content and remote data in the block editor. Easily register blocks that load data from Airtable, Google Sheets, Shopify, GitHub, or any other API. Your data stays in sync. Built-in caching ensures performance and reliability. [Read more about well-supported use cases](docs/concepts/index.md#supported-use-cases).

[![Launch in WordPress Playground](https://img.shields.io/badge/Launch%20in%20WordPress%20Playground-DA9A45?style=for-the-badge&logo=wordpress)](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/Automattic/remote-data-blocks/trunk/blueprint.json)

[Launch the plugin in WordPress Playground](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/Automattic/remote-data-blocks/trunk/blueprint.json) and explore. An example API ("Conference Event") is included, or visit Settings > Remote Data Blocks to add your own. Visit the [workflows guide](docs/workflows/index.md) to dive in.

## Installation

The latest version of the plugin is available in the default `trunk` branch of this repository.

### Install via `git subtree`

We recommend installing the latest plugin version [via `git subtree`][wpvip-plugin-subtrees] within your site's repository:

```bash
# Enter your project's root directory:
cd my-site-repo/

# Add a subtree for the trunk branch:
git subtree add --prefix plugins/remote-data-blocks [email protected]:Automattic/remote-data-blocks.git trunk --squash
```

To deploy the plugin to a remote branch, `git push` the committed subtree.

The `trunk` branch will stay up to date with the latest version of the plugin. Use this command to pull the latest `trunk` branch changes:

```bash
git subtree pull --prefix plugins/remote-data-blocks [email protected]:Automattic/remote-data-blocks.git trunk --squash
```

Ensure that the plugin is up-to-date by pulling changes often.

Note: We **do not recommend** using `git submodule`. [Submodules on WPVIP that require authentication][wpvip-plugin-submodules] will fail to deploy.

### Install via ZIP file
[Launch the plugin in WordPress Playground](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/Automattic/remote-data-blocks/trunk/blueprint.json) and explore. An example API ("Conference Event") is included, or visit Settings > Remote Data Blocks to add your own. Read our [tutorials](docs/tutorials/index.md) to dive in.

The latest version of the plugin can be downloaded from the [repository's Releases page](https://github.com/Automattic/remote-data-blocks/releases/latest/download/remote-data-blocks.zip). Unzip the downloaded plugin and add it to the `plugins/` directory of your site's GitHub repository.

### Plugin activation
## Next steps

We recommend [activating plugins with code][wpvip-plugin-activate].
- Learn about the [core concepts](docs/concepts/index.md) behind Remote Data Blocks.
- Follow our [tutorials](docs/tutorials/index.md) to create your first connection and see Remote Data Blocks in action.
- If you're a developer, you're ready to [extend Remote Data Blocks with custom code](docs/extending/index.md).
- Interested in contributing? Issues, pull requests, and discussions are welcome. Please see our [contribution guide](CONTRIBUTING.md) for more information.

## Requirements

Expand All @@ -55,21 +23,10 @@ We recommend [activating plugins with code][wpvip-plugin-activate].

A [persistent object cache](https://developer.wordpress.org/reference/classes/wp_object_cache/#persistent-cache-plugins) is not strictly required, but it is highly recommended for optimal performance and to help avoid rate limiting from remote data sources. If your WordPress environment does not provide persistent object cache, the plugin will utilize in-memory (per-request) caching.

## Next steps
## Installation

- Learn about the [core concepts](docs/concepts/index.md) behind Remote Data Blocks.
- Create your first connecting following our [tutorials](docs/tutorials/index.md) to see Remote Data Blocks in action.
- If you're a developer, you're ready to [extend Remote Data Blocks with custom code](docs/extending/index.md).
- Interested in contributing? Issues, pull requests, and discussions are welcome. Please see our [contribution guide](CONTRIBUTING.md) for more information.
Download [the latest release of the plugin](https://github.com/Automattic/remote-data-blocks/releases/latest/download/remote-data-blocks.zip), unzip, and add it to the `plugins/` directory of your WordPress site.

## License

Remote Data Blocks is licensed under the [GPLv2 (or later)](LICENSE).

---

Made with ❤️ by [WordPress VIP](https://wpvip.com/).

[wpvip-plugin-activate]: https://docs.wpvip.com/how-tos/activate-plugins-through-code/
[wpvip-plugin-submodules]: https://docs.wpvip.com/technical-references/plugins/installing-plugins-best-practices/#h-submodules
[wpvip-plugin-subtrees]: https://docs.wpvip.com/technical-references/plugins/installing-plugins-best-practices/#h-subtrees
2 changes: 1 addition & 1 deletion docs/concepts/block-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Remote Data Blocks takes advantage of the [Block Bindings API](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-bindings/). This Core WordPress API allows you to “bind” dynamic data to the block's attributes, which are then reflected in the final HTML markup.

The Block Bindings API allows Remote Data Blocks to read from different sources without needing to write custom block boilerplate, React, block registration, and other particulars of writing custom blocks from scratch for each new source you want to read from.
The Block Bindings API allows Remote Data Blocks to read from different sources without needing to write custom block boilerplate, React, block registration, and other particulars of writing custom blocks from scratch for each new data source.

For a quick overview, the [announcement post](https://make.wordpress.org/core/2024/03/06/new-feature-the-block-bindings-api/) is very helpful. The Block Bindings API is evolving, and an in-depth understanding isn't necessary for day-to-day use.

Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Simple data sources can be configured via the plugin's settings screen, while ot

## Queries

**Queries** defines how data is fetched, processed, and displayed. Queries delegate some logic to a **data source**, which can be reused by multiple queries. For example, one query to retrieve a single item, and one to retrieve a list.
**Queries** define how data is fetched, processed, and displayed. Queries delegate some logic to a **data source**, which can be reused by multiple queries. For example, one query to retrieve a single item, and one to retrieve a list.

Simple queries can be configured via the plugin's settings screen, while others may require custom PHP code (see [extending](../extending/index.md)).

Expand Down Expand Up @@ -82,7 +82,7 @@ Remote data blocks can be styled using the block editor's style settings, `theme

Since remote data blocks are container blocks, you can associate a remote data block with a pattern to create reusable layouts. You link a pattern to a particular remote data block in the Site Editor. You will see a new Remote Data Blocks section in the right-hand panel when editing a pattern.

![Screenshot showing the right hand panel of the WordPress Site Editor](patterns-right-panel.png)
![Screenshot showing the right hand panel of the WordPress Site Editor](https://raw.githubusercontent.com/Automattic/remote-data-blocks/trunk/docs/concepts/patterns-right-panel.png)

Select the specific block that is appropriate for this pattern. Once saved, content creators can select this pattern when adding the associated remote data block.

Expand Down
24 changes: 14 additions & 10 deletions docs/extending/block-patterns.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Block patterns

Patterns allow you to represent your remote data in different ways. By default, the plugin registers an unstyled block pattern that you can use out of the box. You can create additional patterns in the WordPress Dashboard or programmatically by passing a `patterns` property to your block options.
Patterns allow you to represent your remote data in different ways. The plugin registers an unstyled block pattern anytime you register a remote data block either in the WordPress admin or with `register_remote_data_block`. You can create additional patterns in the WordPress Site Editor or programmatically by passing a `patterns` property to your block options.

Example:
You cannot edit the default pattern, but you can duplicate it and make changes. We recommend starting with a duplicate and then making changes in the Site Editor. If you want to lock the pattern down from further edits, copy the block markup from the editor and associate the pattern via code.

## Example

```html
<!-- wp:group {"layout":{"type":"constrained"}} -->
Expand All @@ -17,15 +19,17 @@ Example:
<!-- /wp:group -->
```

You could save this file as `my-pattern.html` in the same directory as the code that registers your block.

```php
register_remote_data_block( [
'title' => 'My Remote Data Block',
'render_query' => [ /* ... */ ],
'patterns' => [
[
'title' => 'My Pattern',
'content' => file_get_contents( __DIR__ . '/my-pattern.html' ),
],
],
'title' => 'My Remote Data Block',
'render_query' => [ /* ... */ ],
'patterns' => [
[
'title' => 'My Pattern',
'content' => file_get_contents( __DIR__ . '/my-pattern.html' ),
],
],
] );
```
13 changes: 11 additions & 2 deletions docs/extending/block-registration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ Use the `register_remote_data_block` function to register your block and associa
3. Defines the output schema of a query, which tells the plugin how to map the query response to blocks.
4. Registers a remote data block.

We are assuming `https://api.example.com/` returns JSON that has a shape like:

```json
{
"id": 12345,
"title": "An awesome title"
}
```

```php
function register_your_custom_block() {
$data_source = HttpDataSource::from_array( [
Expand Down Expand Up @@ -56,8 +65,8 @@ The human-friendly name of the block. It is also used to construct the block's n

The render query is executed when the block is rendered and fetches the data that will be provided to block bindings. It is an array with the following properties:

- `query`: An instance of `QueryInterface` that fetches the data.
- `loop`: A boolean that determines if the query returns a collection of data. If `true`, the block will be rendered for each item in the collection.
- `query`: An instance of [`QueryInterface`](./query.md) that fetches the data.
- `loop`: A boolean that indicates if the query returns a collection of data. If `true`, the block will be rendered for each item in the collection.

### `selection_queries`: array (optional)

Expand Down
90 changes: 70 additions & 20 deletions docs/extending/data-source.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,95 @@
# Data source

A data source defines basic reusable properties of an API and is used by a [query](query.md) to reduce boilerplate. It helps this plugin represent your data source in the plugin settings screen and other UI.
A data source defines the basic reusable properties of an API and is used by a [query](query.md) to reduce repeating code with every query. It also helps define how your data source looks in the WordPress admin.

## Example

Most HTTP-powered APIs can be represented by defining a class that extends `HttpDataSource`. Here's an example of a data source for an example HTTP API:

```php
$data_source = HttpDataSource::from_array( [
'service_config' => [
'__version' => 1,
'display_name' => 'Example API',
'endpoint' => 'https://api.example.com/',
'request_headers' => [
'Content-Type' => 'application/json',
'X-Api-Key': MY_API_KEY_CONSTANT,
],
],
'service_config' => [
'__version' => 1,
'display_name' => 'Example API',
'endpoint' => 'https://api.example.com/',
'request_headers' => [
'Content-Type' => 'application/json',
'X-Api-Key' => MY_API_KEY_CONSTANT,
],
],
] );
```

The configuration array passed to `from_array` is very flexible, so it's usually not necessary to extend `HttpDataSource`, but you can do so if you need to add custom behavior.
## HttpDataSource configuration

### **version**: number (required)

There is no built-in versioning logic, but a version number is required for best practice reasons. Changes to the data source could significantly affect [queries](query.md). Checking the data source version is a sensible defensive practice.

### display_name: string (required)

The display name is used in the UI to identify your data source.

### endpoint: string

This is the default endpoint for the data source and can save repeated use in queries. We would suggest putting the root API URL here and then manipulating it as necessary in individual [queries](query.md).

### request_headers: array

Headers will be set according to the properties of the array. When providing authentication credentials, take care to keep them from appearing in code repositories. We strongly recommend using environment variables or other secure means for storage.

## Additional parameters

You can add any additional parameters that are necessary for your data source. In our [Airtable example](../../example/airtable/events/register.php), you can see that we are setting values for the Airtable `base` and `table`.

Consider adding whatever configuration would be useful to queries. As an example, queries have an `endpoint` property. Our [Zip code example](../../example/rest-api/zip-code/register.php) sets the endpoint with a function:

```php
$zipcode_query = HttpQuery::from_array( [
'data_source' => $zipcode_data_source,
'endpoint' => function ( array $input_variables ) use ( $zipcode_data_source ): string {
return $zipcode_data_source->get_endpoint() . $input_variables['zip_code'];
},
])
```

In this case the `data_source` has a built in `get_endpoint()` method. You could also retrieve the endpoint this way:

```php
$zipcode_query = HttpQuery::from_array( [
'data_source' => $zipcode_data_source,
'endpoint' => function ( array $input_variables ) use ( $zipcode_data_source ): string {
return $zipcode_data_source->to_array()['service_config']['endpoint'] . $input_variables['zip_code'];
},
])
```

The goal with design was to provide you with flexibility you need to represent any data source.

## Custom data sources

The configuration array passed to `from_array` is very flexible, so it's usually not necessary to extend `HttpDataSource`, but you can do so if you need to add custom behavior.

For APIs that use non-HTTP transports, you can also implement `DataSourceInterface` and provide methods that define reusable properties of your API. The actual implementation of your transport will need to be provided by a [custom query runner](./query-runner.md).

Here is a theoretical example of a data source for a WebDAV server:

```php
class WebDavFilesDataSource implements DataSourceInterface {
public function get_display_name(): string {
return 'My WebDAV Files';
}
public function get_display_name(): string {
return 'My WebDAV Files';
}

public function get_image_url(): string {
return 'https://example.com/webdav-icon.png';
}
public function get_image_url(): string {
return 'https://example.com/webdav-icon.png';
}

public function get_webdav_root(): string {
return 'webdavs://webdav.example.com/';
}
public function get_webdav_root(): string {
return 'webdavs://webdav.example.com/';
}
}
```

```
```
3 changes: 1 addition & 2 deletions docs/extending/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ Here are some detailed overviews of these classes with notes on how and why to e
- [Data source](data-source.md)
- [Query](query.md)

Once you've defined your data source and queries, you can [register a remote data block](block-registration.md) that uses them.
Once you've defined your data source and queries, you can [register a remote data block](block-registration.md) that uses them. That block can use a [pattern](block-patterns.md) for display. You can also use [overrides](./overrides.md) to dynamically select the displayed content.

### Additional customization

- [Block patterns](block-patterns.md)
- [Hooks (actions and filters)](hooks.md)
- [Query runner](query-runner.md)

Expand Down
Loading

0 comments on commit f6968bb

Please sign in to comment.