From 460471b7f0cc934e8e3dfda0ef06ee8a94a5e7b0 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Mon, 18 Mar 2024 11:46:21 -0700 Subject: [PATCH 01/11] Allow specifying subject and session IDs for single-session case --- schemas/base-metadata.schema.ts | 2 +- src/renderer/src/stories/JSONSchemaInput.js | 2 +- .../guided-mode/data/GuidedPathExpansion.js | 32 ++++---- .../pages/guided-mode/setup/GuidedSubjects.js | 2 +- .../pages/guided-mode/setup/Preform.js | 76 ++++++++++++++++--- .../stories/pages/settings/SettingsPage.js | 13 ++++ 6 files changed, 100 insertions(+), 27 deletions(-) diff --git a/schemas/base-metadata.schema.ts b/schemas/base-metadata.schema.ts index 02fd6a61f..bd44f4523 100644 --- a/schemas/base-metadata.schema.ts +++ b/schemas/base-metadata.schema.ts @@ -111,8 +111,8 @@ export const preprocessMetadataSchema = (schema: any = baseMetadataSchema, globa uvProperties.forEach(prop => { electrodeItems[prop] = {} electrodeItems[prop].title = prop.replace('uV', uvMathFormat) - console.log(electrodeItems[prop]) }) + interfaceProps["Electrodes"].items.order = ["channel_name", "group_name", "shank_electrode_number", ...uvProperties]; interfaceProps["ElectrodeColumns"].items.order = ["name", "description", "data_type"]; diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index a2b388697..8de5a0f99 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -637,7 +637,7 @@ export class JSONSchemaInput extends LitElement { ${ schema.description ? html`

- ${unsafeHTML(capitalize(schema.description))}${schema.description.slice(-1)[0] === "." + ${unsafeHTML(capitalize(schema.description))}${['.', '?', '!'].includes(schema.description.slice(-1)[0]) ? "" : "."}

` diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js index e28852fc4..90e303a8d 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js @@ -263,19 +263,26 @@ export class GuidedPathExpansionPage extends Page { #initialize = () => (this.localState = merge(this.info.globalState.structure, { results: {} })); workflow = { + subject_id: {}, + session_id: {}, locate_data: { skip: () => { this.#initialize(); const globalState = this.info.globalState; merge({ structure: this.localState }, globalState); // Merge the actual entries into the structure + + // Force single subject/session if not keeping existing data - if (!globalState.results) { - const existingMetadata = - globalState.results?.[this.altInfo.subject_id]?.[this.altInfo.session_id]?.metadata; + // if (!globalState.results) { + + const subject_id = this.workflow.subject_id.value + const session_id = this.workflow.session_id.value - const existingSourceData = - globalState.results?.[this.altInfo.subject_id]?.[this.altInfo.session_id]?.source_data; + // Map existing results to new subject information (if available) + const existingResults = Object.values(Object.values(globalState.results ?? {})[0] ?? {})[0] + const existingMetadata = existingResults.metadata; + const existingSourceData = existingResults.source_data; const source_data = {}; for (let key in globalState.interfaces) { @@ -284,23 +291,23 @@ export class GuidedPathExpansionPage extends Page { } globalState.results = { - [this.altInfo.subject_id]: { - [this.altInfo.session_id]: { + [subject_id]: { + [session_id]: { source_data, metadata: { NWBFile: { - session_id: this.altInfo.session_id, + session_id: session_id, ...(existingMetadata?.NWBFile ?? {}), }, Subject: { - subject_id: this.altInfo.subject_id, + subject_id: subject_id, ...(existingMetadata?.Subject ?? {}), }, }, }, }, }; - } + // } }, }, }; @@ -382,11 +389,6 @@ export class GuidedPathExpansionPage extends Page { }, }; - altInfo = { - subject_id: "001", - session_id: "1", - }; - // altForm = new JSONSchemaForm({ // results: this.altInfo, // schema: { diff --git a/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js b/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js index 11f54307b..ea623dc98 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js @@ -5,7 +5,6 @@ import { validateOnChange } from "../../../../validation/index.js"; import { Table } from "../../../Table.js"; import { updateResultsFromSubjects } from "./utils"; -import { merge } from "../../utils.js"; import { preprocessMetadataSchema } from "../../../../../../../schemas/base-metadata.schema"; import { Button } from "../../../Button.js"; import { createGlobalFormModal } from "../../../forms/GlobalFormModal"; @@ -68,6 +67,7 @@ export class GuidedSubjectsPage extends Page { ); nameMap[key] = renamed; } + // Remove identifiers for (let key in localState) delete localState[key].identifier; diff --git a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js index 8ac335db1..60c1d449e 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js @@ -12,11 +12,37 @@ const questions = { type: "boolean", title: "Will this pipeline be run on multiple sessions?", default: false, +}, + subject_id: { + type: 'string', + description: "Provide an identifier for your subject", + dependencies: { + multiple_sessions: { + condition: [ false, undefined ], + default: '', + required: true, + attribute: 'hidden' + } + }, + }, + session_id: { + type: 'string', + description: "Provide an identifier for your session", + dependencies: { + multiple_sessions: { + condition: [ false, undefined ], + default: '', + required: true, + attribute: 'hidden' + } + } }, locate_data: { type: "boolean", title: "Would you like to locate the source data programmatically?", - dependencies: ["multiple_sessions"], + dependencies: { + multiple_sessions: { default: false } + }, default: false, }, }; @@ -28,11 +54,18 @@ const questions = { const dependents = Object.entries(questions).reduce((acc, [name, info]) => { acc[name] = []; - if (info.dependencies) { - info.dependencies.forEach((dep) => { + const deps = info.dependencies + + if (deps) { + if (Array.isArray(deps)) deps.forEach((dep) => { if (!acc[dep]) acc[dep] = []; - acc[dep].push(name); + acc[dep].push({ name }); }); + + else Object.entries(deps).forEach(([dep, opts]) => { + if (!acc[dep]) acc[dep] = []; + acc[dep].push({ name, ...opts }); + }) } return acc; }, {}); @@ -77,17 +110,42 @@ export class GuidedPreform extends Page { if (!projectState.workflow) projectState.workflow = {}; this.state = structuredClone(projectState.workflow); + this.form = new JSONSchemaForm({ schema, results: this.state, validateOnChange: function (name, parent, path, value) { + dependents[name].forEach((dependent) => { - const dependencies = questions[dependent].dependencies; - const dependentEl = this.inputs[dependent]; - if (dependencies.every((dep) => parent[dep])) dependentEl.removeAttribute("disabled"); + const dependencies = questions[dependent.name].dependencies; + const uniformDeps = Array.isArray(dependencies) ? dependencies.map(name => { + return { name } + }) : Object.entries(dependencies).map(([name, info]) => { + return {name, ...info} + }) + + const dependentEl = this.inputs[dependent.name]; + + const attr = dependent.attribute ?? 'disabled' + + let condition = ((v) => !!v) + if (!('condition' in dependent)) {} + else if (typeof dependent.condition === 'boolean') condition = (v) => v == dependent.condition + else if (Array.isArray(dependent.condition)) condition = (v) => dependent.condition.some((condition) => v == condition) + else console.warn('Invalid condition', dependent.condition) + + if (uniformDeps.every(({ name }) => condition(parent[name]))) { + dependentEl.removeAttribute(attr); + if ('required' in dependent) dependentEl.required = dependent.required + if ('__cached' in dependent) dependentEl.updateData(dependent.__cached); + } + else { - dependentEl.updateData(false); - dependentEl.setAttribute("disabled", true); + if (dependentEl.value !== undefined) dependent.__cached = dependentEl.value + dependentEl.updateData(dependent.default); + dependentEl.setAttribute(attr, true); + + if ('required' in dependent) dependentEl.required = !dependent.required } }); }, diff --git a/src/renderer/src/stories/pages/settings/SettingsPage.js b/src/renderer/src/stories/pages/settings/SettingsPage.js index 246c89611..db86cdcbd 100644 --- a/src/renderer/src/stories/pages/settings/SettingsPage.js +++ b/src/renderer/src/stories/pages/settings/SettingsPage.js @@ -37,6 +37,8 @@ function saveNewPipelineFromYaml(name, sourceData, rootFolder) { const subjectId = "mouse1"; const sessions = ["session1"]; + const hasMultipleSessions = sessions.length > 1 + const resolvedSourceData = structuredClone(sourceData); Object.values(resolvedSourceData).forEach((info) => { propertiesToTransform.forEach((property) => { @@ -52,12 +54,23 @@ function saveNewPipelineFromYaml(name, sourceData, rootFolder) { remove(updatedName, true); + const workflowInfo = { + multiple_sessions: hasMultipleSessions, + } + + if (!workflowInfo.multiple_sessions) { + workflowInfo.subject_id = subjectId + workflowInfo.session_id = sessions[0] + } + + save({ info: { globalState: { project: { name: updatedName, initialized: true, + workflow: workflowInfo, }, // provide data for all supported interfaces From ffe7cc9757d851ab431002efe4b1a37ba7a8bb2a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:47:21 +0000 Subject: [PATCH 02/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- schemas/base-metadata.schema.ts | 2 +- src/renderer/src/stories/JSONSchemaInput.js | 4 +- .../guided-mode/data/GuidedPathExpansion.js | 52 ++++++----- .../pages/guided-mode/setup/GuidedSubjects.js | 1 - .../pages/guided-mode/setup/Preform.js | 90 +++++++++---------- .../stories/pages/settings/SettingsPage.js | 9 +- 6 files changed, 78 insertions(+), 80 deletions(-) diff --git a/schemas/base-metadata.schema.ts b/schemas/base-metadata.schema.ts index bd44f4523..c8a16f336 100644 --- a/schemas/base-metadata.schema.ts +++ b/schemas/base-metadata.schema.ts @@ -112,7 +112,7 @@ export const preprocessMetadataSchema = (schema: any = baseMetadataSchema, globa electrodeItems[prop] = {} electrodeItems[prop].title = prop.replace('uV', uvMathFormat) }) - + interfaceProps["Electrodes"].items.order = ["channel_name", "group_name", "shank_electrode_number", ...uvProperties]; interfaceProps["ElectrodeColumns"].items.order = ["name", "description", "data_type"]; diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index 8de5a0f99..7dec3e6e8 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -637,7 +637,9 @@ export class JSONSchemaInput extends LitElement { ${ schema.description ? html`

- ${unsafeHTML(capitalize(schema.description))}${['.', '?', '!'].includes(schema.description.slice(-1)[0]) + ${unsafeHTML(capitalize(schema.description))}${[".", "?", "!"].includes( + schema.description.slice(-1)[0] + ) ? "" : "."}

` diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js index 90e303a8d..e3a6ef2e2 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js @@ -271,42 +271,40 @@ export class GuidedPathExpansionPage extends Page { const globalState = this.info.globalState; merge({ structure: this.localState }, globalState); // Merge the actual entries into the structure - - // Force single subject/session if not keeping existing data // if (!globalState.results) { - const subject_id = this.workflow.subject_id.value - const session_id = this.workflow.session_id.value + const subject_id = this.workflow.subject_id.value; + const session_id = this.workflow.session_id.value; - // Map existing results to new subject information (if available) - const existingResults = Object.values(Object.values(globalState.results ?? {})[0] ?? {})[0] - const existingMetadata = existingResults.metadata; - const existingSourceData = existingResults.source_data; + // Map existing results to new subject information (if available) + const existingResults = Object.values(Object.values(globalState.results ?? {})[0] ?? {})[0]; + const existingMetadata = existingResults.metadata; + const existingSourceData = existingResults.source_data; - const source_data = {}; - for (let key in globalState.interfaces) { - const existing = existingSourceData?.[key]; - if (existing) source_data[key] = existing ?? {}; - } + const source_data = {}; + for (let key in globalState.interfaces) { + const existing = existingSourceData?.[key]; + if (existing) source_data[key] = existing ?? {}; + } - globalState.results = { - [subject_id]: { - [session_id]: { - source_data, - metadata: { - NWBFile: { - session_id: session_id, - ...(existingMetadata?.NWBFile ?? {}), - }, - Subject: { - subject_id: subject_id, - ...(existingMetadata?.Subject ?? {}), - }, + globalState.results = { + [subject_id]: { + [session_id]: { + source_data, + metadata: { + NWBFile: { + session_id: session_id, + ...(existingMetadata?.NWBFile ?? {}), + }, + Subject: { + subject_id: subject_id, + ...(existingMetadata?.Subject ?? {}), }, }, }, - }; + }, + }; // } }, }, diff --git a/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js b/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js index ea623dc98..060e6a3f4 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/GuidedSubjects.js @@ -67,7 +67,6 @@ export class GuidedSubjectsPage extends Page { ); nameMap[key] = renamed; } - // Remove identifiers for (let key in localState) delete localState[key].identifier; diff --git a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js index 60c1d449e..4a3a04223 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js @@ -12,36 +12,36 @@ const questions = { type: "boolean", title: "Will this pipeline be run on multiple sessions?", default: false, -}, + }, subject_id: { - type: 'string', + type: "string", description: "Provide an identifier for your subject", dependencies: { multiple_sessions: { - condition: [ false, undefined ], - default: '', + condition: [false, undefined], + default: "", required: true, - attribute: 'hidden' - } + attribute: "hidden", + }, }, }, session_id: { - type: 'string', + type: "string", description: "Provide an identifier for your session", dependencies: { multiple_sessions: { - condition: [ false, undefined ], - default: '', + condition: [false, undefined], + default: "", required: true, - attribute: 'hidden' - } - } + attribute: "hidden", + }, + }, }, locate_data: { type: "boolean", title: "Would you like to locate the source data programmatically?", dependencies: { - multiple_sessions: { default: false } + multiple_sessions: { default: false }, }, default: false, }, @@ -54,18 +54,19 @@ const questions = { const dependents = Object.entries(questions).reduce((acc, [name, info]) => { acc[name] = []; - const deps = info.dependencies - - if (deps) { - if (Array.isArray(deps)) deps.forEach((dep) => { - if (!acc[dep]) acc[dep] = []; - acc[dep].push({ name }); - }); + const deps = info.dependencies; - else Object.entries(deps).forEach(([dep, opts]) => { - if (!acc[dep]) acc[dep] = []; - acc[dep].push({ name, ...opts }); - }) + if (deps) { + if (Array.isArray(deps)) + deps.forEach((dep) => { + if (!acc[dep]) acc[dep] = []; + acc[dep].push({ name }); + }); + else + Object.entries(deps).forEach(([dep, opts]) => { + if (!acc[dep]) acc[dep] = []; + acc[dep].push({ name, ...opts }); + }); } return acc; }, {}); @@ -110,42 +111,41 @@ export class GuidedPreform extends Page { if (!projectState.workflow) projectState.workflow = {}; this.state = structuredClone(projectState.workflow); - this.form = new JSONSchemaForm({ schema, results: this.state, validateOnChange: function (name, parent, path, value) { - dependents[name].forEach((dependent) => { const dependencies = questions[dependent.name].dependencies; - const uniformDeps = Array.isArray(dependencies) ? dependencies.map(name => { - return { name } - }) : Object.entries(dependencies).map(([name, info]) => { - return {name, ...info} - }) - + const uniformDeps = Array.isArray(dependencies) + ? dependencies.map((name) => { + return { name }; + }) + : Object.entries(dependencies).map(([name, info]) => { + return { name, ...info }; + }); + const dependentEl = this.inputs[dependent.name]; - const attr = dependent.attribute ?? 'disabled' + const attr = dependent.attribute ?? "disabled"; - let condition = ((v) => !!v) - if (!('condition' in dependent)) {} - else if (typeof dependent.condition === 'boolean') condition = (v) => v == dependent.condition - else if (Array.isArray(dependent.condition)) condition = (v) => dependent.condition.some((condition) => v == condition) - else console.warn('Invalid condition', dependent.condition) + let condition = (v) => !!v; + if (!("condition" in dependent)) { + } else if (typeof dependent.condition === "boolean") condition = (v) => v == dependent.condition; + else if (Array.isArray(dependent.condition)) + condition = (v) => dependent.condition.some((condition) => v == condition); + else console.warn("Invalid condition", dependent.condition); if (uniformDeps.every(({ name }) => condition(parent[name]))) { dependentEl.removeAttribute(attr); - if ('required' in dependent) dependentEl.required = dependent.required - if ('__cached' in dependent) dependentEl.updateData(dependent.__cached); - } - - else { - if (dependentEl.value !== undefined) dependent.__cached = dependentEl.value + if ("required" in dependent) dependentEl.required = dependent.required; + if ("__cached" in dependent) dependentEl.updateData(dependent.__cached); + } else { + if (dependentEl.value !== undefined) dependent.__cached = dependentEl.value; dependentEl.updateData(dependent.default); dependentEl.setAttribute(attr, true); - if ('required' in dependent) dependentEl.required = !dependent.required + if ("required" in dependent) dependentEl.required = !dependent.required; } }); }, diff --git a/src/renderer/src/stories/pages/settings/SettingsPage.js b/src/renderer/src/stories/pages/settings/SettingsPage.js index db86cdcbd..d388b2397 100644 --- a/src/renderer/src/stories/pages/settings/SettingsPage.js +++ b/src/renderer/src/stories/pages/settings/SettingsPage.js @@ -37,7 +37,7 @@ function saveNewPipelineFromYaml(name, sourceData, rootFolder) { const subjectId = "mouse1"; const sessions = ["session1"]; - const hasMultipleSessions = sessions.length > 1 + const hasMultipleSessions = sessions.length > 1; const resolvedSourceData = structuredClone(sourceData); Object.values(resolvedSourceData).forEach((info) => { @@ -56,14 +56,13 @@ function saveNewPipelineFromYaml(name, sourceData, rootFolder) { const workflowInfo = { multiple_sessions: hasMultipleSessions, - } + }; if (!workflowInfo.multiple_sessions) { - workflowInfo.subject_id = subjectId - workflowInfo.session_id = sessions[0] + workflowInfo.subject_id = subjectId; + workflowInfo.session_id = sessions[0]; } - save({ info: { globalState: { From a9f722258bc77f29f726fdd242d9a3840e7c8095 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Mon, 18 Mar 2024 12:33:11 -0700 Subject: [PATCH 03/11] Only show errors after submit --- src/renderer/src/stories/Dashboard.js | 1 + src/renderer/src/stories/JSONSchemaInput.js | 20 +++++++++++++++++++ .../guided-mode/data/GuidedPathExpansion.js | 4 ++-- .../pages/guided-mode/setup/Preform.js | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/stories/Dashboard.js b/src/renderer/src/stories/Dashboard.js index c14e5c15b..7606fe64c 100644 --- a/src/renderer/src/stories/Dashboard.js +++ b/src/renderer/src/stories/Dashboard.js @@ -234,6 +234,7 @@ export class Dashboard extends LitElement { if (this.#transitionPromise.value) this.#transitionPromise.trigger(page); // This ensures calls to page.to() can be properly awaited until the next page is ready const { skipped } = this.subSidebar.sections[info.section]?.pages?.[info.id] ?? {}; + if (skipped) { if (isStorybook) return; // Do not skip on storybook diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index 7dec3e6e8..16b6debce 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -498,6 +498,26 @@ export class JSONSchemaInput extends LitElement { }; } + // Enforce dynamic required properties + attributeChangedCallback(key, _, latest) { + super.attributeChangedCallback(...arguments); + + const formSchema = this.form.schema + + if (latest !== null) { + const requirements = formSchema.required ?? (formSchema.required = []) + if (!requirements.includes(key)) requirements.push(key) + } else { + if (formSchema.requirements && formSchema.requirements.includes(key)) { + // Remove key form requirements + const set = new Set(formSchema.requirements) + set.remove(key) + formSchema.requirements = Array.from(set) + } + } + + } + // schema, // parent, // path, diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js index e3a6ef2e2..13d1b57c2 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js @@ -278,7 +278,7 @@ export class GuidedPathExpansionPage extends Page { const session_id = this.workflow.session_id.value; // Map existing results to new subject information (if available) - const existingResults = Object.values(Object.values(globalState.results ?? {})[0] ?? {})[0]; + const existingResults = Object.values(Object.values(globalState.results ?? {})[0] ?? {})[0] ?? {}; const existingMetadata = existingResults.metadata; const existingSourceData = existingResults.source_data; @@ -436,7 +436,7 @@ export class GuidedPathExpansionPage extends Page { const form = (this.form = new JSONSchemaForm({ ...structureState, onThrow, - validateEmptyValues: null, + validateEmptyValues: false, controls, diff --git a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js index 4a3a04223..09e854de9 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js @@ -114,6 +114,7 @@ export class GuidedPreform extends Page { this.form = new JSONSchemaForm({ schema, results: this.state, + validateEmptyValues: false, // Only show errors after submission validateOnChange: function (name, parent, path, value) { dependents[name].forEach((dependent) => { const dependencies = questions[dependent.name].dependencies; From 715088311d0e0536fd64c16ac06436fe222749de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:33:28 +0000 Subject: [PATCH 04/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/JSONSchemaInput.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index 16b6debce..833ebb10a 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -502,20 +502,19 @@ export class JSONSchemaInput extends LitElement { attributeChangedCallback(key, _, latest) { super.attributeChangedCallback(...arguments); - const formSchema = this.form.schema + const formSchema = this.form.schema; if (latest !== null) { - const requirements = formSchema.required ?? (formSchema.required = []) - if (!requirements.includes(key)) requirements.push(key) + const requirements = formSchema.required ?? (formSchema.required = []); + if (!requirements.includes(key)) requirements.push(key); } else { if (formSchema.requirements && formSchema.requirements.includes(key)) { // Remove key form requirements - const set = new Set(formSchema.requirements) - set.remove(key) - formSchema.requirements = Array.from(set) + const set = new Set(formSchema.requirements); + set.remove(key); + formSchema.requirements = Array.from(set); } } - } // schema, From 4eacee2de19fa8e0e01b9dd6d74cd2a64020c0cb Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Mon, 18 Mar 2024 12:49:58 -0700 Subject: [PATCH 05/11] Fixed dynamic requirements --- src/renderer/src/stories/JSONSchemaForm.js | 2 +- src/renderer/src/stories/JSONSchemaInput.js | 23 +++++++++++-------- .../guided-mode/data/GuidedPathExpansion.js | 2 ++ .../guided-mode/data/GuidedSourceData.js | 4 ---- .../pages/guided-mode/setup/Preform.js | 1 - 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index 28dff4eaf..c182c981b 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -98,7 +98,7 @@ const componentCSS = ` :host { display: inline-block; - width:100%; + width: 100%; } .form-section { diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index 16b6debce..632872342 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -504,15 +504,20 @@ export class JSONSchemaInput extends LitElement { const formSchema = this.form.schema - if (latest !== null) { - const requirements = formSchema.required ?? (formSchema.required = []) - if (!requirements.includes(key)) requirements.push(key) - } else { - if (formSchema.requirements && formSchema.requirements.includes(key)) { - // Remove key form requirements - const set = new Set(formSchema.requirements) - set.remove(key) - formSchema.requirements = Array.from(set) + if (key === 'required') { + + const name = this.path.slice(-1)[0] + + if (latest !== null) { + const requirements = formSchema.required ?? (formSchema.required = []) + if (!requirements.includes(name)) requirements.push(name) + } else { + if (formSchema.requirements && formSchema.requirements.includes(name)) { + // Remove key form requirements + const set = new Set(formSchema.requirements) + set.remove(name) + formSchema.requirements = Array.from(set) + } } } diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js index 13d1b57c2..0512e045a 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js @@ -306,6 +306,8 @@ export class GuidedPathExpansionPage extends Page { }, }; // } + + this.save({}, false) // Ensure this structure is saved }, }, }; 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 6bd47bc30..2d67ff619 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedSourceData.js @@ -222,10 +222,6 @@ export class GuidedSourceDataPage extends ManagedPage { updated() { const dashboard = document.querySelector("nwb-dashboard"); const page = dashboard.page; - setTimeout(() => { - console.log(page.forms[0].form.accordions["SpikeGLX Recording"]); - }); - console.log(page.forms[0].form.accordions); } render() { diff --git a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js index 09e854de9..a298f026a 100644 --- a/src/renderer/src/stories/pages/guided-mode/setup/Preform.js +++ b/src/renderer/src/stories/pages/guided-mode/setup/Preform.js @@ -145,7 +145,6 @@ export class GuidedPreform extends Page { if (dependentEl.value !== undefined) dependent.__cached = dependentEl.value; dependentEl.updateData(dependent.default); dependentEl.setAttribute(attr, true); - if ("required" in dependent) dependentEl.required = !dependent.required; } }); From 80297c51d3abfb4e108cd5d1a5f5cd90afca92b4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:50:42 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/JSONSchemaInput.js | 15 +++++++-------- .../pages/guided-mode/data/GuidedPathExpansion.js | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index 5a3bfc2f0..a1d246b76 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -504,19 +504,18 @@ export class JSONSchemaInput extends LitElement { const formSchema = this.form.schema; - if (key === 'required') { + if (key === "required") { + const name = this.path.slice(-1)[0]; - const name = this.path.slice(-1)[0] - if (latest !== null) { - const requirements = formSchema.required ?? (formSchema.required = []) - if (!requirements.includes(name)) requirements.push(name) + const requirements = formSchema.required ?? (formSchema.required = []); + if (!requirements.includes(name)) requirements.push(name); } else { if (formSchema.requirements && formSchema.requirements.includes(name)) { // Remove key form requirements - const set = new Set(formSchema.requirements) - set.remove(name) - formSchema.requirements = Array.from(set) + const set = new Set(formSchema.requirements); + set.remove(name); + formSchema.requirements = Array.from(set); } } } diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js index 0512e045a..124df6afd 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedPathExpansion.js @@ -307,7 +307,7 @@ export class GuidedPathExpansionPage extends Page { }; // } - this.save({}, false) // Ensure this structure is saved + this.save({}, false); // Ensure this structure is saved }, }, }; From 655a5a53595c0df05faea7965b15c56cd3de192e Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Mon, 18 Mar 2024 13:49:16 -0700 Subject: [PATCH 07/11] Update JSONSchemaInput.js --- src/renderer/src/stories/JSONSchemaInput.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index a1d246b76..cac8b8204 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -504,10 +504,12 @@ export class JSONSchemaInput extends LitElement { const formSchema = this.form.schema; + if (key === "required") { + const name = this.path.slice(-1)[0]; - if (latest !== null) { + if (latest !== null && !this.conditional) { const requirements = formSchema.required ?? (formSchema.required = []); if (!requirements.includes(name)) requirements.push(name); } else { From 6fa2c8811260126b6617fdca61a9deb8e7c86969 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:49:32 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/JSONSchemaInput.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index cac8b8204..be40479e7 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -504,9 +504,7 @@ export class JSONSchemaInput extends LitElement { const formSchema = this.form.schema; - if (key === "required") { - const name = this.path.slice(-1)[0]; if (latest !== null && !this.conditional) { From 9de7f0707575f2212229e74831ce8f333eda08d9 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Mon, 18 Mar 2024 13:50:08 -0700 Subject: [PATCH 09/11] Update JSONSchemaInput.js --- src/renderer/src/stories/JSONSchemaInput.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index cac8b8204..046043f37 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -512,9 +512,11 @@ export class JSONSchemaInput extends LitElement { if (latest !== null && !this.conditional) { const requirements = formSchema.required ?? (formSchema.required = []); if (!requirements.includes(name)) requirements.push(name); - } else { + } + + // Remove requirement from form schema (and force if conditional requirement) + else { if (formSchema.requirements && formSchema.requirements.includes(name)) { - // Remove key form requirements const set = new Set(formSchema.requirements); set.remove(name); formSchema.requirements = Array.from(set); From 9fcfafd9ea6534bee9af615032ba1ad2cb608b65 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Mar 2024 20:50:34 +0000 Subject: [PATCH 10/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/JSONSchemaInput.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index f1dbb09f0..d2a018d9c 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -510,8 +510,8 @@ export class JSONSchemaInput extends LitElement { if (latest !== null && !this.conditional) { const requirements = formSchema.required ?? (formSchema.required = []); if (!requirements.includes(name)) requirements.push(name); - } - + } + // Remove requirement from form schema (and force if conditional requirement) else { if (formSchema.requirements && formSchema.requirements.includes(name)) { From a37a393f6ba37fd81742c2210fa1bfa50bb75271 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Fri, 22 Mar 2024 17:31:06 -0700 Subject: [PATCH 11/11] Fix tests --- tests/e2e.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index 82ee7f3f7..9d59f3313 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -215,7 +215,20 @@ describe('E2E Test', () => { test('View the pre-form workflow page', async () => { + await references.page.evaluate(() => { + const dashboard = document.querySelector('nwb-dashboard') + const page = dashboard.page + + const subjectId = page.form.getFormElement(['subject_id']) + subjectId.updateData('subject1') + + const sessionId = page.form.getFormElement(['session_id']) + sessionId.updateData('session1') + }) + await takeScreenshot('workflow-page', 300) + + await toNextPage('structure')