Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig committed Jan 8, 2025
1 parent f93e5c3 commit 3bbd86a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions website/src/components/Submission/DataUploadForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { dateTimeInMonths } from '../../utils/DateTimeInMonths.tsx';
import { createAuthorizationHeader } from '../../utils/createAuthorizationHeader.ts';
import { stringifyMaybeAxiosError } from '../../utils/stringifyMaybeAxiosError.ts';
import { withQueryProvider } from '../common/withQueryProvider.tsx';
import { FASTA_FILE_KIND, METADATA_FILE_KIND, ProcessedFile, RawFile } from './FileUpload/fileProcessing.ts';
import { FASTA_FILE_KIND, METADATA_FILE_KIND, type ProcessedFile, RawFile } from './FileUpload/fileProcessing.ts';

export type UploadAction = 'submit' | 'revise';

Expand Down Expand Up @@ -201,7 +201,7 @@ const InnerDataUploadForm = ({
break;
}
case 'revise':
revise({ metadataFile: finalMetadataFile, sequenceFile });
revise({ metadataFile: finalMetadataFile, sequenceFile: sequenceFile.inner() });
break;
}
};
Expand Down Expand Up @@ -267,8 +267,8 @@ const InnerDataUploadForm = ({
<DevExampleData
setExampleEntries={setExampleEntries}
exampleEntries={exampleEntries}
metadataFile={metadataFile.inner()}
sequenceFile={sequenceFile.inner()}
metadataFile={metadataFile ? metadataFile.inner() : null}
sequenceFile={sequenceFile ? sequenceFile.inner() : null}
handleLoadExampleData={handleLoadExampleData}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';

import { ColumnMapping } from './ColumnMapping';
import { RawFile } from './fileProcessing';

describe('ColumnMapping', () => {
it('should create a mapping from columns', () => {
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('ColumnMapping', () => {

const tsvFile = new File([tsvContent], 'input.tsv');

const remappedFile = await updatedMapping.applyTo(tsvFile);
const remappedFile = await updatedMapping.applyTo(new RawFile(tsvFile));
const remappedContent = await remappedFile.text();

expect(remappedContent).toBe('location\tdate\n' + 'USA\t2023-01-01\n' + 'Canada\t2023-01-02');
Expand Down
7 changes: 4 additions & 3 deletions website/src/components/Submission/FileUpload/ColumnMapping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stringSimilarity } from 'string-similarity-js';
import { ProcessedFile } from './fileProcessing';

import { type ProcessedFile } from './fileProcessing';

export class ColumnMapping {
private readonly map: ReadonlyMap<string, string>;
Expand Down Expand Up @@ -36,7 +37,7 @@ export class ColumnMapping {
/* Create a new mapping with the given columns, doing a best-effort to pre-match columns. */
public static fromColumns(sourceColumns: string[], targetColumns: Map<string, string | undefined>) {
const mapping = new Map<string, string>();
[...targetColumns.entries()].forEach(([targetColumn, targetColumnDisplayName]) => {
Array.from(targetColumns.entries()).forEach(([targetColumn, targetColumnDisplayName]) => {
const bestMatch = this.getBestMatchingSourceColumn(targetColumn, targetColumnDisplayName, sourceColumns);
mapping.set(targetColumn, bestMatch);
});
Expand All @@ -47,7 +48,7 @@ export class ColumnMapping {
mapping intact as possible. */
public update(newSourceColumns: string[], newTargetColumns: Map<string, string | undefined>): ColumnMapping {
const newMapping = new Map<string, string>();
[...newTargetColumns.entries()].forEach(([targetColumn, _targetColumnDisplayName]) => {
Array.from(newTargetColumns.entries()).forEach(([targetColumn, _targetColumnDisplayName]) => {
const prevSourceCol = this.map.get(targetColumn);
if (prevSourceCol && newSourceColumns.includes(prevSourceCol)) {
newMapping.set(targetColumn, prevSourceCol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState, type Dispatch, type FC, type SetStateAction } from
import { toast } from 'react-toastify';

import { ColumnMapping } from './ColumnMapping';
import { ProcessedFile } from './fileProcessing';
import { type ProcessedFile } from './fileProcessing';
import { BaseDialog } from '../../common/BaseDialog';

interface ColumnMappingModalProps {
Expand All @@ -28,6 +28,7 @@ export const ColumnMappingModal: FC<ColumnMappingModalProps> = ({
const [inputColumns, setInputColumns] = useState<string[] | null>(null);

useEffect(() => {
if (!isOpen) return;
const loadColumns = async () => {
const columnExtractionResult = await extractColumns(inputFile);
columnExtractionResult.match(
Expand All @@ -36,7 +37,7 @@ export const ColumnMappingModal: FC<ColumnMappingModalProps> = ({
);
};
void loadColumns();
}, [inputFile, setInputColumns]);
}, [isOpen, inputFile, setInputColumns]);

useEffect(() => {
if (inputColumns === null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export interface ProcessedFile {
warnings(): string[];
}

export const dummy = 0;

export class RawFile implements ProcessedFile {
private innerFile: File;

Expand All @@ -104,7 +106,6 @@ export class RawFile implements ProcessedFile {
}

export class CompressedFile extends RawFile {

async text(): Promise<string> {
const compressedData = new Uint8Array(await this.inner().arrayBuffer());
return fflate.strFromU8(fflate.decompressSync(compressedData));
Expand All @@ -124,7 +125,7 @@ export class ExcelFile implements ProcessedFile {
this.processingWarnings = [];
}

private async getRawData(): Promise<ArrayBuffer> {
private async getRawData(): Promise<ArrayBufferLike> {
if (!this.compressed) {
return this.originalFile.arrayBuffer();
} else {
Expand Down

0 comments on commit 3bbd86a

Please sign in to comment.