Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): Prevent loading files for viewers with built in data transfer #3226

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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

Check warning on line 24 in packages/openneuro-app/src/scripts/dataset/files/file-view.jsx

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L19 - L24 were not covered by tests
}
})

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
Loading