From 04c7bbb2fb47d4eb4487179e4e129b24bb63f38b Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Tue, 24 Sep 2024 21:53:20 +0200 Subject: [PATCH] fix rendering failure for datasets that have not undergone in-depth curation. --- .../__tests__/components/DatasetCard.test.jsx | 84 ++++++++++++++++++- apps/nar-v3/src/components/DataFileCard.jsx | 5 +- apps/nar-v3/src/components/DatasetCard.jsx | 11 ++- apps/nar-v3/src/components/RecordingCard.jsx | 5 +- 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/apps/nar-v3/__tests__/components/DatasetCard.test.jsx b/apps/nar-v3/__tests__/components/DatasetCard.test.jsx index 71763a3..5db529e 100644 --- a/apps/nar-v3/__tests__/components/DatasetCard.test.jsx +++ b/apps/nar-v3/__tests__/components/DatasetCard.test.jsx @@ -5,7 +5,7 @@ import "@testing-library/jest-dom"; import DatasetCard from "../../src/components/DatasetCard"; describe("DatasetCard component", () => { - test("should render without errors", async () => { + test("should render a detailed dataset without errors", async () => { const dataset = { "@context": { "@vocab": "https://schema.hbp.eu/myQuery/", @@ -587,4 +587,86 @@ describe("DatasetCard component", () => { expect(screen.getByText(/An example patch clamp dataset/i)).toBeInTheDocument(); }); + + test("should render a basic dataset without errors", async () => { + const dataset = { + "@context": { + "@vocab": "https://schema.hbp.eu/myQuery/", + }, + fullName: "", + description: "", + id: "https://kg.ebrains.eu/api/instances/ff19f5db-e829-4b85-92eb-fc56991541f1", + author: [], + shortName: "An example patch clamp dataset", + custodian: [], + isVersionOf: { + author: [ + { + givenName: "Stanley", + shortName: null, + familyName: "Laurel", + fullName: null, + type: ["https://openminds.ebrains.eu/core/Person"], + id: "https://kg.ebrains.eu/api/instances/a0993482-69dd-468b-a1d3-ff9589b485ae", + }, + { + givenName: "Oliver", + shortName: null, + familyName: "Hardy", + fullName: null, + type: ["https://openminds.ebrains.eu/core/Person"], + id: "https://kg.ebrains.eu/api/instances/9fe3ffd5-bd56-4aee-979a-6ed15f65d235", + }, + ], + shortName: "An example patch clamp dataset", + custodian: [ + { + givenName: "Stanley", + shortName: null, + familyName: "Laurel", + fullName: null, + type: ["https://openminds.ebrains.eu/core/Person"], + id: "https://kg.ebrains.eu/api/instances/a0993482-69dd-468b-a1d3-ff9589b485ae", + }, + ], + fullName: "An example patch clamp dataset, this is the long version of the name", + description: + "In this study we analyzed the intrinsic electrophysiological properties of foo in a mouse model of ...", + }, + releaseDate: "2024-04-01", + license: "CC BY 4.0", + ethicsAssessment: "EU compliant, non sensitive", + versionIdentifier: "v1", + studiedSpecimen: [ + { + species: { + species: null, + name: "Mus musculus", + }, + lookupLabel: "sub-42", + studiedState: [ + { + age: { + maxValue: 10, + minValue: 9, + maxValueUnit: "month", + value: null, + unit: null, + minValueUnit: "month", + }, + ageCategory: "adult", + lookupLabel: "sub-42-state01", + pathology: [], + slicePreparation: [] + }, + ], + biologicalSex: "male", + }, + ], + }; + + render(); + + expect(screen.getByText(/An example patch clamp dataset/i)).toBeInTheDocument(); + }); }); diff --git a/apps/nar-v3/src/components/DataFileCard.jsx b/apps/nar-v3/src/components/DataFileCard.jsx index 2a76497..666b29b 100644 --- a/apps/nar-v3/src/components/DataFileCard.jsx +++ b/apps/nar-v3/src/components/DataFileCard.jsx @@ -27,7 +27,10 @@ import KeyValueTable from "./KeyValueTable"; import styles from "../styles"; function DataFileCard(props) { - const fileObj = props.fileObjects[props.index]; + let fileObj = null; + if (props.fileObjects) { + fileObj = props.fileObjects[props.index]; + } if (fileObj) { const data = { diff --git a/apps/nar-v3/src/components/DatasetCard.jsx b/apps/nar-v3/src/components/DatasetCard.jsx index f7994ca..cce4389 100644 --- a/apps/nar-v3/src/components/DatasetCard.jsx +++ b/apps/nar-v3/src/components/DatasetCard.jsx @@ -96,9 +96,14 @@ function DatasetCard(props) { }; const getDataFiles = (subjectIndex, sliceIndex, stimulationIndex) => { - const stimulationActivity = getStimulationActivities(subjectIndex, sliceIndex)[stimulationIndex]; - if (stimulationActivity) { - return stimulationActivity.output; + const stimulationActivities = getStimulationActivities(subjectIndex, sliceIndex); + if (stimulationActivities) { + const stimulationActivity = stimulationActivities[stimulationIndex]; + if (stimulationActivity) { + return stimulationActivity.output; + } else { + return null; + } } else { return null; } diff --git a/apps/nar-v3/src/components/RecordingCard.jsx b/apps/nar-v3/src/components/RecordingCard.jsx index 95249a2..863c724 100644 --- a/apps/nar-v3/src/components/RecordingCard.jsx +++ b/apps/nar-v3/src/components/RecordingCard.jsx @@ -29,7 +29,10 @@ import { formatQuant } from "../utility"; function RecordingCard(props) { const recording = props.recording; - const stimulation = props.stimulations[props.index]; + let stimulation = null; + if (props.stimulations) { + stimulation = props.stimulations[props.index]; + } if (recording) { const recordingData = {