Skip to content

Commit

Permalink
Merge pull request #455 from NeurodataWithoutBorders/gray-requirements
Browse files Browse the repository at this point in the history
Add a loose requirement mode
  • Loading branch information
CodyCBakerPhD authored Oct 18, 2023
2 parents 3e9d749 + da48f31 commit 9e5bb6d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
9 changes: 8 additions & 1 deletion src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ hr {
color: #ff0033;
}
:host([requirementmode="loose"]) .required label:after {
color: gray;
}
.required.conditional label:after {
color: transparent;
}
Expand Down Expand Up @@ -152,6 +157,7 @@ export class JSONSchemaForm extends LitElement {
required: { type: Object, reflect: false },
dialogType: { type: String, reflect: false },
dialogOptions: { type: Object, reflect: false },
requirementMode: { type: String, reflect: true },
};
}

Expand Down Expand Up @@ -189,6 +195,7 @@ export class JSONSchemaForm extends LitElement {
this.dialogType = props.dialogType;
this.deferLoading = props.deferLoading ?? false;

this.requirementMode = props.requirementMode ?? "default";
this.onlyRequired = props.onlyRequired ?? false;
this.showLevelOverride = props.showLevelOverride ?? false;

Expand Down Expand Up @@ -302,7 +309,7 @@ export class JSONSchemaForm extends LitElement {
validate = async (resolved) => {
// Check if any required inputs are missing
const invalidInputs = await this.#validateRequirements(resolved); // get missing required paths
const isValid = !invalidInputs.length;
const isValid = this.requirementMode === "loose" ? true : !invalidInputs.length;

// Print out a detailed error message if any inputs are missing
let message = isValid ? "" : `${invalidInputs.length} required inputs are not specified properly.`;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/stories/pages/FormPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export function schemaToPages(schema, globalStatePath, options, transformationCa
.filter(([_, value]) => value.properties)
.map(([key, value]) => {
const optionsCopy = { ...options };

if (optionsCopy.required && optionsCopy.required[key])
optionsCopy.required = {
[key]: optionsCopy.required[key],
};
// Only bring requirements from the current page
else delete optionsCopy.required;
else delete optionsCopy.required; // Only bring requirements from the current page

const page = new GuidedFormPage(
transformationCallback({
Expand Down
17 changes: 14 additions & 3 deletions src/renderer/src/stories/pages/guided-mode/GuidedStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,27 @@ export class GuidedStartPage extends Page {
<p>
The second section will have you provide your source data files and NWB File metadata on a per-subject basis to populate your files.
</p>
${new InspectorListItem({
message: html`<b>Red boxes are error messages.</b> These will block your conversion progress
message: html`Red boxes are <b>Error</b> messages. These will block your conversion progress
until resolved.`,
type: "error",
})}
${new InspectorListItem({
message: html`<b>Yellow boxes are warnings.</b> Fixing them will align your NWB files with
best practices.`,
message: html`Yellow boxes are <b>Warning</b> messages. Fixing them will align your NWB
files with best practices.`,
type: "warning",
})}
<p>
Throughout the forms found in the GUIDE, asterisks (<span style="color:red;">*</span>) represent required properties.
Attempting to move forward will throw an <b>Error</b> until these properties are filled in.
</p>
<p>
Gray asterisks (<span style="color:gray;">*</span>) are sometimes used to represent loose requirements, where missing this property will throw an <b>Error</b>
— though you don't need to specify a value at the current stage.
</p>
<h4>3. Conversion Preview</h4>
<p>
In the third section, you will preview your conversion before uploading to DANDI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ const changesAcrossSessions = {
const projectMetadataSchema = merge(projectGlobalSchema, projectGeneralSchema);

Object.entries(baseMetadataSchema.properties).forEach(([globalProp, v]) => {
Object.keys(v.properties)
.filter((prop) => !(changesAcrossSessions[globalProp] ?? []).includes(prop))
.forEach((prop) => {
const globalNestedProp =
projectMetadataSchema.properties[globalProp] ??
(projectMetadataSchema.properties[globalProp] = { properties: {} });
globalNestedProp.properties[prop] = baseMetadataSchema.properties[globalProp].properties[prop];
});
const info = (projectMetadataSchema.properties[globalProp] = structuredClone(v));

changesAcrossSessions[globalProp]?.forEach((prop) => {
delete info.properties[prop];
});
});

export class GuidedNewDatasetPage extends Page {
Expand Down Expand Up @@ -111,10 +108,16 @@ export class GuidedNewDatasetPage extends Page {

this.state = merge(global.data.output_locations, structuredClone(this.info.globalState.project));

const pages = schemaToPages.call(this, schema, ["project"], { validateEmptyValues: false }, (info) => {
info.title = `${info.label} Global Metadata`;
return info;
});
const pages = schemaToPages.call(
this,
schema,
["project"],
{ validateEmptyValues: false, requirementMode: "loose" },
(info) => {
info.title = `${info.label} Global Metadata`;
return info;
}
);

pages.forEach((page) => {
page.header = {
Expand Down

0 comments on commit 9e5bb6d

Please sign in to comment.