Skip to content

Commit

Permalink
Fix image block binding (#163)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Chris Zarate <[email protected]>
  • Loading branch information
maxschmeling and chriszarate authored Oct 17, 2024
1 parent ad7eeed commit 33b7efe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion inc/Editor/BlockManagement/BlockRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function register_blocks(): void {
// Set available bindings from the display query output mappings.
$available_bindings = [];
foreach ( $config['queries']['__DISPLAY__']->output_schema['mappings'] ?? [] as $key => $mapping ) {
$available_bindings[ $key ] = [
$available_bindings[ ucfirst( $key ) ] = [
'name' => $mapping['name'],
'type' => $mapping['type'],
];
Expand Down
8 changes: 6 additions & 2 deletions inc/Integrations/Airtable/AirtableDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class AirtableDataSource extends HttpDataSource {
'type' => 'object',
'properties' => [
'name' => [ 'type' => 'string' ],
'type' => [
'type' => 'string',
'required' => false,
],
],
],
],
Expand Down Expand Up @@ -117,7 +121,7 @@ public function ___temp_get_query(): AirtableGetItemQuery|\WP_Error {
];

foreach ( $this->config['tables'][0]['output_query_mappings'] as $mapping ) {
$output_schema['mappings'][ strtolower( $mapping['name'] ) ] = [
$output_schema['mappings'][ ucfirst( $mapping['name'] ) ] = [
'name' => $mapping['name'],
'path' => '$.fields.' . ucfirst( $mapping['name'] ),
'type' => $mapping['type'] ?? 'string',
Expand Down Expand Up @@ -145,7 +149,7 @@ public function ___temp_get_list_query(): AirtableListItemsQuery|\WP_Error {
];

foreach ( $this->config['tables'][0]['output_query_mappings'] as $mapping ) {
$output_schema['mappings'][ strtolower( $mapping['name'] ) ] = [
$output_schema['mappings'][ ucfirst( $mapping['name'] ) ] = [
'name' => $mapping['name'],
'path' => '$.fields.' . ucfirst( $mapping['name'] ),
'type' => $mapping['type'] ?? 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface BlockBindingFieldControlProps {

export function BlockBindingFieldControl( props: BlockBindingFieldControlProps ) {
const { availableBindings, fieldTypes, label, target, updateFieldBinding, value } = props;

const options = Object.entries( availableBindings )
.filter( ( [ _key, mapping ] ) => fieldTypes.includes( mapping.type ) )
.map( ( [ key, mapping ] ) => {
Expand Down Expand Up @@ -42,8 +43,8 @@ export function BlockBindingControls( props: BlockBindingControlsProps ) {
const { attributes, availableBindings, blockName, removeBinding, updateBinding } = props;
const contentArgs = attributes.metadata?.bindings?.content?.args;
const contentField = contentArgs?.field ?? '';
const imageAltField = attributes.metadata?.bindings?.image_alt?.args?.field ?? '';
const imageUrlField = attributes.metadata?.bindings?.image_url?.args?.field ?? '';
const imageAltField = attributes.metadata?.bindings?.alt?.args?.field ?? '';
const imageUrlField = attributes.metadata?.bindings?.url?.args?.field ?? '';

function updateFieldBinding( target: string, field: string ): void {
if ( ! field ) {
Expand Down Expand Up @@ -97,15 +98,15 @@ export function BlockBindingControls( props: BlockBindingControlsProps ) {
availableBindings={ availableBindings }
fieldTypes={ [ 'image_url' ] }
label="Image URL"
target="image_url"
target="url"
updateFieldBinding={ updateFieldBinding }
value={ imageUrlField }
/>
<BlockBindingFieldControl
availableBindings={ availableBindings }
fieldTypes={ [ 'image_alt' ] }
fieldTypes={ [ 'image_alt', 'string' ] }
label="Image alt text"
target="image_alt"
target="alt"
updateFieldBinding={ updateFieldBinding }
value={ imageAltField }
/>
Expand Down

0 comments on commit 33b7efe

Please sign in to comment.