Skip to content

Commit 261b6b1

Browse files
authored
add airtable rich text support (#240)
* add support for 'markdown' type * map airtable field type 'richText' to 'markdown' type * update supported types in query in docs
1 parent db77812 commit 261b6b1

File tree

9 files changed

+76
-13
lines changed

9 files changed

+76
-13
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"galbar/jsonpath": "^3.0",
3333
"guzzlehttp/guzzle": "^7.8",
3434
"kevinrob/guzzle-cache-middleware": "^6.0",
35-
"psr/log": "^3.0"
35+
"psr/log": "^3.0",
36+
"erusev/parsedown": "^1.7"
3637
},
3738
"require-dev": {
3839
"automattic/vipwpcs": "^3.0",

composer.lock

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/extending/query.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,9 @@ The `get_input_schema` method defines the input data expected by the query. The
6868
- `type`: The type of the override. Supported values are `query_var` and `url`.
6969
- `target`: The targeted entity for the override (e.g., the query or URL variable that contains the overridde).
7070
- `type` (required): The type of the input variable. Supported types are:
71-
- `base64`
72-
- `boolean`
73-
- `button_url`
74-
- `image_alt`
75-
- `image_url`
7671
- `number`
77-
- `currency`
7872
- `string`
73+
- `id`
7974

8075
#### Example
8176

@@ -101,7 +96,17 @@ The `get_output_schema` method defines how to extract data from the API response
10196
- `name` (optional): The human-friendly display name of the output variable.
10297
- `default_value` (optional): The default value for the output variable.
10398
- `path` (required): A [JSONPath](https://jsonpath.com/) expression to extract the variable value.
104-
- `type` (required): The type of the output variable. Supported types are `string`, `number`, and `boolean`.
99+
- `type` (required): The type of the output variable. Supported types are -
100+
- `id`
101+
- `base64`
102+
- `boolean`
103+
- `number`
104+
- `string`
105+
- `button_url`
106+
- `image_url`
107+
- `image_alt`
108+
- `currency`
109+
- `markdown`
105110

106111
#### Example
107112

inc/Config/QueryRunner/QueryRunner.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use GuzzleHttp\RequestOptions;
77
use JsonPath\JsonObject;
8+
use Parsedown;
89
use RemoteDataBlocks\Config\QueryContext\HttpQueryContext;
910
use RemoteDataBlocks\HttpClient\HttpClient;
1011
use WP_Error;
@@ -259,6 +260,9 @@ protected function get_field_value( array|string $field_value, array $mapping ):
259260
case 'html':
260261
return $field_value_single;
261262

263+
case 'markdown':
264+
return Parsedown::instance()->text( $field_value_single );
265+
262266
case 'currency':
263267
$currency_symbol = $mapping['prefix'] ?? '$';
264268
return sprintf( '%s%s', $currency_symbol, number_format( (float) $field_value_single, 2 ) );

inc/Editor/BlockPatterns/BlockPatterns.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public static function register_default_block_pattern( string $block_name, strin
108108
];
109109
break;
110110

111+
case 'markdown':
111112
case 'base64':
112113
case 'currency':
113114
$bindings['paragraphs'][] = [

inc/REST/AuthController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use WP_REST_Response;
99
use WP_Error;
1010

11-
defined( 'ABSPATH' ) || exit();
1211
defined( 'ABSPATH' ) || exit();
1312

1413
/**

src/blocks/remote-data-container/config/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export const REMOTE_DATA_REST_API_URL = getRestUrl();
1515
export const CONTAINER_CLASS_NAME = getClassName( 'container' );
1616

1717
export const IMAGE_FIELD_TYPES = [ 'image_alt', 'image_url' ];
18-
export const TEXT_FIELD_TYPES = [ 'number', 'base64', 'currency', 'string' ];
18+
export const TEXT_FIELD_TYPES = [ 'number', 'base64', 'currency', 'string', 'markdown' ];
1919
export const BUTTON_FIELD_TYPES = [ 'button_url' ];

src/data-sources/airtable/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export const AIRTABLE_STRING_TYPES = Object.freeze(
44
'multilineText',
55
'email',
66
'phoneNumber',
7-
'richText',
87
'barcode',
98
'singleSelect',
109
'date',
@@ -32,7 +31,6 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [
3231
'multilineText',
3332
'email',
3433
'phoneNumber',
35-
'richText',
3634
'barcode',
3735
'singleSelect',
3836
'multipleSelects',
@@ -55,6 +53,8 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [
5553
'createdBy',
5654
'lastModifiedBy',
5755
'singleCollaborator',
56+
// Markdown types
57+
'richText',
5858
// Other types
5959
'multipleCollaborators',
6060
'currency',

src/data-sources/airtable/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export const getAirtableOutputQueryMappingValue = (
2828
}
2929

3030
switch ( field.type ) {
31+
case 'richText':
32+
return { ...baseField, type: 'markdown' };
33+
3134
case 'currency':
3235
return {
3336
...baseField,

0 commit comments

Comments
 (0)