summaryrefslogtreecommitdiff
path: root/node_modules/@jet-app/app-store/tmp/src/common/grouping/shelf-batching.js
blob: 3746b114d65f31627d76a5f6ac140c3bc94f69a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { isSome } from "@jet/environment";
import * as models from "../../api/models";
/// The number of shelves allowed in a single shelf batch.
const shelfBatchGroupMaxCount = 5;
/**
 * For a given generic page group the shelves in this page into batch groups
 * allowing us to separate our calls for incomplete shelves into groups based on where
 * the shelves are on the page. This will not muck with any pre-existing shelfBatchGroups
 *
 * @param page: The GenericPage to add shelf batches to.
 */
export function addBatchGroupsToPage(page) {
    let currentShelfBatchGroup = 0;
    let currentShelfBatchGroupCount = 0;
    for (const shelf of page.shelves) {
        if (isSome(shelf.batchGroup) && shelf.batchGroup.length > 0) {
            continue;
        }
        shelf.batchGroup = `${models.genericShelfBatchGroupBase}${currentShelfBatchGroup}`;
        currentShelfBatchGroupCount++;
        if (currentShelfBatchGroupCount === shelfBatchGroupMaxCount) {
            currentShelfBatchGroupCount = 0;
            currentShelfBatchGroup++;
        }
    }
}
//# sourceMappingURL=shelf-batching.js.map