Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
improve code quality
  • Loading branch information
gigitux committed Jan 12, 2026
commit ba7c2fa2acfcdd5bb3851b28f0cd2b036f5970ff
3 changes: 2 additions & 1 deletion packages/core-data/src/private-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@
const queryItemIds = new Set< string >();
const queriesForContext = queriedData?.queries?.[ context ] || {};
Object.values( queriesForContext ).forEach( ( queryResult ) => {
if ( Array.isArray( queryResult?.itemIds ) ) {

Check failure on line 387 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / Check

Property 'itemIds' does not exist on type '{}'.

Check failure on line 387 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / check

Property 'itemIds' does not exist on type '{}'.

Check failure on line 387 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / All (Node.js 24 on Linux)

Property 'itemIds' does not exist on type '{}'.

Check failure on line 387 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / Run performance tests

Property 'itemIds' does not exist on type '{}'.
queryResult.itemIds.forEach( ( itemId ) =>

Check failure on line 388 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / Check

Property 'itemIds' does not exist on type '{}'.

Check failure on line 388 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / check

Property 'itemIds' does not exist on type '{}'.

Check failure on line 388 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / All (Node.js 24 on Linux)

Property 'itemIds' does not exist on type '{}'.

Check failure on line 388 in packages/core-data/src/private-selectors.ts

View workflow job for this annotation

GitHub Actions / Run performance tests

Property 'itemIds' does not exist on type '{}'.
queryItemIds.add( String( itemId ) )
);
}
Expand All @@ -396,7 +396,8 @@
if ( ! isStagedId( itemId ) ) {
return false;
}
if ( queryItemIds.has( itemId ) ) {
const itemIdKey = String( itemId );
if ( queryItemIds.has( itemIdKey ) ) {
return false;
}
if ( ! persistedLocalIds.has( itemId ) ) {
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/queried-data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function getQueriedItemsUncached( state, query ) {
include,
persistedIdMapForContext
);

itemId =
getLocalIdForPersistedId( persistedIdMapForContext, itemId ) ||
itemId;
Expand Down
73 changes: 0 additions & 73 deletions packages/core-data/src/queried-data/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,59 +180,6 @@ describe( 'persistedIdMap', () => {
expect( state ).toBe( original );
} );

it( 'should preserve existing mappings when adding new ones', () => {
const original = deepFreeze( {
default: {
5: '__staged__0',
},
} );
const state = persistedIdMap( original, {
type: 'RECEIVE_ITEMS',
items: [
{
id: '__staged__1',
name: 'New Staged Item',
__unstablePersistedId: 10,
},
],
} );

expect( state ).toEqual( {
default: {
5: '__staged__0',
10: '__staged__1',
},
} );
} );

it( 'should handle different contexts', () => {
const original = deepFreeze( {
default: {
5: '__staged__0',
},
} );
const state = persistedIdMap( original, {
type: 'RECEIVE_ITEMS',
query: { context: 'edit' },
items: [
{
id: '__staged__1',
name: 'Edit Context Item',
__unstablePersistedId: 10,
},
],
} );

expect( state ).toEqual( {
default: {
5: '__staged__0',
},
edit: {
10: '__staged__1',
},
} );
} );

it( 'should remove mappings when items are removed', () => {
const original = deepFreeze( {
default: {
Expand All @@ -258,26 +205,6 @@ describe( 'persistedIdMap', () => {
} );
} );

it( 'should remove multiple mappings when multiple items are removed', () => {
const original = deepFreeze( {
default: {
10: '__staged__1',
20: '__staged__2',
30: '__staged__3',
},
} );
const state = persistedIdMap( original, {
type: 'REMOVE_ITEMS',
itemIds: [ '__staged__1', '__staged__3' ],
} );

expect( state ).toEqual( {
default: {
20: '__staged__2',
},
} );
} );

it( 'should use custom key when provided', () => {
const original = deepFreeze( {} );
const state = persistedIdMap( original, {
Expand Down
103 changes: 0 additions & 103 deletions packages/core-data/src/queried-data/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,109 +176,6 @@ describe( 'getQueriedItems', () => {
] );
} );

it( 'should work without persistedIdMap (backwards compatibility)', () => {
const state = {
items: {
default: {
1: { id: 1, title: 'Post 1' },
2: { id: 2, title: 'Post 2' },
},
},
itemIsComplete: {
default: {
1: true,
2: true,
},
},
queries: {
default: {
'': { itemIds: [ 1, 2 ] },
},
},
// No persistedIdMap
};

const result = getQueriedItems( state );

expect( result ).toEqual( [
{ id: 1, title: 'Post 1' },
{ id: 2, title: 'Post 2' },
] );
} );

it( 'should handle mixed staged and regular items in query results', () => {
const state = {
items: {
default: {
__staged__1: {
id: '__staged__1',
title: 'Staged Post',
__unstablePersistedId: 10,
},
2: {
id: 2,
title: 'Regular Post',
},
},
},
itemIsComplete: {
default: {
__staged__1: true,
2: true,
},
},
queries: {
default: {
'': { itemIds: [ 10, 2 ] },
},
},
persistedIdMap: {
default: {
10: '__staged__1',
},
},
};

const result = getQueriedItems( state );

expect( result ).toEqual( [
{
id: '__staged__1',
title: 'Staged Post',
__unstablePersistedId: 10,
},
{ id: 2, title: 'Regular Post' },
] );
} );

it( 'should handle empty persistedIdMap for context', () => {
const state = {
items: {
default: {
1: { id: 1, title: 'Post' },
},
},
itemIsComplete: {
default: {
1: true,
},
},
queries: {
default: {
'': { itemIds: [ 1 ] },
},
},
persistedIdMap: {
// Empty for default context
default: {},
},
};

const result = getQueriedItems( state );

expect( result ).toEqual( [ { id: 1, title: 'Post' } ] );
} );

it( 'should dynamically construct fields-filtered item from available data', () => {
const state = {
items: {
Expand Down
43 changes: 0 additions & 43 deletions packages/core-data/src/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,49 +211,6 @@ describe( 'deleteEntityRecord', () => {
expect( result ).toBe( true );
} );

it( 'deletes staged records with persisted IDs via the API', async () => {
const stagedId = `${ STAGED_ID_PREFIX }test-uuid-123`;
const configs = [
{ name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
];

const dispatch = Object.assign( jest.fn(), {
receiveEntityRecords: jest.fn(),
__unstableAcquireStoreLock: jest.fn(),
__unstableReleaseStoreLock: jest.fn(),
} );
const resolveSelect = { getEntitiesConfig: jest.fn( () => configs ) };
const select = {
getPersistedIdMap: jest.fn( () => ( { 10: stagedId } ) ),
};

apiFetch.mockImplementation( () => ( { id: 10 } ) );

await deleteEntityRecord(
'postType',
'post',
stagedId
)( {
dispatch,
resolveSelect,
select,
} );

expect( apiFetch ).toHaveBeenCalledWith( {
path: '/wp/v2/posts/10',
method: 'DELETE',
} );
expect( dispatch ).toHaveBeenCalledWith(
expect.objectContaining( {
type: 'REMOVE_ITEMS',
itemIds: expect.arrayContaining( [ stagedId, '10' ] ),
kind: 'postType',
name: 'post',
invalidateCache: true,
} )
);
} );

it( 'removes staged record when deleting by persisted ID', async () => {
const configs = [
{ name: 'post', kind: 'postType', baseURL: '/wp/v2/posts' },
Expand Down
18 changes: 0 additions & 18 deletions packages/core-data/src/test/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,4 @@ describe( 'createStagedEntityRecord', () => {
undefined
);
} );

it( 'should generate unique staged IDs for each call', () => {
const record = { title: 'Test' };

const result1 = createStagedEntityRecord(
'postType',
'post',
record
)( { select, dispatch, resolveSelect } );

const result2 = createStagedEntityRecord(
'postType',
'post',
record
)( { select, dispatch, resolveSelect } );

expect( result1.id ).not.toBe( result2.id );
} );
} );
Loading
Loading