Skip to content

Commit

Permalink
Move seq pages so they aren't within organism/ (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson authored Mar 11, 2024
1 parent 41c6fff commit d511087
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 156 deletions.
5 changes: 4 additions & 1 deletion website/src/components/Navigation/OrganismSelector.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { type Organism } from '../../config';
import { routes } from '../../routes';
import IwwaArrowDown from '~icons/iwwa/arrow-down';
const { knownOrganisms, organism } = cleanOrganism(Astro.params.organism);
const { knownOrganisms, organism: originalOrganism } = cleanOrganism(Astro.params.organism);
const { implicitOrganism } = Astro.props;
const foundimplicitOrganism = knownOrganisms.find((knownOrganism: Organism) => knownOrganism.key === implicitOrganism);
const organism = foundimplicitOrganism || originalOrganism;
const label = organism === undefined ? 'Organisms' : organism.displayName;
const firstBitOfUrl = Astro.url.pathname.split('/')[1];
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/SearchPage/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const Table: FC<TableProps> = ({
{data.map((row, index) => (
<tr key={index}>
<td>
<a href={routes.sequencesDetailsPage(organism, row[primaryKey] as string)}>
<a href={routes.sequencesDetailsPage(row[primaryKey] as string)}>
{row[primaryKey]}
</a>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { getAccessionVersionString } from '../../utils/extractAccessionVersion';
interface Props {
sequenceEntryHistory: SequenceEntryHistory;
accessionVersion: string;
organism: string;
}
const { sequenceEntryHistory, accessionVersion, organism } = Astro.props;
const { sequenceEntryHistory, accessionVersion } = Astro.props;
const ownHistoryEntry = sequenceEntryHistory.find((entry) => entry.accessionVersion === accessionVersion);
Expand All @@ -29,10 +28,7 @@ const isLatestVersion = ownHistoryEntry?.versionStatus === siloVersionStatuses.l
{latestAccessionVersion !== undefined && (
<p>
Go to the latest version:
<a
href={routes.sequencesDetailsPage(organism, latestAccessionVersion)}
class='font-bold underline mx-3'
>
<a href={routes.sequencesDetailsPage(latestAccessionVersion)} class='font-bold underline mx-3'>
{getAccessionVersionString(latestAccessionVersion)}
</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
accessionVersion: string;
}
const { sequenceEntryHistory, organism, accessionVersion } = Astro.props;
const { sequenceEntryHistory, accessionVersion } = Astro.props;
---

<div class='flex justify-between flex-wrap'>
Expand All @@ -25,7 +25,7 @@ const { sequenceEntryHistory, organism, accessionVersion } = Astro.props;
sequenceEntryHistory !== undefined && sequenceEntryHistory.length > 1 && (
<div class='dropdown dropdown-hover'>
<label tabindex='0' class='btn btn-sm btn-outline py-1'>
<a href={routes.versionPage(organism, accessionVersion)} class='text-sm'>
<a href={routes.versionPage(accessionVersion)} class='text-sm'>
All versions
</a>
<Arrow />
Expand All @@ -36,7 +36,7 @@ const { sequenceEntryHistory, organism, accessionVersion } = Astro.props;
>
{sequenceEntryHistory.map((version) => (
<li>
<a href={routes.sequencesDetailsPage(organism, getAccessionVersionString({ ...version }))}>
<a href={routes.sequencesDetailsPage(getAccessionVersionString({ ...version }))}>
{getAccessionVersionString({ ...version })}

<p class={`font-bold ${getVersionStatusColor(version.versionStatus)}`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const isMyGroup =
<div>
<a
class='mt-4 inline-block text-blue-600 hover:text-blue-800'
href={routes.sequencesFastaPage(organism, accessionVersion) + '?download'}
href={routes.sequencesFastaPage(accessionVersion) + '?download'}
>
Download FASTA
</a>
Expand Down
5 changes: 3 additions & 2 deletions website/src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const { name: websiteName, logo } = websiteConfig;
interface Props {
title: string;
implicitOrganism?: string;
}
const { title } = Astro.props;
const { title, implicitOrganism } = Astro.props;
---

<html lang='en'>
Expand Down Expand Up @@ -47,7 +48,7 @@ const { title } = Astro.props;
>
<a href='/' class='fancytitle mr-4'>{websiteName}</a>
</div>
<OrganismSelector />
<OrganismSelector implicitOrganism={implicitOrganism} />
</div>
</div>
<Navigation />
Expand Down
5 changes: 1 addition & 4 deletions website/src/pages/404.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import BaseLayout from '../layouts/BaseLayout.astro';
<BaseLayout title='Not Found'>
<div class='bc'>
<h1 class='title'>Page not found</h1>
<p>
The page you are looking for does not exist.
<a href='/'>Go to start page.</a>
</p>
<p>The page you are looking for does not exist.</p>
</div>
</BaseLayout>
3 changes: 0 additions & 3 deletions website/src/pages/500.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ import BaseLayout from '../layouts/BaseLayout.astro';
<BaseLayout title='Internal Server Error'>
<div class='bc'>
<h1 class='title'>An Error occurred</h1>
<p>
<a href='/'>Go to start page.</a>
</p>
</div>
</BaseLayout>
79 changes: 0 additions & 79 deletions website/src/pages/[organism]/seq/[accessionVersion]/index.astro

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { APIRoute } from 'astro';
import { err, type Result } from 'neverthrow';

import { getReferenceGenomes } from '../../../../config.ts';
import { routes } from '../../../../routes.ts';
import { LapisClient } from '../../../../services/lapisClient.ts';
import type { ProblemDetail } from '../../../../types/backend.ts';
import { parseAccessionVersionFromString } from '../../../../utils/extractAccessionVersion.ts';
import { fastaEntryToString, parseFasta } from '../../../../utils/parseFasta.ts';
import { getConfiguredOrganisms } from '../../../config';
import { getReferenceGenomes } from '../../../config.ts';
import { routes } from '../../../routes.ts';
import { LapisClient } from '../../../services/lapisClient.ts';
import { type ProblemDetail } from '../../../types/backend.ts';
import { parseAccessionVersionFromString } from '../../../utils/extractAccessionVersion.ts';
import { fastaEntryToString, parseFasta } from '../../../utils/parseFasta.ts';

export const GET: APIRoute = async ({ params, redirect, request }) => {
const accessionVersion = params.accessionVersion!;
const organism = params.organism!;

const isDownload = new URL(request.url).searchParams.has('download');

const result = await getSequenceDetailsUnalignedFasta(accessionVersion, organism, isDownload);
const result = await getSequenceDetailsUnalignedFasta(accessionVersion, isDownload);
if (!result.isOk()) {
return new Response(undefined, {
status: 404,
Expand Down Expand Up @@ -53,7 +53,7 @@ type Redirect = {
redirectUrl: string;
};

const getSequenceDetailsUnalignedFasta = async (
const getSequenceDetailsUnalignedFastaWithOrganism = async (
accessionVersion: string,
organism: string,
isDownload: boolean,
Expand All @@ -66,7 +66,7 @@ const getSequenceDetailsUnalignedFasta = async (
const latestVersionResult = await lapisClient.getLatestAccessionVersion(accession);
return latestVersionResult.map((latestVersion) => ({
type: ResultType.REDIRECT,
redirectUrl: routes.sequencesFastaPage(organism, latestVersion, isDownload),
redirectUrl: routes.sequencesFastaPage(latestVersion, isDownload),
}));
}

Expand Down Expand Up @@ -109,3 +109,17 @@ const getSequenceDetailsUnalignedFasta = async (
fasta,
}));
};

const getSequenceDetailsUnalignedFasta = async (accessionVersion: string, isDownload: boolean) => {
const organisms = getConfiguredOrganisms();
const results = await Promise.all(
organisms.map((organism) =>
getSequenceDetailsUnalignedFastaWithOrganism(accessionVersion, organism.key, isDownload),
),
);
const firstSuccess = results.find((result) => result.isOk());
if (firstSuccess) {
return firstSuccess;
}
return results[0];
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Result } from 'neverthrow';

import { getTableData, type TableDataEntry } from '../../../../components/SequenceDetailsPage/getTableData.ts';
import { getSchema } from '../../../../config.ts';
import { routes } from '../../../../routes.ts';
import { BackendClient } from '../../../../services/backendClient.ts';
import { LapisClient } from '../../../../services/lapisClient.ts';
import type { DataUseTermsHistoryEntry, ProblemDetail } from '../../../../types/backend.ts';
import type { SequenceEntryHistory } from '../../../../types/lapis.ts';
import { parseAccessionVersionFromString } from '../../../../utils/extractAccessionVersion.ts';
import { getTableData, type TableDataEntry } from '../../../components/SequenceDetailsPage/getTableData.ts';
import { getSchema } from '../../../config.ts';
import { routes } from '../../../routes.ts';
import { BackendClient } from '../../../services/backendClient.ts';
import { LapisClient } from '../../../services/lapisClient.ts';
import type { DataUseTermsHistoryEntry, ProblemDetail } from '../../../types/backend.ts';
import type { SequenceEntryHistory } from '../../../types/lapis.ts';
import { parseAccessionVersionFromString } from '../../../utils/extractAccessionVersion.ts';

export enum SequenceDetailsTableResultType {
TABLE_DATA = 'tableData',
REDIRECT = 'redirect',
ERROR = 'error',
}

type TableData = {
Expand Down Expand Up @@ -39,7 +40,7 @@ export const getSequenceDetailsTableData = async (
const latestVersionResult = await lapisClient.getLatestAccessionVersion(accession);
return latestVersionResult.map((latestVersion) => ({
type: SequenceDetailsTableResultType.REDIRECT,
redirectUrl: routes.sequencesDetailsPage(organism, latestVersion),
redirectUrl: routes.sequencesDetailsPage(latestVersion),
}));
}

Expand Down
Loading

0 comments on commit d511087

Please sign in to comment.