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

Fix metadata types #1013

Merged
merged 1 commit into from
Feb 15, 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
15 changes: 8 additions & 7 deletions website/src/components/Edit/EditPage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { beforeEach, describe, expect, test } from 'vitest';

import { EditPage } from './EditPage.tsx';
import { testAccessToken, testOrganism } from '../../../vitest.setup.ts';
import type { MetadataField, SequenceEntryToEdit } from '../../types/backend.ts';
import type { MetadataField, SequenceEntryToEdit, UnprocessedMetadataRecord } from '../../types/backend.ts';
import type { ClientConfig } from '../../types/runtimeConfig.ts';

const queryClient = new QueryClient();
Expand Down Expand Up @@ -49,6 +49,7 @@ const defaultReviewData: SequenceEntryToEdit = {
processedData: {
metadata: {
processedMetaDataField: 'processedMetaDataValue',
nullField: null,
},
unalignedNucleotideSequences: {
unalignedProcessedSequenceName: 'processedUnalignedNucleotideSequencesValue',
Expand Down Expand Up @@ -158,24 +159,24 @@ describe('EditPage', () => {
});

const expectTextInSequenceData = {
original: (metadata: Record<string, MetadataField>): void =>
original: (metadata: Record<string, string>): void =>
Object.entries(metadata).forEach(([key, value]) => {
expect(screen.getByText(key + ':')).toBeInTheDocument();
expect(screen.getByDisplayValue(value.toString())).toBeInTheDocument();
expect(screen.getByDisplayValue(value)).toBeInTheDocument();
}),
originalMetadata: (metadata: Record<string, MetadataField>): void =>
originalMetadata: (metadata: UnprocessedMetadataRecord): void =>
Object.entries(metadata).forEach(([key, value]) => {
expect(screen.getByText(sentenceCase(key) + ':')).toBeInTheDocument();
expect(screen.getByDisplayValue(value.toString())).toBeInTheDocument();
expect(screen.getByDisplayValue(value)).toBeInTheDocument();
}),
processed: (metadata: Record<string, MetadataField>): void =>
processed: (metadata: Record<string, string>): void =>
Object.entries(metadata).forEach(([key, value]) => {
expect(screen.getByText(key + ':')).toBeInTheDocument();
expect(screen.getByText(value.toString())).toBeInTheDocument();
}),
processedMetadata: (metadata: Record<string, MetadataField>): void =>
Object.entries(metadata).forEach(([key, value]) => {
expect(screen.getByText(sentenceCase(key) + ':')).toBeInTheDocument();
expect(screen.getByText(value.toString())).toBeInTheDocument();
expect(screen.getByText((value ?? 'null').toString())).toBeInTheDocument();
}),
};
10 changes: 7 additions & 3 deletions website/src/components/Edit/EditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ACCESSION_FIELD } from '../../settings.ts';
import type { MetadataRecord, ProcessingAnnotationSourceType, SequenceEntryToEdit } from '../../types/backend.ts';
import type { ClientConfig } from '../../types/runtimeConfig.ts';
import { createAuthorizationHeader } from '../../utils/createAuthorizationHeader.ts';
import { displayMetadataField } from '../../utils/displayMetadataField.ts';
import { getAccessionVersionString } from '../../utils/extractAccessionVersion.ts';
import { ConfirmationDialog } from '../DeprecatedConfirmationDialog.tsx';
import { ManagedErrorFeedback, useErrorFeedbackState } from '../common/ManagedErrorFeedback.tsx';
Expand Down Expand Up @@ -248,7 +249,10 @@ const ProcessedMetadata: FC<ProcessedMetadataProps> = ({ processedMetadata }) =>
<>
<Subtitle title='Metadata' customKey='preprocessing_metadata' />
{Object.entries(processedMetadata).map(([key, value]) => (
<ProcessedDataRow key={'processed' + key} row={{ key: sentenceCase(key), value: value.toString() }} />
<ProcessedDataRow
key={'processed' + key}
row={{ key: sentenceCase(key), value: displayMetadataField(value) }}
/>
))}
</>
);
Expand Down Expand Up @@ -282,8 +286,8 @@ const ProcessedInsertions: FC<ProcessedInsertionsProps> = ({ processedInsertions
const mapMetadataToRow = (editedData: SequenceEntryToEdit): Row[] =>
Object.entries(editedData.originalData.metadata).map(([key, value]) => ({
key,
initialValue: value.toString(),
value: value.toString(),
value,
initialValue: value,
...mapErrorsAndWarnings(editedData, key, 'Metadata'),
}));

Expand Down
22 changes: 10 additions & 12 deletions website/src/components/ReviewPage/ReviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '../../types/backend.ts';
import type { ClientConfig } from '../../types/runtimeConfig.ts';
import { createAuthorizationHeader } from '../../utils/createAuthorizationHeader.ts';
import { displayMetadataField } from '../../utils/displayMetadataField.ts';
import Edit from '~icons/bxs/edit';
import Trash from '~icons/bxs/trash';
import Send from '~icons/fa/send';
Expand Down Expand Up @@ -126,18 +127,15 @@ const isAnnotationPresent = (metadataField: string) => (item: ProcessingAnnotati
const MetadataList: FC<MetadataListProps> = ({ data, isLoading }) => (
<div className='flex flex-row flex-wrap'>
{!isLoading &&
Object.entries(data.processedData.metadata).map((entry, index) => {
const valueString = entry[1].toString();
return (
<KeyValueComponent
key={index}
keyName={entry[0]}
value={valueString}
warnings={data.warnings?.filter(isAnnotationPresent(entry[0]))}
errors={data.errors?.filter(isAnnotationPresent(entry[0]))}
/>
);
})}
Object.entries(data.processedData.metadata).map(([metadataName, value], index) => (
<KeyValueComponent
key={index}
keyName={metadataName}
value={displayMetadataField(value)}
warnings={data.warnings?.filter(isAnnotationPresent(metadataName))}
errors={data.errors?.filter(isAnnotationPresent(metadataName))}
/>
))}
</div>
);

Expand Down
9 changes: 6 additions & 3 deletions website/src/types/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const processingAnnotation = z.object({
});
export type ProcessingAnnotation = z.infer<typeof processingAnnotation>;

export const metadataField = z.union([z.string(), z.number(), z.date()]);
const unprocessedMetadataRecord = z.record(z.string());
export type UnprocessedMetadataRecord = z.infer<typeof unprocessedMetadataRecord>;

export const metadataField = z.union([z.string(), z.number(), z.date(), z.null()]);
export type MetadataField = z.infer<typeof metadataField>;

const metadataRecord = z.record(metadataField);
Expand Down Expand Up @@ -104,7 +107,7 @@ export type SubmissionIdMapping = z.infer<typeof submissionIdMapping>;
export const unprocessedData = accessionVersion.merge(
z.object({
data: z.object({
metadata: metadataRecord,
metadata: unprocessedMetadataRecord,
unalignedNucleotideSequences: z.record(z.string()),
}),
}),
Expand All @@ -117,7 +120,7 @@ export const sequenceEntryToEdit = accessionVersion.merge(
errors: z.array(processingAnnotation).nullable(),
warnings: z.array(processingAnnotation).nullable(),
originalData: z.object({
metadata: metadataRecord,
metadata: unprocessedMetadataRecord,
unalignedNucleotideSequences: z.record(z.string()),
}),
processedData: z.object({
Expand Down
3 changes: 3 additions & 0 deletions website/src/utils/displayMetadataField.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { MetadataField } from '../types/backend.ts';

export const displayMetadataField = (value: MetadataField) => (value === null ? 'null' : value.toString());
Loading