From 8e173385e7d47a7c5264a38ddae2ad3f477813ad Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Thu, 26 Oct 2023 16:56:59 -0700 Subject: [PATCH 1/2] Update schema handling --- schemas/base-metadata.schema.ts | 12 ++- schemas/json/base_metadata_schema.json | 2 +- schemas/json/project/nwbfile.json | 74 ------------------- schemas/source-data.schema.ts | 14 +++- .../pages/guided-mode/data/GuidedMetadata.js | 3 +- .../guided-mode/data/GuidedSourceData.js | 8 +- 6 files changed, 27 insertions(+), 86 deletions(-) delete mode 100644 schemas/json/project/nwbfile.json diff --git a/schemas/base-metadata.schema.ts b/schemas/base-metadata.schema.ts index 57abb60db..08063e099 100644 --- a/schemas/base-metadata.schema.ts +++ b/schemas/base-metadata.schema.ts @@ -1,6 +1,14 @@ import baseMetadataSchema from './json/base_metadata_schema.json' assert { type: "json" } -baseMetadataSchema.properties.Subject.properties.weight.unit = 'kg' // Add unit to weight +export const preprocessMetadataSchema = (schema: any = baseMetadataSchema) => { + // Add unit to weight + schema.properties.Subject.properties.weight.unit = 'kg' -export default baseMetadataSchema + // Override description of keywords + schema.properties.NWBFile.properties.keywords.description = 'Terms to describe your dataset (e.g. Neural circuits, V1, etc.)' // Add description to keywords + return schema + +} + +export default preprocessMetadataSchema() diff --git a/schemas/json/base_metadata_schema.json b/schemas/json/base_metadata_schema.json index 201620788..4b7503e81 100644 --- a/schemas/json/base_metadata_schema.json +++ b/schemas/json/base_metadata_schema.json @@ -102,7 +102,7 @@ }, "stimulus_notes": { "type": "string", - "description": "Notes about data collection and analysis." + "description": "Notes about stimuli, such as how and where presented." } } }, diff --git a/schemas/json/project/nwbfile.json b/schemas/json/project/nwbfile.json deleted file mode 100644 index f5c047e17..000000000 --- a/schemas/json/project/nwbfile.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "properties": { - "NWBFile": { - "type": "object", - "properties": { - - "institution": { - "type": "string", - "description": "Enter the name of your institution.", - "placeholder": "Enter institution name here" - }, - "lab": { - "type": "string", - "description": "Enter the name of your lab.", - "placeholder": "Enter lab name here" - }, - "experimenter": { - "type": "array", - "description": "Enter the names of the experimenters.", - "placeholder": "Enter experimenter name heres", - "items": { - "type": "string" - } - }, - - "related_publications": { - "type": "array", - "description": "Enter DOIs of relevant publications.", - "placeholder": "Enter publication DOIs here", - "items": { - "type": "string" - } - }, - - "experiment_description": { - "type": "string", - "format": "long", - "description": "Enter a description of the experiment.", - "placeholder": "Enter experiment description here" - }, - - "keywords": { - "type": "array", - "items": { - "type": "string" - }, - "description": "Enter keywords for the experiment.", - "placeholder": "Enter experiment keywords here" - }, - - "protocol": { - "type": "string", - "description": "Enter a description of the protocol.", - "placeholder": "Enter protocol description here" - }, - "surgery": { - "type": "string", - "description": "Enter a description of the surgery.", - "placeholder": "Enter surgery description here" - }, - "virus": { - "type": "string", - "description": "Enter a description of the virus.", - "placeholder": "Enter virus description here" - }, - "stimulus_notes": { - "type": "string", - "description": "Enter a description of the stimulus.", - "placeholder": "Enter stimulus description here" - } - } - } - } -} diff --git a/schemas/source-data.schema.ts b/schemas/source-data.schema.ts index 5fe9ba03c..718b714c2 100644 --- a/schemas/source-data.schema.ts +++ b/schemas/source-data.schema.ts @@ -1,10 +1,18 @@ // import { merge } from "../src/renderer/src/stories/pages/utils" -export default function getSourceDataSchema (schema) { - // const copy = merge(schema, {}) +export default function preprocessSourceDataSchema (schema) { + + // Abstract across different interfaces Object.values(schema.properties ?? {}).forEach((schema: any) => { - if (schema.properties.gain) schema.properties.gain.step = null // Do not show steps + + // Do not show steps + if (schema.properties.gain) schema.properties.gain.step = null + + // Add description to exclude_cluster_groups + if (schema.properties.exclude_cluster_groups) schema.properties.exclude_cluster_groups.description = 'Cluster groups to exclude (e.g. "noise" or ["noise", "mua"]).' + }) + return schema } diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js index 3fe49cc04..ebf13eccb 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedMetadata.js @@ -11,6 +11,7 @@ import { SimpleTable } from "../../../SimpleTable.js"; import { onThrow } from "../../../../errors"; import { merge } from "../../utils.js"; import { NWBFilePreview } from "../../../preview/NWBFilePreview.js"; +import { preprocessMetadataSchema } from "../../../../../../../schemas/base-metadata.schema"; const getInfoFromId = (key) => { let [subject, session] = key.split("/"); @@ -106,7 +107,7 @@ export class GuidedMetadataPage extends ManagedPage { const form = new JSONSchemaForm({ identifier: instanceId, mode: "accordion", - schema, + schema: preprocessMetadataSchema(schema), results, globals: aggregateGlobalMetadata, diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js index d23d77956..64e6e0dfe 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js @@ -6,7 +6,7 @@ import { ManagedPage } from "./ManagedPage.js"; import { baseUrl } from "../../../../globals.js"; import { onThrow } from "../../../../errors"; import { merge } from "../../utils.js"; -import getSourceDataSchema from "../../../../../../../schemas/source-data.schema"; +import preprocessSourceDataSchema from "../../../../../../../schemas/source-data.schema"; export class GuidedSourceDataPage extends ManagedPage { constructor(...args) { @@ -95,7 +95,7 @@ export class GuidedSourceDataPage extends ManagedPage { const schema = this.info.globalState.schema; if (!schema.metadata) schema.metadata = {}; if (!schema.metadata[subject]) schema.metadata[subject] = {}; - schema.metadata[subject][session] = result.schema; + schema.metadata[subject][session] = result.schema }) ); @@ -109,12 +109,10 @@ export class GuidedSourceDataPage extends ManagedPage { const schema = this.info.globalState.schema.source_data; delete schema.description; - const schemaResolved = getSourceDataSchema(schema); - const form = new JSONSchemaForm({ identifier: instanceId, mode: "accordion", - schema: schemaResolved, + schema: preprocessSourceDataSchema(schema), results: info.source_data, emptyMessage: "No source data required for this session.", ignore: [ From e28c580935b36f41756da7236d24b59e9fe21182 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Oct 2023 23:58:35 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- schemas/source-data.schema.ts | 2 +- .../src/stories/pages/guided-mode/data/GuidedSourceData.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/schemas/source-data.schema.ts b/schemas/source-data.schema.ts index 718b714c2..f3622ee81 100644 --- a/schemas/source-data.schema.ts +++ b/schemas/source-data.schema.ts @@ -1,7 +1,7 @@ // import { merge } from "../src/renderer/src/stories/pages/utils" export default function preprocessSourceDataSchema (schema) { - + // Abstract across different interfaces Object.values(schema.properties ?? {}).forEach((schema: any) => { diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js index 64e6e0dfe..f54cc7d6d 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js @@ -95,7 +95,7 @@ export class GuidedSourceDataPage extends ManagedPage { const schema = this.info.globalState.schema; if (!schema.metadata) schema.metadata = {}; if (!schema.metadata[subject]) schema.metadata[subject] = {}; - schema.metadata[subject][session] = result.schema + schema.metadata[subject][session] = result.schema; }) );