Skip to content

Commit

Permalink
Merge pull request #3226 from OpenNeuroOrg/3225-file-viewer-load-fix
Browse files Browse the repository at this point in the history
fix(app): Prevent loading files for viewers with built in data transfer
  • Loading branch information
nellh authored Nov 19, 2024
2 parents ae8103c + e78f2a5 commit 6278e53
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isNifti, isNwb } from "../file-types"

describe("isNifti()", () => {
it("detects nifti files", () => {
expect(isNifti("sub-01/anat/sub-01_T1w.nii.gz")).toBeTruthy()
expect(isNifti("dataset_description.json")).toBeFalsy()
})
})
describe("isNwb()", () => {
it("detects nwb/edf files", () => {
expect(isNwb("eeg/sub-5_task-oa_eeg.edf")).toBeTruthy()
expect(isNwb("eeg/sub-cbm009_task-protmap_eeg.edf")).toBeTruthy()
expect(isNwb("sub-01/anat/sub-01_T1w.nii.gz")).toBeFalsy()
})
})
10 changes: 10 additions & 0 deletions packages/openneuro-app/src/scripts/dataset/files/file-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function isNifti(path) {
return path.endsWith(".nii.gz") ||
path.endsWith(".nii") ||
path.endsWith(".mgh") ||
path.endsWith(".mgz")
}

export function isNwb(path) {
return path.endsWith(".edf") || path.endsWith(".nwb")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from "react"
import { Loading } from "@openneuro/components/loading"
import FileViewerType from "./file-viewer-type.jsx"
import { isNifti, isNwb } from "./file-types"

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

useEffect(() => {
if (loading) {
fetchUrl()
// These viewers load their own data
if (isNifti(path) || isNwb(path)) {
setLoading(false)
} else {
fetchUrl()
}
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FileViewerTsv from "./viewers/file-viewer-tsv.jsx"
import FileViewerCsv from "./viewers/file-viewer-csv.jsx"
import FileViewerHtml from "./viewers/file-viewer-html.jsx"
import { FileViewerNeurosift } from "./viewers/file-viewer-neurosift"
import { isNifti } from "./file-types"

/**
* Choose the right viewer for each file type
Expand All @@ -21,10 +22,7 @@ const FileViewerType = ({ path, url, data }) => {
) {
return <FileViewerText data={data} />
} else if (
path.endsWith(".nii.gz") ||
path.endsWith(".nii") ||
path.endsWith(".mgh") ||
path.endsWith(".mgz")
isNifti(path)
) {
return <FileViewerNifti imageUrl={url} />
} else if (path.endsWith(".json")) {
Expand Down

0 comments on commit 6278e53

Please sign in to comment.