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

add airtable rich text support #240

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
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 All @@ -31,7 +30,6 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [
'multilineText',
'email',
'phoneNumber',
'richText',
'barcode',
'singleSelect',
'multipleSelects',
Expand All @@ -53,6 +51,8 @@ export const SUPPORTED_AIRTABLE_TYPES = Object.freeze( [
'createdBy',
'lastModifiedBy',
'singleCollaborator',
// Markdown types
'richText',
// Other types
'multipleCollaborator',
'url',
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 @@ -32,6 +32,9 @@ export const getAirtableOutputQueryMappingValue = (
case 'button':
return { ...baseField, type: 'button_url' };

case 'richText':
return { ...baseField, type: 'markdown' };

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