Maintain query order when merging core Order data and lookup table data.

This commit is contained in:
Jeff Stieler 2019-07-17 09:56:59 -06:00
parent 705379bdbb
commit 66e321f568
1 changed files with 10 additions and 5 deletions

View File

@ -292,13 +292,18 @@ export default compose(
order_includes: map( actionableOrders, 'id' ),
};
// Merge the core endpoint data with our reporting table.
const reportOrdersById = keyBy( getReportItems( 'orders', ordersQuery ).data, 'order_id' );
const actionableOrdersById = keyBy( actionableOrders, 'id' );
const orders = Object.values( merge( reportOrdersById, actionableOrdersById ) );
const reportOrders = getReportItems( 'orders', ordersQuery ).data;
const isError = Boolean( getReportItemsError( 'orders', ordersQuery ) );
const isRequesting = isReportItemsRequesting( 'orders', ordersQuery );
let orders = [];
if ( reportOrders && reportOrders.length ) {
// Merge the core endpoint data with our reporting table.
const actionableOrdersById = keyBy( actionableOrders, 'id' );
orders = reportOrders.map( order =>
merge( {}, order, actionableOrdersById[ order.order_id ] || {} )
);
}
return { orders, isError, isRequesting, orderStatuses };
}