Skip to content

Commit 6278e53

Browse files
authored
Merge pull request #3226 from OpenNeuroOrg/3225-file-viewer-load-fix
fix(app): Prevent loading files for viewers with built in data transfer
2 parents ae8103c + e78f2a5 commit 6278e53

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { isNifti, isNwb } from "../file-types"
2+
3+
describe("isNifti()", () => {
4+
it("detects nifti files", () => {
5+
expect(isNifti("sub-01/anat/sub-01_T1w.nii.gz")).toBeTruthy()
6+
expect(isNifti("dataset_description.json")).toBeFalsy()
7+
})
8+
})
9+
describe("isNwb()", () => {
10+
it("detects nwb/edf files", () => {
11+
expect(isNwb("eeg/sub-5_task-oa_eeg.edf")).toBeTruthy()
12+
expect(isNwb("eeg/sub-cbm009_task-protmap_eeg.edf")).toBeTruthy()
13+
expect(isNwb("sub-01/anat/sub-01_T1w.nii.gz")).toBeFalsy()
14+
})
15+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function isNifti(path) {
2+
return path.endsWith(".nii.gz") ||
3+
path.endsWith(".nii") ||
4+
path.endsWith(".mgh") ||
5+
path.endsWith(".mgz")
6+
}
7+
8+
export function isNwb(path) {
9+
return path.endsWith(".edf") || path.endsWith(".nwb")
10+
}

packages/openneuro-app/src/scripts/dataset/files/file-view.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect, useState } from "react"
22
import { Loading } from "@openneuro/components/loading"
33
import FileViewerType from "./file-viewer-type.jsx"
4+
import { isNifti, isNwb } from "./file-types"
45

56
const FileView = ({ url, path }) => {
67
const [data, setData] = useState(new ArrayBuffer(0))
@@ -15,7 +16,12 @@ const FileView = ({ url, path }) => {
1516

1617
useEffect(() => {
1718
if (loading) {
18-
fetchUrl()
19+
// These viewers load their own data
20+
if (isNifti(path) || isNwb(path)) {
21+
setLoading(false)
22+
} else {
23+
fetchUrl()
24+
}
1925
}
2026
})
2127

packages/openneuro-app/src/scripts/dataset/files/file-viewer-type.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import FileViewerTsv from "./viewers/file-viewer-tsv.jsx"
77
import FileViewerCsv from "./viewers/file-viewer-csv.jsx"
88
import FileViewerHtml from "./viewers/file-viewer-html.jsx"
99
import { FileViewerNeurosift } from "./viewers/file-viewer-neurosift"
10+
import { isNifti } from "./file-types"
1011

1112
/**
1213
* Choose the right viewer for each file type
@@ -21,10 +22,7 @@ const FileViewerType = ({ path, url, data }) => {
2122
) {
2223
return <FileViewerText data={data} />
2324
} else if (
24-
path.endsWith(".nii.gz") ||
25-
path.endsWith(".nii") ||
26-
path.endsWith(".mgh") ||
27-
path.endsWith(".mgz")
25+
isNifti(path)
2826
) {
2927
return <FileViewerNifti imageUrl={url} />
3028
} else if (path.endsWith(".json")) {

0 commit comments

Comments
 (0)