| 1 |
/** |
| 2 |
* Clear sync parameter from the URL. |
| 3 |
* |
| 4 |
* @returns {void} |
| 5 |
*/ |
| 6 |
export const clearSyncParam = () => { |
| 7 |
window.history.replaceState( |
| 8 |
{}, |
| 9 |
document.title, |
| 10 |
document.location.pathname + document.location.search.replace(/&do_sync/, ''), |
| 11 |
); |
| 12 |
}; |
| 13 |
|
| 14 |
/** |
| 15 |
* Get the total number of items from index meta. |
| 16 |
* |
| 17 |
* @param {object} indexMeta Index meta. |
| 18 |
* @returns {number} Number of items. |
| 19 |
*/ |
| 20 |
export const getItemsTotalFromIndexMeta = (indexMeta) => { |
| 21 |
let itemsTotal = 0; |
| 22 |
|
| 23 |
if (indexMeta.current_sync_item) { |
| 24 |
itemsTotal += indexMeta.current_sync_item.found_items; |
| 25 |
} |
| 26 |
|
| 27 |
itemsTotal = indexMeta.sync_stack.reduce( |
| 28 |
(itemsTotal, sync) => itemsTotal + sync.found_items, |
| 29 |
itemsTotal, |
| 30 |
); |
| 31 |
|
| 32 |
itemsTotal += indexMeta.totals.failed; |
| 33 |
itemsTotal += indexMeta.totals.skipped; |
| 34 |
itemsTotal += indexMeta.totals.synced; |
| 35 |
|
| 36 |
return itemsTotal; |
| 37 |
}; |
| 38 |
|
| 39 |
/** |
| 40 |
* Get the number of processed items from index meta. |
| 41 |
* |
| 42 |
* @param {object} indexMeta Index meta. |
| 43 |
* @returns {number} Number of processed items. |
| 44 |
*/ |
| 45 |
export const getItemsProcessedFromIndexMeta = (indexMeta) => { |
| 46 |
let itemsProcessed = 0; |
| 47 |
|
| 48 |
if (indexMeta.current_sync_item) { |
| 49 |
itemsProcessed += indexMeta.current_sync_item.failed; |
| 50 |
itemsProcessed += indexMeta.current_sync_item.skipped; |
| 51 |
itemsProcessed += indexMeta.current_sync_item.synced; |
| 52 |
} |
| 53 |
|
| 54 |
itemsProcessed += indexMeta.totals.failed; |
| 55 |
itemsProcessed += indexMeta.totals.skipped; |
| 56 |
itemsProcessed += indexMeta.totals.synced; |
| 57 |
|
| 58 |
return itemsProcessed; |
| 59 |
}; |
| 60 |
|