Skip to content

Commit

Permalink
feat(backend): pluralize Sequences, remove accessionVersion, adapt …
Browse files Browse the repository at this point in the history
…download format
  • Loading branch information
TobiasKampmann committed Feb 1, 2024
1 parent 99bdf55 commit de60dd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions website/src/components/Edit/EditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ const InnerEditPage: FC<EditPageProps> = ({ organism, dataToEdit, clientConfig,
<button
className='btn normal-case'
onClick={() => generateAndDownloadFastaFile(editedSequences, dataToEdit)}
title={`Download the original, unaligned sequence${
editedSequences.length > 1 ? 's' : ''
} as provided by the submitter`}
>
Download Sequences as fasta file
Download Sequence{editedSequences.length > 1 ? 's' : ''}
</button>
</div>

Expand Down Expand Up @@ -157,16 +160,17 @@ function useSubmitEditedSequence(

function generateAndDownloadFastaFile(editedSequences: Row[], editedData: SequenceEntryToEdit) {
const accessionVersion = getAccessionVersionString(editedData);
const fileContent = editedSequences
.map((sequence) => `>${accessionVersion}.${sequence.key}\n${sequence.value}\n\n`)
.join();
const fileContent =
editedSequences.length === 1
? `>${accessionVersion}\n${editedSequences[0].value}`
: editedSequences.map((sequence) => `>${accessionVersion}_${sequence.key}\n${sequence.value}\n\n`).join();

const blob = new Blob([fileContent], { type: 'text/plain' });
const url = URL.createObjectURL(blob);

const a = document.createElement('a');
a.href = url;
a.download = `accessionVersion${accessionVersion}.fasta`;
a.download = `${accessionVersion}.fasta`;
a.click();

URL.revokeObjectURL(url);
Expand Down
6 changes: 3 additions & 3 deletions website/tests/pages/edit/edit.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Page } from '@playwright/test';

import { routes } from '../../../src/routes.ts';
import type { AccessionVersion } from '../../../src/types/backend.ts';
import { getAccessionVersionString } from '../../../src/utils/extractAccessionVersion.ts';
import { extractAccessionVersion, getAccessionVersionString } from '../../../src/utils/extractAccessionVersion.ts';
import { baseUrl, dummyOrganism, expect } from '../../e2e.fixture';

export class EditPage {
Expand Down Expand Up @@ -33,7 +33,7 @@ export class EditPage {
await this.downloadButton.click();
const download = await downloadPromise;

expect(download.suggestedFilename()).toContain('accessionVersion');
expect(download.suggestedFilename()).toContain(getAccessionVersionString(accessionVersion));
const downloadStream = await download.createReadStream();
expect(downloadStream).toBeDefined();

Expand All @@ -46,7 +46,7 @@ export class EditPage {
downloadStream.on('end', resolve);
});

expect(downloadData.toString()).toContain(`>${getAccessionVersionString(accessionVersion)}.main
expect(downloadData.toString()).toContain(`>${getAccessionVersionString(accessionVersion)}
ACTG`);
}
}

0 comments on commit de60dd9

Please sign in to comment.