Skip to content

Commit e42d0d9

Browse files
authored
Update type names (#23)
* ContextInnerBlockAttributes => RemoteDataInnerBlockAttributes * ContextBlockAttributes => RemoteDataBlockAttributes
1 parent c20f178 commit e42d0d9

File tree

12 files changed

+26
-26
lines changed

12 files changed

+26
-26
lines changed

src/blocks/remote-data-container/components/block-binding-controls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function BlockBindingFieldControl( props: BlockBindingFieldControlProps )
3131
}
3232

3333
interface BlockBindingControlsProps {
34-
attributes: ContextInnerBlockAttributes;
34+
attributes: RemoteDataInnerBlockAttributes;
3535
availableBindings: AvailableBindings;
3636
blockName: string;
3737
removeBinding: ( target: string ) => void;

src/blocks/remote-data-container/components/inner-blocks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface InnerBlocksProps {
77
blockConfig: BlockConfig;
88
getInnerBlocks: (
99
result: Record< string, string >
10-
) => BlockInstance< ContextInnerBlockAttributes >[];
10+
) => BlockInstance< RemoteDataInnerBlockAttributes >[];
1111
remoteData: RemoteData;
1212
}
1313

src/blocks/remote-data-container/components/loop-template.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { LoopIndexContext } from '@/blocks/remote-data-container/context/loop-in
1515
interface LoopTemplateProps {
1616
getInnerBlocks: (
1717
result: Record< string, string >
18-
) => BlockInstance< ContextInnerBlockAttributes >[];
18+
) => BlockInstance< RemoteDataInnerBlockAttributes >[];
1919
remoteData: RemoteData;
2020
}
2121

src/blocks/remote-data-container/edit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { hasRemoteDataChanged } from '@/utils/block-binding';
1515
import { getBlockConfig } from '@/utils/localized-block-data';
1616
import './editor.scss';
1717

