Skip to content

Commit

Permalink
client side paginated downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudis committed Jun 6, 2024
1 parent f384306 commit 8178e76
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/components/searchResults/BiosamplesResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function BiosamplesResults({ response, isLoading, error, query }) {
<>
<AlleleResponses
biosampleResponseSets={response.response.resultSets}
responseMeta={response.meta}
query={query}
/>
</>
Expand All @@ -23,7 +24,7 @@ export function BiosamplesResults({ response, isLoading, error, query }) {
)
}

function AlleleResponses({ biosampleResponseSets, query }) {
function AlleleResponses({ biosampleResponseSets, responseMeta, query }) {
if (biosampleResponseSets?.[0].resultsCount < 1) {
return (
<div className="notification">
Expand All @@ -32,7 +33,7 @@ function AlleleResponses({ biosampleResponseSets, query }) {
)
}
return biosampleResponseSets.map((r, i) => (
<DatasetResultBox key={i} data={r} query={query} />
<DatasetResultBox key={i} data={r} responseMeta={responseMeta} query={query} />
))
}

Expand Down
77 changes: 52 additions & 25 deletions src/components/searchResults/DatasetResultBox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, useState } from "react"
import {
// MAX_HISTO_SAMPLES,
SITE_DEFAULTS,
// SITE_DEFAULTS,
replaceWithProxy,
useProgenetixApi,
useExtendedSWR
Expand Down Expand Up @@ -38,7 +38,7 @@ const TABS = {
variants: "Variants"
}

export function DatasetResultBox({ data: responseSet, query }) {
export function DatasetResultBox({ data: responseSet, responseMeta, query }) {
const {
id,
resultsHandovers,
Expand All @@ -47,24 +47,54 @@ export function DatasetResultBox({ data: responseSet, query }) {
paginatedResultsCount
} = responseSet

console.log(responseMeta)

const limit = responseMeta.receivedRequestSummary?.pagination?.limit ? responseMeta.receivedRequestSummary?.pagination?.limit : 121

const handoverById = (givenId) =>
resultsHandovers.find(({ info: { contentId } }) => contentId === givenId)

const biosamplesHandover = handoverById(HANDOVER_IDS.biosamples)
const biosamplesTableHandover = handoverById(HANDOVER_IDS.biosamplestable)
const biosamplesmapURL = handoverById(HANDOVER_IDS.biosamplesmap) === undefined ? false : handoverById(HANDOVER_IDS.biosamplesmap).url
const phenopacketsHandover = handoverById(HANDOVER_IDS.phenopackets)
const variantsHandover = handoverById(HANDOVER_IDS.variants)
const vcfHandover = handoverById(HANDOVER_IDS.vcf)
const pgxsegHandover = handoverById(HANDOVER_IDS.pgxseg)
const UCSCbedHandoverURL = handoverById(HANDOVER_IDS.UCSClink) === undefined ? false : handoverById(HANDOVER_IDS.UCSClink).url

const biocount = biosamplesHandover.info.count
const biosamplesReply = useProgenetixApi(
biosamplesHandover && replaceWithProxy(biosamplesHandover.url)
)
const biosamplesTableHandover = handoverById(HANDOVER_IDS.biosamplestable)
biosamplesHandover.pages = []
biosamplesTableHandover.pages = []
var cntr = 0
var skpr = 0
while (cntr < biocount) {
const pagu = "&skip=" + skpr + "&limit=" + limit
cntr += limit
skpr += 1
biosamplesTableHandover.pages.push({"url": biosamplesTableHandover.url + pagu, "label": "Part" + skpr})
biosamplesHandover.pages.push({"url": biosamplesHandover.url + pagu, "label": "Part" + skpr})
}

const variantsHandover = handoverById(HANDOVER_IDS.variants)
const varcount = variantsHandover.info.count
const variantsReply = useProgenetixApi(
variantsHandover && replaceWithProxy(variantsHandover.url)
)
variantsHandover.pages = []
cntr = 0
skpr = 0
while (cntr < varcount) {
const pagu = "&skip=" + skpr + "&limit=" + limit
cntr += limit
skpr += 1
variantsHandover.pages.push({"url": variantsHandover.url + pagu, "label": "Part" + skpr})
}


// const phenopacketsHandover = handoverById(HANDOVER_IDS.phenopackets)
// const vcfHandover = handoverById(HANDOVER_IDS.vcf)
// const pgxsegHandover = handoverById(HANDOVER_IDS.pgxseg)
const UCSCbedHandoverURL = handoverById(HANDOVER_IDS.UCSClink) === undefined ? false : handoverById(HANDOVER_IDS.UCSClink).url


const biosamplesmapURL = handoverById(HANDOVER_IDS.biosamplesmap) === undefined ? false : handoverById(HANDOVER_IDS.biosamplesmap).url

// the histogram is only rendered but correct handover is needed, obviously
let histoplotUrl
Expand All @@ -74,16 +104,16 @@ export function DatasetResultBox({ data: responseSet, query }) {
let visualizationAccessId = new URLSearchParams(
new URL(histoplotUrl).search
).get("accessid")
let visualizationFileId = new URLSearchParams(
new URL(histoplotUrl).search
).get("fileId")
let visualizationSkip = new URLSearchParams(
new URL(histoplotUrl).search
).get("skip")
let visualizationLimit = new URLSearchParams(
new URL(histoplotUrl).search
).get("limit")
visualizationLink = getVisualizationLink(id, visualizationAccessId, visualizationFileId, visualizationSkip, visualizationLimit, paginatedResultsCount)
// let visualizationFileId = new URLSearchParams(
// new URL(histoplotUrl).search
// ).get("fileId")
// let visualizationSkip = new URLSearchParams(
// new URL(histoplotUrl).search
// ).get("skip")
// let visualizationLimit = new URLSearchParams(
// new URL(histoplotUrl).search
// ).get("limit")
visualizationLink = getVisualizationLink(id, visualizationAccessId, "", 0, 0, paginatedResultsCount)
}

var retrievedCount = resultsCount
Expand Down Expand Up @@ -225,10 +255,6 @@ export function DatasetResultBox({ data: responseSet, query }) {
</div>
) : null}
{tabComponent ? <div>{tabComponent}</div> : null}
{/*
// TODO:Implement paginated downloads, e.g. on separate form
// page with hidden accessid ... parameters and fields for
// limit / skip ...
<hr/>

{biosamplesTableHandover?.pages && (
Expand Down Expand Up @@ -270,6 +296,7 @@ export function DatasetResultBox({ data: responseSet, query }) {
</div>
</div>
)}
{/*
{vcfHandover?.pages && (
<div className="tabs ">
<div>
Expand Down Expand Up @@ -382,7 +409,7 @@ function PagedLink({ handover }) {
<li>
<ExternalLink
href={handover.url}
label={handover.handoverType.label}
label={handover.label}
download
/>
</li>
Expand Down
8 changes: 4 additions & 4 deletions src/config/beaconSearchParameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ parameters:
label: Skip Pages
infoText: >
The number of result pages to skip when retrieving data.
defaultValue: 0
isHidden: true
# defaultValue: 0
# isHidden: true
limit:
label: Response Limit / Page Size
infoText: >
The maximum number of biosamples to retrieve per page and also the size of response pages.
defaultValue: 100
isHidden: true
# defaultValue: 200
# isHidden: true

0 comments on commit 8178e76

Please sign in to comment.