Skip to content

Commit c11f986

Browse files
authored
Merge pull request #3516 from OpenNeuroOrg/issue/3511
adds modalityHEX and Dataset Citation to the my datasets - dataset cards
2 parents 998a4fa + fecf3a5 commit c11f986

File tree

13 files changed

+337
-206
lines changed

13 files changed

+337
-206
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export function authorsCitationList(authors: string[], limit?: number): string {
2+
let formattedAuthors = "NO AUTHORS FOUND"
3+
if (authors && authors.length > 0) {
4+
if (!limit || authors.length <= limit) {
5+
// Pre-Limit
6+
// Join with commas, with "and" before the last author
7+
if (authors.length === 1) {
8+
formattedAuthors = authors[0]
9+
} else if (authors.length === 2) {
10+
formattedAuthors = `${authors[0]} and ${authors[1]}`
11+
} else {
12+
const lastAuthor = authors[authors.length - 1]
13+
const remainingAuthors = authors.slice(0, authors.length - 1)
14+
formattedAuthors = `${remainingAuthors.join(", ")}, and ${lastAuthor}`
15+
}
16+
} else {
17+
// Limit to `limit` authors and add "et al."
18+
const limitedAuthors = authors.slice(0, limit)
19+
formattedAuthors = `${limitedAuthors.join(", ")}, et al.`
20+
}
21+
}
22+
return formattedAuthors
23+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react"
2+
import { parseISO } from "date-fns"
3+
import getYear from "date-fns/getYear"
4+
import type { Dataset } from "../../types/user-types"
5+
import { authorsCitationList } from "./authors-citation-list"
6+
7+
interface SearchResultsCitationProps {
8+
dataset: Dataset
9+
}
10+
11+
export const SearchResultsCitation: React.FC<SearchResultsCitationProps> = ({
12+
dataset,
13+
}) => {
14+
const rawAuthors = dataset.latestSnapshot?.description?.Authors
15+
const year = dataset.created ? getYear(parseISO(dataset.created)) : "N/A"
16+
const datasetName = dataset.latestSnapshot?.description?.Name ||
17+
"NO DATASET NAME FOUND"
18+
const datasetDOI = dataset.latestSnapshot?.description?.DatasetDOI
19+
20+
const datasetCite = `${
21+
authorsCitationList(rawAuthors, 4)
22+
} (${year}). ${datasetName}. OpenNeuro. [Dataset] doi: ${
23+
datasetDOI ? `${datasetDOI}` : "N/A"
24+
}`
25+
26+
return (
27+
<cite>
28+
{datasetCite}
29+
</cite>
30+
)
31+
}
32+
33+
export default SearchResultsCitation

packages/openneuro-app/src/scripts/components/modality-cube/ModalityHexagon.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { modalityShortMapping } from "../../components/formatting/modality-label
44
import "./modality-hexagon.scss"
55
interface ModalityHexagonProps {
66
primaryModality: string | null | undefined
7+
size?: string
78
}
89

910
//ModalityHexagon component displays a colored hexagon and label
1011
// based on the provided primaryModality.
1112

1213
export const ModalityHexagon: FC<ModalityHexagonProps> = ({
1314
primaryModality,
15+
size,
1416
}) => {
1517
const hexagonClass = primaryModality
1618
? primaryModality.toLowerCase()
@@ -20,8 +22,10 @@ export const ModalityHexagon: FC<ModalityHexagonProps> = ({
2022
? modalityShortMapping(primaryModality)
2123
: <i className="fa fa-circle-o-notch fa-spin"></i>
2224

25+
const effectiveSizeClass = size || ""
26+
2327
return (
24-
<div className="hexagon-wrapper">
28+
<div className={`hexagon-wrapper ${effectiveSizeClass}`}>
2529
<div className={`hexagon ${hexagonClass}`}></div>
2630
<div className="label">{labelText}</div>
2731
</div>

packages/openneuro-app/src/scripts/components/modality-cube/modality-hexagon.scss

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,96 @@
4949
transform: rotateZ(-60deg);
5050
}
5151

52-
&.mri { background-color: $mri-theme; }
53-
&.eeg { background-color: $on-light-green; } // EEG uses on-light-green
54-
&.pet { background-color: $pet-theme; }
55-
&.ieeg { background-color: $ieeg-theme; }
56-
&.meg { background-color: $meg-theme; }
57-
&.nirs { background-color: $nirs-theme; }
52+
&.mri {
53+
background-color: $mri-theme;
54+
}
55+
&.eeg {
56+
background-color: $on-light-green;
57+
} // EEG uses on-light-green
58+
&.pet {
59+
background-color: $pet-theme;
60+
}
61+
&.ieeg {
62+
background-color: $ieeg-theme;
63+
}
64+
&.meg {
65+
background-color: $meg-theme;
66+
}
67+
&.nirs {
68+
background-color: $nirs-theme;
69+
}
70+
}
71+
&.small {
72+
margin-left: 10px;
73+
width: 28px;
74+
height: 28px;
75+
div.label {
76+
font-size: 10px;
77+
font-weight: normal;
78+
}
5879
}
5980
}
6081

82+
83+
6184
a {
6285
.hexagon-wrapper {
63-
margin: 20px auto;
86+
margin: 20px auto;
6487

6588
div.label {
66-
color: unset;
89+
color: unset;
6790
}
6891

6992
.hexagon {
70-
transition: color 0.3s;
71-
background-color: #fff;
93+
transition: color 0.3s;
94+
background-color: #fff;
7295

7396
// Modality specific colors (when inside 'a')
74-
&.mri { background-color: #fff; color: $mri-theme; }
75-
&.eeg { background-color: #fff; color: $eeg-theme; }
76-
&.pet { background-color: #fff; color: $pet-theme; }
77-
&.ieeg { background-color: #fff; color: $ieeg-theme; }
78-
&.meg { background-color: #fff; color: $meg-theme; }
79-
&.nirs { background-color: #fff; color: $nirs-theme; }
97+
&.mri {
98+
background-color: #fff;
99+
color: $mri-theme;
100+
}
101+
&.eeg {
102+
background-color: #fff;
103+
color: $eeg-theme;
104+
}
105+
&.pet {
106+
background-color: #fff;
107+
color: $pet-theme;
108+
}
109+
&.ieeg {
110+
background-color: #fff;
111+
color: $ieeg-theme;
112+
}
113+
&.meg {
114+
background-color: #fff;
115+
color: $meg-theme;
116+
}
117+
&.nirs {
118+
background-color: #fff;
119+
color: $nirs-theme;
120+
}
80121
}
81122

82123
&:hover {
83124
.hexagon {
84-
color: lighten($on-dark-aqua, 15%);
85-
&.mri { color: lighten($mri-theme, 10%); }
86-
&.eeg { color: lighten($eeg-theme, 10%); }
87-
&.pet { color: lighten($pet-theme, 10%); }
88-
&.ieeg { color: lighten($ieeg-theme, 10%); }
89-
&.meg { color: lighten($meg-theme, 10%); }
125+
color: lighten($on-dark-aqua, 15%);
126+
&.mri {
127+
color: lighten($mri-theme, 10%);
128+
}
129+
&.eeg {
130+
color: lighten($eeg-theme, 10%);
131+
}
132+
&.pet {
133+
color: lighten($pet-theme, 10%);
134+
}
135+
&.ieeg {
136+
color: lighten($ieeg-theme, 10%);
137+
}
138+
&.meg {
139+
color: lighten($meg-theme, 10%);
140+
}
90141
}
91142
}
92143
}
93-
}
144+
}

packages/openneuro-app/src/scripts/dataset/__tests__/__snapshots__/snapshot-container.spec.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ exports[`SnapshotContainer component > renders successfully 1`] = `
4949
href="/search/modality/MRI"
5050
>
5151
<div
52-
class="hexagon-wrapper"
52+
class="hexagon-wrapper "
5353
>
5454
<div
5555
class="hexagon mri"
@@ -1042,7 +1042,7 @@ OCI-1131441 (R. Poldrack, PI) in any publications.
10421042
<h5
10431043
class="cite-content-block"
10441044
>
1045-
J. Doe and J. Doe and J. Doe (2021). DS003-downsampled (only T1). OpenNeuro. [Dataset] doi: null
1045+
J. Doe, J. Doe, and J. Doe (2021). DS003-downsampled (only T1). OpenNeuro. [Dataset] doi: null
10461046
</h5>
10471047
</div>
10481048
<h5>

packages/openneuro-app/src/scripts/dataset/fragments/__tests__/dataset-citation.spec.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("formatCitation", () => {
1818
})
1919
it('should work with "BibTeX" input', () => {
2020
expect(formatCitation(snapshot, "BibTeX")).toEqual(`@dataset{ds999999:1.0.2,
21-
author = {Jane Doe and Doe, John},
21+
author = {Jane Doe AND Doe, John},
2222
title = {"A Test Dataset"},
2323
year = {2020},
2424
doi = {doinumbersgohere},

packages/openneuro-app/src/scripts/dataset/fragments/dataset-citation.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import parseISO from "date-fns/parseISO"
55
import { CopyToClipboard } from "react-copy-to-clipboard"
66
import { Button } from "../../components/button/Button"
77
import { Tooltip } from "../../components/tooltip/Tooltip"
8+
import { authorsCitationList } from "../../components/citation/authors-citation-list"
89

910
export const formatCitation = (snapshot, style) => {
1011
const year = getYear(parseISO(snapshot.created))
1112
const authors = snapshot.description.Authors
12-
? snapshot.description.Authors.join(" and ")
13-
: "NO AUTHORS FOUND"
13+
? authorsCitationList(snapshot.description.Authors)
14+
: ""
1415
if (style === "Text") {
1516
return `${authors} (${year}). ${snapshot.description.Name}. OpenNeuro. [Dataset] doi: ${snapshot.description.DatasetDOI}`
1617
} else if (style === "BibTeX") {
1718
return `@dataset{${snapshot.id},
18-
author = {${authors}},
19+
author = {${snapshot.description.Authors.join(" AND ")}},
1920
title = {"${snapshot.description.Name}"},
2021
year = {${year}},
2122
doi = {${snapshot.description.DatasetDOI}},

packages/openneuro-app/src/scripts/queries/user.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const ADVANCED_SEARCH_DATASETS_QUERY = gql`
117117
TracerName
118118
TracerRadionuclide
119119
}
120+
primaryModality
120121
}
121122
issues {
122123
severity
@@ -128,6 +129,7 @@ export const ADVANCED_SEARCH_DATASETS_QUERY = gql`
128129
description {
129130
Name
130131
Authors
132+
DatasetDOI
131133
}
132134
}
133135
analytics {

packages/openneuro-app/src/scripts/search/components/SearchResultItem.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import React from "react"
2-
import getYear from "date-fns/getYear"
3-
import parseISO from "date-fns/parseISO"
42
import { Link } from "react-router-dom"
53
import { Tooltip } from "../../components/tooltip/Tooltip"
64
import { Icon } from "../../components/icon/Icon"
@@ -11,6 +9,7 @@ import "../scss/search-result.scss"
119
import activityPulseIcon from "../../../assets/activity-icon.png"
1210
import { hasEditPermissions } from "../../authentication/profile"
1311
import { ModalityHexagon } from "../../components/modality-cube/ModalityHexagon"
12+
import { SearchResultsCitation } from "../../components/citation/search-results-citation"
1413

1514
export const formatDate = (dateObject) =>
1615
new Date(dateObject).toISOString().split("T")[0]
@@ -19,6 +18,7 @@ export interface SearchResultItemProps {
1918
node: {
2019
id: string
2120
created: string
21+
name: string
2222
uploader: {
2323
id: string
2424
name: string
@@ -243,12 +243,6 @@ export const SearchResultItem = ({
243243
</div>
244244
)
245245

246-
const year = getYear(parseISO(node.created))
247-
const authors = node.latestSnapshot.description?.Authors
248-
? node.latestSnapshot.description.Authors.join(" and ")
249-
: "NO AUTHORS FOUND"
250-
const datasetCite =
251-
`${authors} (${year}). ${node.latestSnapshot.description.Name}. OpenNeuro. [Dataset] doi: ${node.latestSnapshot.description.DatasetDOI}`
252246
const trimlength = 450
253247

254248
return (
@@ -270,7 +264,7 @@ export const SearchResultItem = ({
270264
: node.latestSnapshot.readme)
271265
: ""}
272266
</p>
273-
<cite>{datasetCite}</cite>
267+
<SearchResultsCitation dataset={node} />
274268
</div>
275269
</div>
276270

packages/openneuro-app/src/scripts/types/user-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export interface Dataset {
4848
created?: string
4949
description?: {
5050
Authors: string[]
51+
DatasetDOI?: string | null
52+
Name: string
53+
}
54+
summary?: {
55+
primaryModality?: string
5156
}
5257
}
5358
draft?: {

0 commit comments

Comments
 (0)