Skip to content

Commit

Permalink
pull through metadata template fields
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig committed Dec 23, 2024
1 parent da8a87e commit e61a0e0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
4 changes: 3 additions & 1 deletion website/src/components/Submission/DataUploadForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type DataUploadFormProps = {
action: UploadAction;
group: Group;
referenceGenomeSequenceNames: ReferenceGenomesSequenceNames;
metadataTemplateFields: string[];
onSuccess: () => void;
onError: (message: string) => void;
};
Expand Down Expand Up @@ -131,6 +132,7 @@ const InnerDataUploadForm = ({
onError,
group,
referenceGenomeSequenceNames,
metadataTemplateFields,
}: DataUploadFormProps) => {
const [metadataFile, setMetadataFile] = useState<File | null>(null);
// can be null; if null -> don't apply mapping.
Expand Down Expand Up @@ -302,7 +304,7 @@ const InnerDataUploadForm = ({
inputFile={metadataFile}
columnMapping={columnMapping}
setColumnMapping={setColumnMapping}
possibleTargetColumns={['foo', 'bar']} // TODO
possibleTargetColumns={metadataTemplateFields}
/>
)}
</div>
Expand Down
3 changes: 3 additions & 0 deletions website/src/components/Submission/RevisionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type RevisionFormProps = {
clientConfig: ClientConfig;
group: Group;
referenceGenomeSequenceNames: ReferenceGenomesSequenceNames;
metadataTemplateFields: string[];
};

export const RevisionForm: FC<RevisionFormProps> = ({
Expand All @@ -21,13 +22,15 @@ export const RevisionForm: FC<RevisionFormProps> = ({
clientConfig,
group,
referenceGenomeSequenceNames,
metadataTemplateFields,
}) => {
return (
<div className='flex flex-col items-center'>
<DataUploadForm
accessToken={accessToken}
organism={organism}
referenceGenomeSequenceNames={referenceGenomeSequenceNames}
metadataTemplateFields={metadataTemplateFields}
clientConfig={clientConfig}
action='revise'
onError={(message) => toast.error(message, { position: 'top-center', autoClose: false })}
Expand Down
3 changes: 3 additions & 0 deletions website/src/components/Submission/SubmissionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SubmissionFormProps = {
clientConfig: ClientConfig;
group: Group;
referenceGenomeSequenceNames: ReferenceGenomesSequenceNames;
metadataTemplateFields: string[];
};

export const SubmissionForm: FC<SubmissionFormProps> = ({
Expand All @@ -21,13 +22,15 @@ export const SubmissionForm: FC<SubmissionFormProps> = ({
clientConfig,
group,
referenceGenomeSequenceNames,
metadataTemplateFields,
}) => {
return (
<div className='flex flex-col items-center'>
<DataUploadForm
accessToken={accessToken}
organism={organism}
referenceGenomeSequenceNames={referenceGenomeSequenceNames}
metadataTemplateFields={metadataTemplateFields}
clientConfig={clientConfig}
action='submit'
onError={(message) => toast.error(message, { position: 'top-center', autoClose: false })}
Expand Down
7 changes: 5 additions & 2 deletions website/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';

import type { z, ZodError } from 'zod';

import { ACCESSION_FIELD, SUBMISSION_ID_FIELD } from './settings.ts';
import { type InstanceConfig, type Schema, type WebsiteConfig, websiteConfig } from './types/config.ts';
import { type ReferenceGenomes } from './types/referencesGenomes.ts';
import { runtimeConfig, type RuntimeConfig, type ServiceUrls } from './types/runtimeConfig.ts';
Expand Down Expand Up @@ -92,12 +93,14 @@ export function getSchema(organism: string): Schema {
return getConfig(organism).schema;
}

export function getMetadataTemplateFields(organism: string): string[] {
export function getMetadataTemplateFields(organism: string, action: 'submit' | 'revise'): string[] {
const schema = getConfig(organism).schema;
if (schema.metadataTemplate !== undefined) {
return schema.metadataTemplate;
}
return getConfig(organism).schema.inputFields.map((field) => field.name);
const baseFields = getConfig(organism).schema.inputFields.map((field) => field.name);
const extraFields = action === 'submit' ? [SUBMISSION_ID_FIELD] : [ACCESSION_FIELD, SUBMISSION_ID_FIELD];
return [...extraFields, ...baseFields];
}

export function getRuntimeConfig(): RuntimeConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { cleanOrganism } from '../../../../components/Navigation/cleanOrganism';
import { RevisionForm } from '../../../../components/Submission/RevisionForm';
import SubmissionPageWrapper from '../../../../components/Submission/SubmissionPageWrapper.astro';
import { getRuntimeConfig } from '../../../../config';
import { getMetadataTemplateFields, getRuntimeConfig } from '../../../../config';
import { getAccessToken } from '../../../../utils/getAccessToken';
import { getReferenceGenomesSequenceNames } from '../../../../utils/search';
import { getGroupsAndCurrentGroup } from '../../../../utils/submissionPages';
Expand All @@ -17,6 +17,7 @@ if (!cleanedOrganism) {
};
}
const referenceGenomeSequenceNames = getReferenceGenomesSequenceNames(cleanedOrganism.key);
const metadataTemplateFields = getMetadataTemplateFields(cleanedOrganism.key, 'revise');
const groupsResult = await getGroupsAndCurrentGroup(Astro.params, Astro.locals.session);
const clientConfig = getRuntimeConfig().public;
Expand All @@ -30,6 +31,7 @@ const clientConfig = getRuntimeConfig().public;
accessToken={getAccessToken(Astro.locals.session)!}
organism={organism}
referenceGenomeSequenceNames={referenceGenomeSequenceNames}
metadataTemplateFields={metadataTemplateFields}
clientConfig={clientConfig}
group={group}
client:load
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { cleanOrganism } from '../../../../components/Navigation/cleanOrganism';
import { SubmissionForm } from '../../../../components/Submission/SubmissionForm';
import SubmissionPageWrapper from '../../../../components/Submission/SubmissionPageWrapper.astro';
import { getRuntimeConfig } from '../../../../config';
import { getMetadataTemplateFields, getRuntimeConfig } from '../../../../config';
import { getAccessToken } from '../../../../utils/getAccessToken';
import { getReferenceGenomesSequenceNames } from '../../../../utils/search';
import { getGroupsAndCurrentGroup } from '../../../../utils/submissionPages';
Expand All @@ -18,6 +18,7 @@ if (!cleanedOrganism) {
};
}
const referenceGenomeSequenceNames = getReferenceGenomesSequenceNames(cleanedOrganism.key);
const metadataTemplateFields = getMetadataTemplateFields(cleanedOrganism.key, 'submit');
const groupsResult = await getGroupsAndCurrentGroup(Astro.params, Astro.locals.session);
Expand All @@ -36,6 +37,7 @@ Astro.response.headers.append('Expires', '0');
<SubmissionForm
accessToken={getAccessToken(Astro.locals.session)!}
referenceGenomeSequenceNames={referenceGenomeSequenceNames}
metadataTemplateFields={metadataTemplateFields}
organism={organism}
clientConfig={clientConfig}
group={group}
Expand Down
7 changes: 2 additions & 5 deletions website/src/pages/[organism]/submission/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { APIRoute } from 'astro';
import { cleanOrganism } from '../../../../components/Navigation/cleanOrganism';
import type { UploadAction } from '../../../../components/Submission/DataUploadForm.tsx';
import { getMetadataTemplateFields } from '../../../../config';
import { ACCESSION_FIELD, SUBMISSION_ID_FIELD } from '../../../../settings.ts';

/** The TSV template file that users can download from the submission page. */
export const GET: APIRoute = ({ params, request }) => {
Expand All @@ -16,7 +15,8 @@ export const GET: APIRoute = ({ params, request }) => {
}

const action: UploadAction = new URL(request.url).searchParams.get('format') === 'revise' ? 'revise' : 'submit';
const extraFields = action === 'submit' ? [SUBMISSION_ID_FIELD] : [ACCESSION_FIELD, SUBMISSION_ID_FIELD];
const fieldNames = getMetadataTemplateFields(organism.key, action);
const tsvTemplate = fieldNames.join('\t') + '\n';

const headers: Record<string, string> = {
'Content-Type': 'text/tsv', // eslint-disable-line @typescript-eslint/naming-convention
Expand All @@ -25,9 +25,6 @@ export const GET: APIRoute = ({ params, request }) => {
const filename = `${organism.displayName.replaceAll(' ', '_')}_metadata_${action === 'revise' ? 'revision_' : ''}template.tsv`;
headers['Content-Disposition'] = `attachment; filename="${filename}"`;

const fieldNames = getMetadataTemplateFields(organism.key);
const tsvTemplate = [...extraFields, ...fieldNames].join('\t') + '\n';

return new Response(tsvTemplate, {
headers,
});
Expand Down

0 comments on commit e61a0e0

Please sign in to comment.