@openneuro/app 4.21.0 → 4.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/scripts/components/__tests__/__snapshots__/date-distance.spec.tsx.snap +7 -0
- package/src/scripts/components/__tests__/date-distance.spec.tsx +19 -0
- package/src/scripts/components/date-distance.tsx +10 -0
- package/src/scripts/dataset/__tests__/snapshot-container.spec.tsx +7 -0
- package/src/scripts/dataset/components/VersionList.tsx +4 -5
- package/src/scripts/dataset/draft-container.tsx +5 -16
- package/src/scripts/dataset/snapshot-container.tsx +5 -18
- package/src/scripts/pages/front-page/front-page.tsx +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openneuro/app",
|
|
3
|
-
"version": "4.21.
|
|
3
|
+
"version": "4.21.2",
|
|
4
4
|
"description": "React JS web frontend for the OpenNeuro platform.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "public/client.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@emotion/react": "11.11.1",
|
|
21
21
|
"@emotion/styled": "11.11.0",
|
|
22
22
|
"@niivue/niivue": "0.34.0",
|
|
23
|
-
"@openneuro/client": "^4.21.
|
|
24
|
-
"@openneuro/components": "^4.21.
|
|
23
|
+
"@openneuro/client": "^4.21.2",
|
|
24
|
+
"@openneuro/components": "^4.21.2",
|
|
25
25
|
"@tanstack/react-table": "^8.9.3",
|
|
26
26
|
"bids-validator": "1.13.0",
|
|
27
27
|
"bytes": "^3.0.0",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "5607a295f9130a0e51bffdaf8d3d6235c8eab8f8"
|
|
74
74
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { vi } from "vitest"
|
|
3
|
+
import { render } from "@testing-library/react"
|
|
4
|
+
import { DateDistance } from "../date-distance"
|
|
5
|
+
|
|
6
|
+
describe("DataTable component", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.useFakeTimers()
|
|
9
|
+
vi.setSystemTime(new Date(2024, 1, 4))
|
|
10
|
+
})
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.useRealTimers()
|
|
13
|
+
})
|
|
14
|
+
it("renders date distance components", () => {
|
|
15
|
+
const date = new Date(2022, 1, 4).toISOString()
|
|
16
|
+
const { asFragment } = render(<DateDistance date={date} />)
|
|
17
|
+
expect(asFragment()).toMatchSnapshot()
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import formatDistanceToNow from "date-fns/formatDistanceToNow"
|
|
3
|
+
import parseISO from "date-fns/parseISO"
|
|
4
|
+
import { formatDate } from "../utils/date"
|
|
5
|
+
|
|
6
|
+
export function DateDistance({ date }) {
|
|
7
|
+
const formattedDate = formatDate(date)
|
|
8
|
+
const distance = formatDistanceToNow(parseISO(date))
|
|
9
|
+
return <>{formattedDate} - {distance} ago</>
|
|
10
|
+
}
|
|
@@ -15,6 +15,13 @@ const defProps = {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
describe("SnapshotContainer component", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.useFakeTimers()
|
|
20
|
+
vi.setSystemTime(new Date("2023-12-01"))
|
|
21
|
+
})
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
vi.useRealTimers()
|
|
24
|
+
})
|
|
18
25
|
it("renders successfully", () => {
|
|
19
26
|
const { asFragment } = render(<SnapshotContainer {...defProps} />, {
|
|
20
27
|
wrapper: MockAppWrapper,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { Link } from "react-router-dom"
|
|
3
3
|
import { Dropdown } from "@openneuro/components/dropdown"
|
|
4
|
+
import { formatDate } from "../../utils/date"
|
|
4
5
|
|
|
5
6
|
export interface VersionListProps {
|
|
6
7
|
items: {
|
|
@@ -19,9 +20,6 @@ export interface VersionListProps {
|
|
|
19
20
|
dateModified: string
|
|
20
21
|
datasetId?: string
|
|
21
22
|
}
|
|
22
|
-
const formatDate = (dateObject) =>
|
|
23
|
-
new Date(dateObject).toISOString().split("T")[0]
|
|
24
|
-
|
|
25
23
|
export const VersionList = ({
|
|
26
24
|
items,
|
|
27
25
|
selected,
|
|
@@ -41,7 +39,8 @@ export const VersionList = ({
|
|
|
41
39
|
<>
|
|
42
40
|
<div className="active-version">
|
|
43
41
|
<div>{selected === "draft" ? "Draft" : selected}</div>
|
|
44
|
-
{selected === "draft" ? "Updated" : "Created"}:
|
|
42
|
+
{selected === "draft" ? "Updated" : "Created"}:{" "}
|
|
43
|
+
{formatDate(dateModified)}
|
|
45
44
|
</div>
|
|
46
45
|
{items.length
|
|
47
46
|
? (
|
|
@@ -68,7 +67,7 @@ export const VersionList = ({
|
|
|
68
67
|
{selected === "draft" ? "*" : ""}
|
|
69
68
|
</span>
|
|
70
69
|
</span>
|
|
71
|
-
{dateModified}
|
|
70
|
+
{formatDate(dateModified)}
|
|
72
71
|
</Link>
|
|
73
72
|
</li>
|
|
74
73
|
{items.map((item, index) => (
|
|
@@ -3,8 +3,6 @@ import Markdown from "markdown-to-jsx"
|
|
|
3
3
|
import Helmet from "react-helmet"
|
|
4
4
|
import { Navigate, useLocation } from "react-router-dom"
|
|
5
5
|
import pluralize from "pluralize"
|
|
6
|
-
import formatDistanceToNow from "date-fns/formatDistanceToNow"
|
|
7
|
-
import parseISO from "date-fns/parseISO"
|
|
8
6
|
import { pageTitle } from "../resources/strings.js"
|
|
9
7
|
|
|
10
8
|
import { DatasetPageTabContainer } from "./routes/styles/dataset-page-tab-container"
|
|
@@ -37,15 +35,13 @@ import { DOILink } from "./fragments/doi-link"
|
|
|
37
35
|
|
|
38
36
|
import { TabRoutesDraft } from "./routes/tab-routes-draft"
|
|
39
37
|
import { FollowToggles } from "./common/follow-toggles"
|
|
38
|
+
import { DateDistance } from "../components/date-distance"
|
|
40
39
|
|
|
41
40
|
export interface DraftContainerProps {
|
|
42
41
|
dataset
|
|
43
42
|
tag?: string
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
const formatDate = (dateObject) =>
|
|
47
|
-
new Date(dateObject).toISOString().split("T")[0]
|
|
48
|
-
|
|
49
45
|
// Helper function for getting version from URL
|
|
50
46
|
const snapshotVersion = (location) => {
|
|
51
47
|
const matches = location.pathname.match(/versions\/(.*?)(\/|$)/)
|
|
@@ -65,13 +61,6 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
|
|
|
65
61
|
? summary.sessions.length
|
|
66
62
|
: 1
|
|
67
63
|
|
|
68
|
-
const dateAdded = formatDate(dataset.created)
|
|
69
|
-
const dateAddedDifference = formatDistanceToNow(parseISO(dataset.created))
|
|
70
|
-
const dateModified = formatDate(dataset.draft.modified)
|
|
71
|
-
const dateUpdatedDifference = formatDistanceToNow(
|
|
72
|
-
parseISO(dataset.draft.modified),
|
|
73
|
-
)
|
|
74
|
-
|
|
75
64
|
const [cookies] = useCookies()
|
|
76
65
|
const profile = getUnexpiredProfile(cookies)
|
|
77
66
|
const isAdmin = profile?.admin
|
|
@@ -213,7 +202,7 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
|
|
|
213
202
|
items={dataset.snapshots}
|
|
214
203
|
className="version-dropdown"
|
|
215
204
|
activeDataset={activeDataset}
|
|
216
|
-
dateModified={
|
|
205
|
+
dateModified={dataset.draft.modified}
|
|
217
206
|
selected={selectedVersion}
|
|
218
207
|
setSelected={setSelectedVersion}
|
|
219
208
|
/>
|
|
@@ -278,8 +267,8 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
|
|
|
278
267
|
heading="Uploaded by"
|
|
279
268
|
item={
|
|
280
269
|
<>
|
|
281
|
-
<Username user={dataset.uploader} /> on
|
|
282
|
-
{
|
|
270
|
+
<Username user={dataset.uploader} /> on{" "}
|
|
271
|
+
<DateDistance date={dataset.created} />
|
|
283
272
|
</>
|
|
284
273
|
}
|
|
285
274
|
/>
|
|
@@ -289,7 +278,7 @@ const DraftContainer: React.FC<DraftContainerProps> = ({ dataset }) => {
|
|
|
289
278
|
heading="Last Updated"
|
|
290
279
|
item={
|
|
291
280
|
<>
|
|
292
|
-
|
|
281
|
+
<DateDistance date={dataset.draft.modified} />
|
|
293
282
|
</>
|
|
294
283
|
}
|
|
295
284
|
/>
|
|
@@ -5,8 +5,6 @@ import { DatasetPageTabContainer } from "./routes/styles/dataset-page-tab-contai
|
|
|
5
5
|
import DatasetQueryContext from "../datalad/dataset/dataset-query-context.js"
|
|
6
6
|
import { Link, useLocation, useParams } from "react-router-dom"
|
|
7
7
|
import pluralize from "pluralize"
|
|
8
|
-
import formatDistanceToNow from "date-fns/formatDistanceToNow"
|
|
9
|
-
import parseISO from "date-fns/parseISO"
|
|
10
8
|
import { pageTitle } from "../resources/strings.js"
|
|
11
9
|
import Validation from "../validation/validation.jsx"
|
|
12
10
|
import { config } from "../config"
|
|
@@ -41,9 +39,7 @@ import { DOILink } from "./fragments/doi-link"
|
|
|
41
39
|
import { TabRoutesSnapshot } from "./routes/tab-routes-snapshot"
|
|
42
40
|
import schemaGenerator from "../utils/json-ld.js"
|
|
43
41
|
import { FollowToggles } from "./common/follow-toggles"
|
|
44
|
-
|
|
45
|
-
const formatDate = (dateObject) =>
|
|
46
|
-
new Date(dateObject).toISOString().split("T")[0]
|
|
42
|
+
import { DateDistance } from "../components/date-distance"
|
|
47
43
|
|
|
48
44
|
// Helper function for getting version from URL
|
|
49
45
|
const snapshotVersion = (location) => {
|
|
@@ -75,11 +71,6 @@ export const SnapshotContainer: React.FC<SnapshotContainerProps> = ({
|
|
|
75
71
|
? summary.sessions.length
|
|
76
72
|
: 1
|
|
77
73
|
|
|
78
|
-
const dateAdded = formatDate(dataset.created)
|
|
79
|
-
const dateAddedDifference = formatDistanceToNow(parseISO(dataset.created))
|
|
80
|
-
const dateModified = formatDate(snapshot.created)
|
|
81
|
-
const dateUpdatedDifference = formatDistanceToNow(parseISO(snapshot.created))
|
|
82
|
-
|
|
83
74
|
const [cookies] = useCookies()
|
|
84
75
|
const profile = getUnexpiredProfile(cookies)
|
|
85
76
|
const isAdmin = profile?.admin
|
|
@@ -209,7 +200,7 @@ export const SnapshotContainer: React.FC<SnapshotContainerProps> = ({
|
|
|
209
200
|
items={dataset.snapshots}
|
|
210
201
|
className="version-dropdown"
|
|
211
202
|
activeDataset={activeDataset}
|
|
212
|
-
dateModified={
|
|
203
|
+
dateModified={snapshot.created}
|
|
213
204
|
selected={selectedVersion}
|
|
214
205
|
setSelected={setSelectedVersion}
|
|
215
206
|
/>
|
|
@@ -275,8 +266,8 @@ export const SnapshotContainer: React.FC<SnapshotContainerProps> = ({
|
|
|
275
266
|
heading="Uploaded by"
|
|
276
267
|
item={
|
|
277
268
|
<>
|
|
278
|
-
<Username user={dataset.uploader} /> on
|
|
279
|
-
{
|
|
269
|
+
<Username user={dataset.uploader} /> on{" "}
|
|
270
|
+
<DateDistance date={dataset.created} />
|
|
280
271
|
</>
|
|
281
272
|
}
|
|
282
273
|
/>
|
|
@@ -284,11 +275,7 @@ export const SnapshotContainer: React.FC<SnapshotContainerProps> = ({
|
|
|
284
275
|
{dataset.snapshots.length && (
|
|
285
276
|
<MetaDataBlock
|
|
286
277
|
heading="Last Updated"
|
|
287
|
-
item={
|
|
288
|
-
<>
|
|
289
|
-
{dateModified} - {dateUpdatedDifference} ago
|
|
290
|
-
</>
|
|
291
|
-
}
|
|
278
|
+
item={<DateDistance date={snapshot.created} />}
|
|
292
279
|
/>
|
|
293
280
|
)}
|
|
294
281
|
<MetaDataBlock heading="Sessions" item={numSessions} />
|
|
@@ -110,7 +110,9 @@ export const FrontPageTopQuery = ({ query }) => {
|
|
|
110
110
|
</>
|
|
111
111
|
)
|
|
112
112
|
} else if (result.error || result.data.datasets == null) {
|
|
113
|
-
|
|
113
|
+
if (result?.error) {
|
|
114
|
+
apm.captureError(result?.error)
|
|
115
|
+
}
|
|
114
116
|
return <div>Failed to load top datasets, please try again later.</div>
|
|
115
117
|
} else {
|
|
116
118
|
// Remove any edges which could not be loaded
|
|
@@ -138,7 +140,9 @@ export const FrontPageNewQuery = ({ query }) => {
|
|
|
138
140
|
if (result.loading) {
|
|
139
141
|
return <Loading />
|
|
140
142
|
} else if (result.error || result.data.datasets == null) {
|
|
141
|
-
|
|
143
|
+
if (result?.error) {
|
|
144
|
+
apm.captureError(result?.error)
|
|
145
|
+
}
|
|
142
146
|
return <div>Failed to load top datasets, please try again later.</div>
|
|
143
147
|
} else {
|
|
144
148
|
// Remove any edges which could not be loaded
|