-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(website): move logic to TS file, properly use neverthrow
Refs: #1713
- Loading branch information
1 parent
f6400aa
commit b846d6b
Showing
3 changed files
with
74 additions
and
75 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
website/src/pages/seq/[accessionVersion]/findOrganismAndData.ts
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,28 @@ | ||
import { err, ok } from 'neverthrow'; | ||
|
||
import { getSequenceDetailsTableData, SequenceDetailsTableResultType } from './getSequenceDetailsTableData.ts'; | ||
import { getConfiguredOrganisms } from '../../../config.ts'; | ||
|
||
export async function findOrganismAndData(accessionVersion: string) { | ||
const organisms = getConfiguredOrganisms(); | ||
|
||
const promises = organisms.map(async ({ key }) => { | ||
return { | ||
organism: key, | ||
result: await getSequenceDetailsTableData(accessionVersion, key), | ||
}; | ||
}); | ||
|
||
const queries = await Promise.all(promises); | ||
|
||
for (const { organism, result } of queries) { | ||
if (result.isOk()) { | ||
return ok({ | ||
organism, | ||
result: result.value, | ||
}); | ||
} | ||
} | ||
|
||
return err({ type: SequenceDetailsTableResultType.ERROR }); | ||
} |
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 |
---|---|---|
@@ -1,106 +1,75 @@ | ||
--- | ||
import { getSequenceDetailsTableData, SequenceDetailsTableResultType } from './getSequenceDetailsTableData'; | ||
import { findOrganismAndData } from './findOrganismAndData'; | ||
import { SequenceDetailsTableResultType } from './getSequenceDetailsTableData'; | ||
import RevocationEntryDataTable from '../../../components/SequenceDetailsPage/RevocationEntryDataTable.astro'; | ||
import SequencesBanner from '../../../components/SequenceDetailsPage/SequencesBanner.astro'; | ||
import SequencesDataTableTitle from '../../../components/SequenceDetailsPage/SequencesDataTableTitle.astro'; | ||
import SequencesDataPage from '../../../components/SequenceDetailsPage/SequencesDetailsPage.astro'; | ||
import { isRevocationEntry } from '../../../components/SequenceDetailsPage/getTableData'; | ||
import ErrorBox from '../../../components/common/ErrorBox.astro'; | ||
import { getConfiguredOrganisms } from '../../../config'; | ||
import BaseLayout from '../../../layouts/BaseLayout.astro'; | ||
const accessionVersion = Astro.params.accessionVersion!; | ||
const organisms = getConfiguredOrganisms(); | ||
let sequenceDetailsTableData; | ||
let organism: string | undefined; | ||
const promises = organisms.map(async ({ key }) => { | ||
return { | ||
organism: key, | ||
result: await getSequenceDetailsTableData(accessionVersion, key), | ||
}; | ||
}); | ||
const queries = await Promise.all(promises); | ||
for (const query of queries) { | ||
if (query.result.isOk()) { | ||
sequenceDetailsTableData = query.result; | ||
organism = query.organism; | ||
break; | ||
} | ||
} | ||
if (sequenceDetailsTableData === undefined) { | ||
sequenceDetailsTableData = { | ||
isOk: () => false, | ||
type: SequenceDetailsTableResultType.ERROR, | ||
}; | ||
} | ||
const sequenceDetailsTableData = await findOrganismAndData(accessionVersion); | ||
if ( | ||
sequenceDetailsTableData.isOk() && | ||
sequenceDetailsTableData.value!.type === SequenceDetailsTableResultType.REDIRECT | ||
sequenceDetailsTableData.value.result.type === SequenceDetailsTableResultType.REDIRECT | ||
) { | ||
return Astro.redirect(sequenceDetailsTableData.value.redirectUrl); | ||
return Astro.redirect(sequenceDetailsTableData.value.result.redirectUrl); | ||
} | ||
--- | ||
|
||
<BaseLayout | ||
title={sequenceDetailsTableData.isOk() ? accessionVersion : 'Sequence not found'} | ||
implicitOrganism={organism} | ||
implicitOrganism={sequenceDetailsTableData.isOk() ? sequenceDetailsTableData.value.organism : undefined} | ||
> | ||
{ | ||
sequenceDetailsTableData.isOk() && | ||
sequenceDetailsTableData.value!.type === SequenceDetailsTableResultType.TABLE_DATA && ( | ||
sequenceDetailsTableData.value.result.type === SequenceDetailsTableResultType.TABLE_DATA && ( | ||
<div slot='banner'> | ||
<SequencesBanner | ||
sequenceEntryHistory={sequenceDetailsTableData.value!.sequenceEntryHistory} | ||
sequenceEntryHistory={sequenceDetailsTableData.value.result.sequenceEntryHistory} | ||
accessionVersion={accessionVersion} | ||
/> | ||
</div> | ||
) | ||
} | ||
{ | ||
sequenceDetailsTableData.isOk() && ( | ||
<SequencesDataTableTitle | ||
accessionVersion={accessionVersion} | ||
organism={organism!} | ||
sequenceEntryHistory={ | ||
sequenceDetailsTableData.isOk() && | ||
sequenceDetailsTableData.value!.type === SequenceDetailsTableResultType.TABLE_DATA | ||
? sequenceDetailsTableData.value!.sequenceEntryHistory | ||
: undefined | ||
} | ||
/> | ||
) | ||
} | ||
|
||
{ | ||
sequenceDetailsTableData.isOk() && | ||
sequenceDetailsTableData.match!( | ||
(data) => | ||
data.type === SequenceDetailsTableResultType.TABLE_DATA && | ||
(isRevocationEntry(data.tableData) ? ( | ||
<RevocationEntryDataTable | ||
tableData={data.tableData} | ||
dataUseTermsHistory={data.dataUseTermsHistory} | ||
/> | ||
) : ( | ||
<SequencesDataPage | ||
tableData={data.tableData} | ||
organism={organism!} | ||
accessionVersion={accessionVersion} | ||
dataUseTermsHistory={data.dataUseTermsHistory} | ||
/> | ||
)), | ||
() => null, | ||
) | ||
} | ||
{ | ||
!sequenceDetailsTableData.isOk() && ( | ||
<ErrorBox title='Sequence entry not found'>No data found for accession version {accessionVersion}</ErrorBox> | ||
sequenceDetailsTableData.match( | ||
({ organism, result }) => ( | ||
<> | ||
<SequencesDataTableTitle | ||
accessionVersion={accessionVersion} | ||
organism={organism} | ||
sequenceEntryHistory={ | ||
sequenceDetailsTableData.isOk() && result.type === SequenceDetailsTableResultType.TABLE_DATA | ||
? result.sequenceEntryHistory | ||
: undefined | ||
} | ||
/> | ||
{result.type === SequenceDetailsTableResultType.TABLE_DATA && | ||
(isRevocationEntry(result.tableData) ? ( | ||
<RevocationEntryDataTable | ||
tableData={result.tableData} | ||
dataUseTermsHistory={result.dataUseTermsHistory} | ||
/> | ||
) : ( | ||
<SequencesDataPage | ||
tableData={result.tableData} | ||
organism={organism} | ||
accessionVersion={accessionVersion} | ||
dataUseTermsHistory={result.dataUseTermsHistory} | ||
/> | ||
))} | ||
</> | ||
), | ||
() => ( | ||
<ErrorBox title='Sequence entry not found'> | ||
No data found for accession version {accessionVersion} | ||
</ErrorBox> | ||
), | ||
) | ||
} | ||
</BaseLayout> |