18-
export function Edit( props: BlockEditProps< ContextBlockAttributes > ) {
18+
export function Edit( props: BlockEditProps< RemoteDataBlockAttributes > ) {
1919
const blockConfig = getBlockConfig( props.name );
2020

2121
if ( ! blockConfig ) {

src/blocks/remote-data-container/hooks/use-existing-remote-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function useExistingRemoteData(): RemoteData[] {
1717

1818
return blocks
1919
.map( clientId => {
20-
const block = getBlocksByClientId< ContextBlockAttributes >( clientId )[ 0 ];
20+
const block = getBlocksByClientId< RemoteDataBlockAttributes >( clientId )[ 0 ];
2121
return block?.attributes?.remoteData;
2222
} )
2323
.filter( ( maybeRemoteData ): maybeRemoteData is RemoteData => Boolean( maybeRemoteData ) );

src/blocks/remote-data-container/hooks/use-patterns.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export function usePatterns( blockName: string, rootClientId: string ) {
3333
return {
3434
getInnerBlocks: (
3535
result: Record< string, string >
36-
): BlockInstance< ContextInnerBlockAttributes >[] => {
37-
return getBlocks< ContextInnerBlockAttributes >( rootClientId ).map( block =>
36+
): BlockInstance< RemoteDataInnerBlockAttributes >[] => {
37+
return getBlocks< RemoteDataInnerBlockAttributes >( rootClientId ).map( block =>
3838
cloneBlockWithAttributes( block, result )
3939
);
4040
},

src/blocks/remote-data-container/hooks/with-block-binding.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import { getMismatchedAttributes } from '@/utils/block-binding';
1717
import { getBlockAvailableBindings } from '@/utils/localized-block-data';
1818

1919
interface BoundBlockEditProps {
20-
attributes: ContextInnerBlockAttributes;
20+
attributes: RemoteDataInnerBlockAttributes;
2121
availableBindings: AvailableBindings;
2222
blockName: string;
2323
children: JSX.Element;
2424
remoteDataName: string;
25-
setAttributes: ( attributes: ContextInnerBlockAttributes ) => void;
25+
setAttributes: ( attributes: RemoteDataInnerBlockAttributes ) => void;
2626
}
2727

2828
function BoundBlockEdit( props: BoundBlockEditProps ) {
@@ -78,7 +78,7 @@ function BoundBlockEdit( props: BoundBlockEditProps ) {
7878
}
7979

8080
export const withBlockBinding = createHigherOrderComponent( BlockEdit => {
81-
return ( props: BlockEditProps< ContextInnerBlockAttributes > ) => {
81+
return ( props: BlockEditProps< RemoteDataInnerBlockAttributes > ) => {
8282
const { attributes, context, name, setAttributes } = props;
8383
const remoteData = context[ REMOTE_DATA_CONTEXT_KEY ] as RemoteData | undefined;
8484
const availableBindings = getBlockAvailableBindings( remoteData?.blockName ?? '' );
@@ -118,7 +118,7 @@ export const withBlockBinding = createHigherOrderComponent( BlockEdit => {
118118

119119
// If the block has a binding and the attributes do not match their expected
120120
// values, update and merge the attributes.
121-
const mergedAttributes = useMemo< ContextInnerBlockAttributes >( () => {
121+
const mergedAttributes = useMemo< RemoteDataInnerBlockAttributes >( () => {
122122
return {
123123
...attributes,
124124
...getMismatchedAttributes( attributes, remoteData.results, index ),

src/blocks/remote-data-container/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import './style.scss';
1111

1212
// Register a unique block definition for each of the context blocks.
1313
Object.values( getBlocksConfig() ).forEach( blockConfig => {
14-
registerBlockType< ContextBlockAttributes >( blockConfig.name, {
14+
registerBlockType< RemoteDataBlockAttributes >( blockConfig.name, {
1515
...blockConfig.settings,
1616
attributes: {
1717
remoteData: {

src/utils/block-binding.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ function getExpectedAttributeValue(
3131
}
3232

3333
export function getBoundAttributeEntries(
34-
attributes: ContextInnerBlockAttributes
34+
attributes: RemoteDataInnerBlockAttributes
3535
): [ string, RemoteDataBlockBinding ][] {
3636
return Object.entries( attributes.metadata?.bindings ?? {} ).filter(
3737
( [ _target, binding ] ) => binding.source === BLOCK_BINDING_SOURCE
3838
);
3939
}
4040

4141
export function getMismatchedAttributes(
42-
attributes: ContextInnerBlockAttributes,
42+
attributes: RemoteDataInnerBlockAttributes,
4343
results: RemoteData[ 'results' ],
4444
index = 0
45-
): Partial< ContextInnerBlockAttributes > {
45+
): Partial< RemoteDataInnerBlockAttributes > {
4646
return Object.fromEntries(
4747
getBoundAttributeEntries( attributes )
4848
.map( ( [ target, binding ] ) => [
@@ -52,7 +52,7 @@ export function getMismatchedAttributes(
5252
.filter(
5353
( [ target, value ] ) => null !== value && value !== getAttributeValue( attributes, target )
5454
)
55-
) as Partial< ContextInnerBlockAttributes >;
55+
) as Partial< RemoteDataInnerBlockAttributes >;
5656
}
5757

5858
export function hasRemoteDataChanged( one: RemoteData, two: RemoteData ): boolean {

tests/src/utils/block-binding.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe( 'block-binding utils', () => {
77
describe( 'getBoundAttributeEntries', () => {
88
it( 'should return bound attribute entries', () => {
99
const name = 'test/block';
10-
const attributes: ContextInnerBlockAttributes = {
10+
const attributes: RemoteDataInnerBlockAttributes = {
1111
metadata: {
1212
bindings: {
1313
content: { source: BLOCK_BINDING_SOURCE, args: { name, field: 'title' } },
@@ -26,7 +26,7 @@ describe( 'block-binding utils', () => {
2626
} );
2727

2828
it( 'should return an empty array when no bindings are present', () => {
29-
const attributes: ContextInnerBlockAttributes = {};
29+
const attributes: RemoteDataInnerBlockAttributes = {};
3030

3131
const result = getBoundAttributeEntries( attributes );
3232

@@ -37,7 +37,7 @@ describe( 'block-binding utils', () => {
3737
describe( 'getMismatchedAttributes', () => {
3838
it( 'should return mismatched attributes', () => {
3939
const name = 'test/block';
40-
const attributes: ContextInnerBlockAttributes = {
40+
const attributes: RemoteDataInnerBlockAttributes = {
4141
content: 'Old content',
4242
url: 'https://old-url.com',
4343
alt: 'Old alt',
@@ -61,7 +61,7 @@ describe( 'block-binding utils', () => {
6161

6262
it( 'should return an empty object when no mismatches are found', () => {
6363
const name = 'test/block';
64-
const attributes: ContextInnerBlockAttributes = {
64+
const attributes: RemoteDataInnerBlockAttributes = {
6565
content: 'Title: Current content',
6666
url: 'https://current-url.com',
6767
metadata: {
@@ -84,7 +84,7 @@ describe( 'block-binding utils', () => {
8484

8585
it( 'should handle missing results', () => {
8686
const name = 'test/block';
87-
const attributes: ContextInnerBlockAttributes = {
87+
const attributes: RemoteDataInnerBlockAttributes = {
8888
content: 'Old content',
8989
url: 'https://old-url.com',
9090
metadata: {
@@ -106,7 +106,7 @@ describe( 'block-binding utils', () => {
106106

107107
it( 'should handle missing label', () => {
108108
const name = 'test/block';
109-
const attributes: ContextInnerBlockAttributes = {
109+
const attributes: RemoteDataInnerBlockAttributes = {
110110
content: 'My Title',
111111
metadata: {
112112
bindings: {

types/remote-data.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ interface RemoteData {
2323
results: Record< string, string >[];
2424
}
2525

26-
interface ContextBlockAttributes {
26+
interface RemoteDataBlockAttributes {
2727
remoteData: RemoteData;
2828
}
2929

30-
interface FieldSelection extends ContextBlockAttributes {
30+
interface FieldSelection extends RemoteDataBlockAttributes {
3131
selectedField: string;
3232
type: 'field' | 'meta';
3333
}
@@ -47,7 +47,7 @@ interface RemoteDataBlockBinding {
4747
args: RemoteDataBlockBindingArgs;
4848
}
4949

50-
interface ContextInnerBlockAttributes {
50+
interface RemoteDataInnerBlockAttributes {
5151
alt?: string | RichTextData;
5252
content?: string | RichTextData;
5353
index?: number;

types/wordpress__block-editor/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare module '@wordpress/block-editor' {
2727

2828
// Incomplete type for our use case.
2929
interface BlockPattern {
30-
blocks: BlockInstance< ContextInnerBlockAttributes >[];
30+
blocks: BlockInstance< RemoteDataInnerBlockAttributes >[];
3131
name: string;
3232
title: string;
3333
}

0 commit comments

Comments
 (0)