Skip to content

Commit

Permalink
add airtable rich text support (#240)
Browse files Browse the repository at this point in the history
* add support for 'markdown' type

* map airtable field type 'richText' to 'markdown' type

* update supported types in query in docs
  • Loading branch information
shekharnwagh authored Dec 19, 2024
1 parent db77812 commit 261b6b1
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 13 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"galbar/jsonpath": "^3.0",
"guzzlehttp/guzzle": "^7.8",
"kevinrob/guzzle-cache-middleware": "^6.0",
"psr/log": "^3.0"
"psr/log": "^3.0",
"erusev/parsedown": "^1.7"
},
"require-dev": {
"automattic/vipwpcs": "^3.0",
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions docs/extending/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,9 @@ The `get_input_schema` method defines the input data expected by the query. The
- `type`: The type of the override. Supported values are `query_var` and `url`.
- `target`: The targeted entity for the override (e.g., the query or URL variable that contains the overridde).
- `type` (required): The type of the input variable. Supported types are:
- `base64`
- `boolean`
- `button_url`
- `image_alt`
- `image_url`
- `number`
- `currency`
- `string`
- `id`

#### Example

Expand All @@ -101,7 +96,17 @@ The `get_output_schema` method defines how to extract data from the API response
- `name` (optional): The human-friendly display name of the output variable.
- `default_value` (optional): The default value for the output variable.
- `path` (required): A [JSONPath](https://jsonpath.com/) expression to extract the variable value.
- `type` (required): The type of the output variable. Supported types are `string`, `number`, and `boolean`.
- `type` (required): The type of the output variable. Supported types are -
- `id`
- `base64`
- `boolean`
- `number`
- `string`
- `button_url`
- `image_url`
- `image_alt`
- `currency`
- `markdown`

#### Example

Expand Down
4 changes: 4 additions & 0 deletions inc/Config/QueryRunner/QueryRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use GuzzleHttp\RequestOptions;
use JsonPath\JsonObject;
use Parsedown;
use RemoteDataBlocks\Config\QueryContext\HttpQueryContext;
use RemoteDataBlocks\HttpClient\HttpClient;
use WP_Error;
Expand Down Expand Up @@ -259,6 +260,9 @@ protected function get_field_value( array|string $field_value, array $mapping ):
case 'html':
return $field_value_single;

case 'markdown':
return Parsedown::instance()->text( $field_value_single );

case 'currency':
$currency_symbol = $mapping['prefix'] ?? '$';
return sprintf( '%s%s', $currency_symbol, number_format( (float) $field_value_single, 2 ) );
Expand Down
1 change: 1 addition & 0 deletions inc/Editor/BlockPatterns/BlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static function register_default_block_pattern( string $block_name, strin
];
break;

case 'markdown':
case 'base64':
case 'currency':
$bindings['paragraphs'][] = [
Expand Down
1 change: 0 additions & 1 deletion inc/REST/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use WP_REST_Response;
use WP_Error;

defined( 'ABSPATH' ) || exit();
defined( 'ABSPATH' ) || exit();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/remote-data-container/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export const REMOTE_DATA_REST_API_URL = getRestUrl();
export const CONTAINER_CLASS_NAME = getClassName( 'container' );

export const IMAGE_FIELD_TYPES = [ 'image_alt', 'image_url' ];
export const TEXT_FIELD_TYPES = [ 'number', 'base64', 'currency', 'string' ];
export const TEXT_FIELD_TYPES = [ 'number', 'base64', 'currency', 'string', 'markdown' ];
export const BUTTON_FIELD_TYPES = [ 'button_url' ];
4 changes: 2 additions & 2 deletions src/data-sources/airtable/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const AIRTABLE_STRING_TYPES = Object.freeze(
'multilineText',
'email',
'phoneNumber',
'richText',
'barcode',
'singleSelect',
'date',
Expand Down Expand Up @@ -32,7 +31,6 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [
'multilineText',
'email',
'phoneNumber',
'richText',
'barcode',
'singleSelect',
'multipleSelects',
Expand All @@ -55,6 +53,8 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [
'createdBy',
'lastModifiedBy',
'singleCollaborator',
// Markdown types
'richText',
// Other types
'multipleCollaborators',
'currency',
Expand Down
3 changes: 3 additions & 0 deletions src/data-sources/airtable/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const getAirtableOutputQueryMappingValue = (
}

switch ( field.type ) {
case 'richText':
return { ...baseField, type: 'markdown' };

case 'currency':
return {
...baseField,
Expand Down

0 comments on commit 261b6b1

Please sign in to comment.