Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(website): download compressed files #1220

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ describe('DownloadDialog', () => {

await userEvent.click(screen.getByLabelText(/Yes, include older versions/));
await userEvent.click(screen.getByLabelText(/Raw nucleotide sequences/));
await userEvent.click(screen.getByLabelText(/Gzip/));
expect(getDownloadHref()).toBe(
`${defaultLapisUrl}/sample/unalignedNucleotideSequences?downloadAsFile=true&dataUseTerms=OPEN&field1=value1`,
`${defaultLapisUrl}/sample/unalignedNucleotideSequences?downloadAsFile=true&dataUseTerms=OPEN&compression=gzip&field1=value1`,
);

await userEvent.click(screen.getByLabelText(/include restricted data/));
await userEvent.click(screen.getByLabelText(/Zstandard/));
expect(getDownloadHref()).toBe(
`${defaultLapisUrl}/sample/unalignedNucleotideSequences?downloadAsFile=true&field1=value1`,
`${defaultLapisUrl}/sample/unalignedNucleotideSequences?downloadAsFile=true&compression=zstd&field1=value1`,
);
});
});
Expand Down
11 changes: 11 additions & 0 deletions website/src/components/SearchPage/DownloadDialog/DownloadForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const DownloadForm: FC<DownloadFormProps> = ({ referenceGenomesSequenceNa
const [includeRestricted, setIncludeRestricted] = useState(0);
const [includeOldData, setIncludeOldData] = useState(0);
const [dataType, setDataType] = useState(0);
const [compression, setCompression] = useState(0);
chaoran-chen marked this conversation as resolved.
Show resolved Hide resolved
const [unalignedNucleotideSequence, setUnalignedNucleotideSequence] = useState(0);
const [alignedNucleotideSequence, setAlignedNucleotideSequence] = useState(0);
const [alignedAminoAcidSequence, setAlignedAminoAcidSequence] = useState(0);
Expand Down Expand Up @@ -50,14 +51,17 @@ export const DownloadForm: FC<DownloadFormProps> = ({ referenceGenomesSequenceNa
default:
throw new Error(`Invalid state error: DownloadForm dataType=${dataType}`);
}
const compressionOptions = [undefined, 'zstd', 'gzip'] as const;
onChange({
dataType: downloadDataType,
includeOldData: includeOldData === 1,
includeRestricted: includeRestricted === 1,
compression: compressionOptions[compression],
});
}, [
includeRestricted,
includeOldData,
compression,
dataType,
unalignedNucleotideSequence,
alignedNucleotideSequence,
Expand Down Expand Up @@ -161,6 +165,13 @@ export const DownloadForm: FC<DownloadFormProps> = ({ referenceGenomesSequenceNa
selected={dataType}
onSelect={setDataType}
/>
<RadioOptionBlock
name='compression'
title='Compression'
options={[{ label: <>None</> }, { label: <>Zstandard</> }, { label: <>Gzip</> }]}
selected={compression}
onSelect={setCompression}
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const RadioOptionBlock: FC<OptionBlockProps> = ({
disabled = false,
}) => {
return (
<div className='max-w-80'>
<div className='max-w-80 basis-1/3'>
{title !== undefined && <h4 className='font-bold'>{title}</h4>}
{options.map((option, index) => (
<div key={index}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ export type DownloadDataType =
| { type: 'alignedNucleotideSequences'; segment: string | undefined }
| { type: 'alignedAminoAcidSequences'; gene: string };

export type Compression = 'zstd' | 'gzip' | undefined;

export type DownloadOption = {
includeOldData: boolean;
includeRestricted: boolean;
dataType: DownloadDataType;
compression: Compression;
};

export const generateDownloadUrl = (
Expand All @@ -33,6 +36,9 @@ export const generateDownloadUrl = (
if (option.dataType.type === 'metadata') {
params.set('dataFormat', metadataDefaultDownloadDataFormat);
}
if (option.compression !== undefined) {
params.set('compression', option.compression);
}
for (const { name, filterValue } of metadataFilter) {
if (filterValue.trim().length > 0) {
params.set(name, filterValue);
Expand Down
Loading