Skip to content

Commit

Permalink
Remove the insert.ref field from insertUsage data (WordPress#51130)
Browse files Browse the repository at this point in the history
* Remove the insert.ref field from insertUsage data

* Update test data
  • Loading branch information
jsnajdr authored and sethrubenstein committed Jul 13, 2023
1 parent 147f8fa commit 75e2ebf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
14 changes: 6 additions & 8 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1604,18 +1604,17 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) {
case 'REPLACE_BLOCKS':
return action.blocks.reduce( ( prevState, block ) => {
const { attributes, name: blockName } = block;
let id = blockName;
// If a block variation match is found change the name to be the same with the
// one that is used for block variations in the Inserter (`getItemFromVariation`).
const match = select( blocksStore ).getActiveBlockVariation(
blockName,
attributes
);
// If a block variation match is found change the name to be the same with the
// one that is used for block variations in the Inserter (`getItemFromVariation`).
let id = match?.name
? `${ blockName }/${ match.name }`
: blockName;
const insert = { name: id };
if ( match?.name ) {
id += '/' + match.name;
}
if ( blockName === 'core/block' ) {
insert.ref = attributes.ref;
id += '/' + attributes.ref;
}

Expand All @@ -1628,7 +1627,6 @@ export function preferences( state = PREFERENCES_DEFAULTS, action ) {
count: prevState.insertUsage[ id ]
? prevState.insertUsage[ id ].count + 1
: 1,
insert,
},
},
};
Expand Down
7 changes: 0 additions & 7 deletions packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,6 @@ describe( 'state', () => {
'core/embed': {
time: 123456,
count: 1,
insert: { name: 'core/embed' },
},
},
} );
Expand All @@ -2900,7 +2899,6 @@ describe( 'state', () => {
'core/embed': {
time: 123456,
count: 1,
insert: { name: 'core/embed' },
},
},
} ),
Expand All @@ -2926,12 +2924,10 @@ describe( 'state', () => {
'core/embed': {
time: 123457,
count: 2,
insert: { name: 'core/embed' },
},
'core/block/123': {
time: 123457,
count: 1,
insert: { name: 'core/block', ref: 123 },
},
},
} );
Expand Down Expand Up @@ -2994,17 +2990,14 @@ describe( 'state', () => {
[ orangeVariationName ]: {
time: 123456,
count: 1,
insert: { name: orangeVariationName },
},
[ appleVariationName ]: {
time: 123456,
count: 1,
insert: { name: appleVariationName },
},
[ blockWithVariations ]: {
time: 123456,
count: 2,
insert: { name: blockWithVariations },
},
} ),
} );
Expand Down

0 comments on commit 75e2ebf

Please sign in to comment.