Skip to content

Commit

Permalink
feat: Finish run page migration to V2 (#1577)
Browse files Browse the repository at this point in the history
* fix authors

* fix test
  • Loading branch information
bchu1 authored Feb 4, 2025
1 parent 8795234 commit 14d3439
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ it('should have icon if user is corresponding author', () => {
it('should use regular icon size', () => {
render(<AuthorLink author={pick(DEFAULT_AUTHOR, 'name')} />)

const text = screen.getByText(DEFAULT_AUTHOR.name)
const text = screen.getByText(DEFAULT_AUTHOR.name!)
expect(text).toHaveClass('text-xs')
})

it('should use large icon size', () => {
render(<AuthorLink author={pick(DEFAULT_AUTHOR, 'name')} large />)

const text = screen.getByText(DEFAULT_AUTHOR.name)
const text = screen.getByText(DEFAULT_AUTHOR.name!)
expect(text).toHaveClass('text-sm')
})
23 changes: 6 additions & 17 deletions frontend/packages/data-portal/app/components/AuthorLink/types.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
export type AuthorInfo =
| {
corresponding_author_status?: boolean | null
email?: string | null
name: string
orcid?: string | null
primary_author_status?: boolean | null
}
| AuthorInfoV2
import { DeepPartial } from 'utility-types'

export type AuthorInfoV2 = {
correspondingAuthorStatus?: boolean | null
email?: string | null
name: string
orcid?: string | null
primaryAuthorStatus?: boolean | null
}
import { Dataset_Authors } from 'app/__generated__/graphql'
import { Author } from 'app/types/gql/genericTypes'

export type AuthorInfo = DeepPartial<Dataset_Authors> | Author

// TODO(kira-api-migration): Delete this when everything migrated.
export function convertToAuthorInfoV2(author: AuthorInfo): AuthorInfoV2 {
export function convertToAuthorInfoV2(author: AuthorInfo): Author {
return 'corresponding_author_status' in author ||
'primary_author_status' in author
? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { render, screen } from '@testing-library/react'

import { AuthorInfoV2, MockAuthorLink } from 'app/components/AuthorLink'
import { MockAuthorLink } from 'app/components/AuthorLink'
import { AuthorInfoType } from 'app/types/authorInfo'

import { AuthorList } from './AuthorList'

const DEFAULT_AUTHORS: AuthorInfoV2[] = [
const DEFAULT_AUTHORS: AuthorInfoType[] = [
{ name: 'Foo', correspondingAuthorStatus: true },
{ name: 'Bar' },
{ name: 'Foo Bar', primaryAuthorStatus: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import {
} from 'app/components/AuthorLink'
import { cns } from 'app/utils/cns'

function getAuthorKey(author: AuthorInfo) {
return author.name + author.email
function getAuthorKey(author: AuthorInfo): string {
return `${author.name}-${author.email}`
}

const SEPARATOR = `, `

function getAuthorIds(authors: AuthorInfo[]) {
return authors.map((author) => author.name + author.email + author.orcid)
return authors.map(
(author) => `${author.name} - ${author.email} - ${author.orcid}`,
)
}

export function AuthorList({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { isString } from 'lodash-es'

import { AccordionMetadataTable } from 'app/components/AccordionMetadataTable'
import { AuthorLegend } from 'app/components/AuthorLegend'
import { AuthorInfo } from 'app/components/AuthorLink'
import { AuthorList } from 'app/components/AuthorList'
import { DatabaseEntryList } from 'app/components/DatabaseEntry'
import { Link } from 'app/components/Link'
Expand All @@ -27,8 +26,10 @@ export function DatasetMetadataTable({
const { t } = useI18n()
const isV2 = isV2Dataset(dataset)

const numAuthors =
(isV2 ? dataset.authors?.edges?.length : dataset.authors?.length) ?? 0
const authors =
(isV2
? dataset.authors?.edges?.map((author) => author.node).filter(isDefined)
: dataset.authors) ?? []

const datasetMetadata = getTableData(
!!showAllFields && {
Expand Down Expand Up @@ -91,10 +92,10 @@ export function DatasetMetadataTable({
},

!!showAllFields && {
label: numAuthors === 1 ? t('author') : t('authors'),
label: authors.length === 1 ? t('author') : t('authors'),
labelExtra: <AuthorLegend inline />,
renderValue: () => {
return <AuthorList authors={dataset.authors as AuthorInfo[]} large />
return <AuthorList authors={authors} large />
},
values: [],
className: 'leading-sds-body-s',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export function AnnotationTable() {
sdsStyle="minimal"
onClick={() => {
openAnnotationDownloadModal({
datasetId: run.dataset.id,
datasetId: run.dataset?.id,
runId: run.id,
annotationId: annotationShape.annotation?.id,
referenceTomogramId: tomograms.find(
Expand Down Expand Up @@ -387,7 +387,7 @@ export function AnnotationTable() {
t,
openAnnotationDrawer,
openAnnotationDownloadModal,
run.dataset.id,
run.dataset?.id,
run.id,
tomograms,
])
Expand Down
45 changes: 23 additions & 22 deletions frontend/packages/data-portal/app/components/Run/RunHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export function RunHeader() {
const { toggleDrawer } = useMetadataDrawer()
const { t } = useI18n()

const tiltSeries = run.tiltseries[0]

const tomogram = run.tomogram_voxel_spacings.at(0)?.tomograms.at(0)
const tiltSeries = run.tiltseries.edges[0]?.node

// Use author submitted tomogram if available, otherwise default to the first one
const tomogramV2 =
Expand All @@ -50,8 +48,8 @@ export function RunHeader() {

const { openRunDownloadModal } = useDownloadModalQueryParamState()

const framesCount = run.tiltseries_aggregate.aggregate?.sum?.frames_count ?? 0
const tiltSeriesCount = run.tiltseries_aggregate.aggregate?.count ?? 0
const framesCount = run.framesAggregate?.aggregate?.[0]?.count ?? 0
const tiltSeriesCount = run.tiltseriesAggregate?.aggregate?.[0]?.count ?? 0
const annotationsCount = annotationFilesAggregates.totalCount

return (
Expand All @@ -68,10 +66,10 @@ export function RunHeader() {
}}
tooltipPlacement="bottom"
event={{
datasetId: run.dataset.id,
organism: run.dataset.organism_name ?? 'None',
datasetId: run.dataset?.id ?? 0,
organism: run.dataset?.organismName ?? 'None',
runId: run.id,
tomogramId: tomogram?.id ?? 'None',
tomogramId: tomogramV2?.id?.toString() ?? 'None',
type: 'run',
}}
/>
Expand All @@ -82,7 +80,7 @@ export function RunHeader() {
sdsStyle="rounded"
onClick={() =>
openRunDownloadModal({
datasetId: run.dataset.id,
datasetId: run.dataset?.id,
runId: run.id,
})
}
Expand All @@ -91,11 +89,11 @@ export function RunHeader() {
</Button>
</div>
}
releaseDate={run.dataset.release_date}
lastModifiedDate={
run.dataset.last_modified_date ?? run.dataset.deposition_date
releaseDate={run.dataset?.releaseDate.split('T')[0]}
lastModifiedDate={run.dataset?.lastModifiedDate.split('T')[0]}
breadcrumbs={
run.dataset != null && <Breadcrumbs variant="run" data={run.dataset} />
}
breadcrumbs={<Breadcrumbs variant="run" data={run.dataset} />}
metadata={[{ key: t('runId'), value: `${IdPrefix.Run}-${run.id}` }]}
onMoreInfoClick={() => toggleDrawer(MetadataDrawerId.Run)}
title={run.name}
Expand Down Expand Up @@ -164,8 +162,8 @@ export function RunHeader() {
// hack to align with score badge
labelExtra: <span className="mt-sds-xxxs h-[18px]" />,
values:
typeof tiltSeries?.tilt_series_quality === 'number'
? [String(tiltSeries.tilt_series_quality)]
tiltSeries?.tiltSeriesQuality !== undefined
? [String(tiltSeries.tiltSeriesQuality)]
: [],
renderValue: (value) => (
<TiltSeriesQualityScoreBadge score={+value} />
Expand All @@ -174,22 +172,25 @@ export function RunHeader() {
{
label: t('tiltRange'),
values:
typeof tiltSeries?.tilt_min === 'number' &&
typeof tiltSeries?.tilt_max === 'number'
tiltSeries?.tiltRange !== undefined &&
tiltSeries.tiltMin !== undefined &&
tiltSeries.tiltMax !== undefined
? [
getTiltRangeLabel(
t,
tiltSeries.tilt_min,
tiltSeries.tilt_max,
tiltSeries.tiltRange,
tiltSeries.tiltMin,
tiltSeries.tiltMax,
),
]
: [],
},
{
label: i18n.tiltScheme,
values: tiltSeries?.tilting_scheme
? [tiltSeries.tilting_scheme]
: [],
values:
tiltSeries?.tiltingScheme !== undefined
? [tiltSeries.tiltingScheme]
: [],
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ export function RunMetadataDrawer() {
label={i18n.runDetails}
idInfo={{ label: 'runId', text: `${IdPrefix.Run}-${run.id}` }}
>
<DatasetMetadataTable
showAllFields
dataset={run.dataset}
initialOpen={false}
/>
<SampleAndExperimentConditionsTable
dataset={run.dataset}
initialOpen={false}
/>
{run.dataset != null && (
<>
<DatasetMetadataTable
showAllFields
dataset={run.dataset}
initialOpen={false}
/>
<SampleAndExperimentConditionsTable
dataset={run.dataset}
initialOpen={false}
/>
</>
)}
<RunTiltSeriesTable />
<TomogramsSummarySection />
</MetadataDrawer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function RunTiltSeriesTable() {

return (
<TiltSeriesTable
tiltSeriesData={run.tiltseries[0]}
tiltSeriesData={run.tiltseries.edges[0]?.node}
fields={SELECT_FIELDS}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function TomogramMetadataDrawer() {
},
{
label: t('publications'),
values: [run.dataset.dataset_publications ?? ''],
values: [run.dataset?.datasetPublications ?? ''],
renderValue: (value: string) => (
<DatabaseEntryList entries={value} />
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ export function TomogramsTable() {
}}
tooltipPlacement="top"
event={{
datasetId: run.dataset.id,
organism: run.dataset.organism_name ?? 'None',
datasetId: run.dataset?.id ?? 0,
organism: run.dataset?.organismName ?? 'None',
runId: run.id,
tomogramId: original.id,
type: 'tomogram',
Expand All @@ -226,7 +226,7 @@ export function TomogramsTable() {
onClick={() => {
openTomogramDownloadModal({
tomogramId: original.id,
datasetId: run.dataset.id,
datasetId: run.dataset?.id,
runId: run.id,
})
}}
Expand All @@ -243,8 +243,8 @@ export function TomogramsTable() {
] as ColumnDef<TomogramV2>[] // https://github.com/TanStack/table/issues/4382
}, [
run.id,
run.dataset.id,
run.dataset.organism_name,
run.dataset?.id,
run.dataset?.organismName,
openMetadataDrawer,
openTomogramDownloadModal,
t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function useTiltSeriesValueMappings(
const tiltAxis = isV2 ? tiltSeries.tiltAxis : tiltSeries?.tilt_axis
const tiltMin = isV2 ? tiltSeries.tiltMin : tiltSeries?.tilt_min
const tiltMax = isV2 ? tiltSeries.tiltMax : tiltSeries?.tilt_max
const tiltRange = isV2 ? tiltSeries.tiltRange : tiltMax! - tiltMin!
const tiltStep = isV2 ? tiltSeries.tiltStep : tiltSeries?.tilt_step

return useMemo<Record<TiltSeriesKeys, TableData>>(
Expand Down Expand Up @@ -201,8 +202,10 @@ export function useTiltSeriesValueMappings(
[TiltSeriesKeys.TiltRange]: {
label: t('tiltRange'),
values: [
tiltMin !== undefined && tiltMax !== undefined
? getTiltRangeLabel(t, tiltMin, tiltMax)
tiltMin !== undefined &&
tiltMax !== undefined &&
tiltRange !== undefined
? getTiltRangeLabel(t, tiltRange, tiltMin, tiltMax)
: '--',
],
},
Expand Down Expand Up @@ -237,6 +240,7 @@ export function useTiltSeriesValueMappings(
tiltAxis,
tiltMax,
tiltMin,
tiltRange,
tiltStep,
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface DownloadModalContextValue {
runName?: string
s3Path?: string
tomogramId?: number
tomogramVoxelId?: number
type: DownloadModalType
}

Expand Down
6 changes: 2 additions & 4 deletions frontend/packages/data-portal/app/hooks/useRunById.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { useTypedLoaderData } from 'remix-typedjson'

import { GetRunByIdQuery } from 'app/__generated__/graphql'
import { GetRunByIdV2Query } from 'app/__generated_v2__/graphql'
import { isDefined } from 'app/utils/nullish'

export function useRunById() {
const { v1, v2 } = useTypedLoaderData<{
v1: GetRunByIdQuery
const { v2 } = useTypedLoaderData<{
v2: GetRunByIdV2Query
}>()

const run = v1.runs[0]
const run = v2.runs[0]

const { tomograms, annotationShapes } = v2

Expand Down
Loading

0 comments on commit 14d3439

Please sign in to comment.