-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #764 from Health-Informatics-UoN/fix/763/paginatio…
…n-limits Fix update table list of columns limit
- Loading branch information
Showing
3 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import request from "./request"; | ||
|
||
/** | ||
* Fetches all pages of paginated data from the specified url. | ||
* | ||
* Iterates through paginated data until all pages are fetched and concatenated. | ||
* | ||
* @template T - The type of data to be fetched | ||
* @param {string} url - The url to fetch from | ||
* @returns {Promise<T[]>} - A promise that resolves to an array of all fetched data | ||
*/ | ||
export async function fetchAllPages<T>(url: string): Promise<T[]> { | ||
let allResults: T[] = []; | ||
let pageNumber = 1; | ||
|
||
while (true) { | ||
const urlWithPage = `${url}&p=${pageNumber}`; | ||
const data: PaginatedResponse<T> = await request(urlWithPage); | ||
|
||
allResults = allResults.concat(data.results); | ||
pageNumber++; | ||
if (!data.next) break; | ||
} | ||
|
||
return allResults; | ||
} |