Skip to content

Commit

Permalink
feat(web): take title, description and update date from Auspice JSON
Browse files Browse the repository at this point in the history
When using Auspice JSON as an input dataset, if pathogen info is not present, let's also attempt to read `.meta.title` or `.meta.description` and use as a dataset name. And let's try to read `.meta.updated` as the updated date time of the dataset.

This allows for a prettier and more informative dataset info section when using Auspice JSON as an input dataset.
  • Loading branch information
ivan-aksamentov committed May 24, 2024
1 parent 82e69a1 commit 44fb8a5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/nextclade-web/src/components/Main/DatasetInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function DatasetInfo({ dataset, showSuggestions, ...restProps }: DatasetI
if (version?.tag === 'unreleased') {
updatedAt = `${updatedAt} (${t('unreleased')})`
}
return updatedAt
return updatedAt ?? t('unknown')
}, [t, version?.tag, version?.updatedAt])

const datasetName = attrStrMaybe(attributes, 'name') ?? path
Expand Down
8 changes: 7 additions & 1 deletion packages/nextclade-web/src/helpers/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { isEmpty } from 'lodash'
import { DateTime } from 'luxon'
import { notUndefinedOrNull } from 'src/helpers/notUndefined'

export function formatDateIsoUtcSimple(dateTimeStr: string) {
const utc = DateTime.fromISO(dateTimeStr, { zone: 'UTC' })

const date = utc.toISODate()

if (isEmpty(date)) {
return undefined
}

const time = utc.toISOTime({
suppressMilliseconds: true,
suppressSeconds: true,
includeOffset: false,
})

return [date, time, `(${utc.zoneName})`].join(' ')
return [date, time, `(${utc.zoneName})`].filter(notUndefinedOrNull).filter(isEmpty).join(' ')
}
22 changes: 21 additions & 1 deletion packages/nextclade-web/src/io/fetchSingleDatasetAuspice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@ export async function fetchSingleDatasetAuspice(datasetJsonUrl_: string) {
const auspiceJson = await axiosFetch<AuspiceTree>(datasetJsonUrl, {
headers: { Accept: 'application/json, text/plain, */*' },
})
const pathogen = auspiceJson.meta?.extensions?.nextclade?.pathogen
const pathogen = auspiceJson.meta.extensions?.nextclade?.pathogen

const name =
auspiceJson.meta.title ??
auspiceJson.meta.description ??
attrStrMaybe(pathogen?.attributes, 'name') ??
datasetJsonUrl

let version = pathogen?.version
if (!version) {
const updatedAt = pathogen?.version?.updatedAt ?? auspiceJson.meta.updated
version = {
tag: updatedAt ?? '',
updatedAt,
}
}

const currentDataset: Dataset & { auspiceJson?: AuspiceTree } = {
path: datasetJsonUrl,
Expand All @@ -17,6 +32,11 @@ export async function fetchSingleDatasetAuspice(datasetJsonUrl_: string) {
qc: [],
},
...pathogen,
attributes: {
name,
...pathogen?.attributes,
},
version,
auspiceJson,
}

Expand Down
9 changes: 9 additions & 0 deletions packages/nextclade/src/tree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ impl AuspiceGenomeAnnotations {

#[derive(Clone, Serialize, Deserialize, schemars::JsonSchema, Validate, Debug)]
pub struct AuspiceTreeMeta {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub title: Option<String>,

#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,

#[serde(default, skip_serializing_if = "Option::is_none")]
pub updated: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub genome_annotations: Option<AuspiceGenomeAnnotations>,

Expand Down

0 comments on commit 44fb8a5

Please sign in to comment.