Skip to content

Commit

Permalink
Merge branch 'update-create-dandiset' of https://github.com/Neurodata…
Browse files Browse the repository at this point in the history
…WithoutBorders/nwb-guide into update-create-dandiset
  • Loading branch information
garrettmflynn committed Mar 8, 2024
2 parents e5ee64c + 4b74ced commit 384ac4a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 55 deletions.
9 changes: 3 additions & 6 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const componentCSS = `
border: 1px solid black;
border-radius: 4px;
position: relative;
}
.link > div {
Expand Down Expand Up @@ -818,14 +818,13 @@ export class JSONSchemaForm extends LitElement {

const value = parent[name];


const skipValidation = this.validateEmptyValues === null && value === undefined;

const validateArgs = input.pattern || skipValidation ? [] : [value, schema];

// Run validation functions
const jsonSchemaErrors = validateArgs.length === 2 ? this.validateSchema(...validateArgs, name) : [];
const valid = skipValidation ? true : await this.validateOnChange(name, parent, pathToValidate, value);
const valid = skipValidation ? true : await this.validateOnChange(name, parent, pathToValidate, value);

if (valid === null) return null; // Skip validation / data change if the value is null

Expand Down Expand Up @@ -882,9 +881,7 @@ export class JSONSchemaForm extends LitElement {
type: "error",
missing: true,
});
}

else if (this.validateEmptyValues === null) {
} else if (this.validateEmptyValues === null) {
warnings.push({
message: `${schema.title ?? header(name)} is a suggested property.`,
type: "warning",
Expand Down
41 changes: 17 additions & 24 deletions src/renderer/src/stories/JSONSchemaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,12 +858,11 @@ export class JSONSchemaInput extends LitElement {
}

const itemSchema = this.form?.getSchema ? this.form.getSchema("items", schema) : schema["items"];

const fileSystemFormat = isFilesystemSelector(name, itemSchema?.format);
if (fileSystemFormat) return createFilesystemSelector(fileSystemFormat);
// Create tables if possible
else if (itemSchema?.type === "string" && !itemSchema.properties) {

const list = new List({
items: this.value,
emptyMessage: "No items",
Expand All @@ -874,7 +873,6 @@ export class JSONSchemaInput extends LitElement {
});

if (itemSchema.enum) {

const search = new Search({
options: itemSchema.enum.map((v) => {
return {
Expand All @@ -887,45 +885,41 @@ export class JSONSchemaInput extends LitElement {
};
}),
value: this.value,
listMode: schema.strict === false ? 'click' : "append",
listMode: schema.strict === false ? "click" : "append",
showAllWhenEmpty: false,
onSelect: async ({ label, value }) => {
if (!value) return
if (schema.uniqueItems && this.value && this.value.includes(value)) return
list.add({ content: label, value })
if (!value) return;
if (schema.uniqueItems && this.value && this.value.includes(value)) return;
list.add({ content: label, value });
},
});

search.style.height = "auto";
return html`<div style="width: 100%;">${search}${list}</div>`;

}

else {
} else {
const input = document.createElement("input");
input.classList.add("guided--input");
input.placeholder = "Add an item to the list"
input.placeholder = "Provide an item for the list"

const submitButton = new Button({
label: "Submit",
primary: true,
size: "small",
onClick: () => {
const value = input.value
if (!value) return
if (schema.uniqueItems && this.value && this.value.includes(value)) return
list.add({ value })
input.value = ""
}
const value = input.value;
if (!value) return;
if (schema.uniqueItems && this.value && this.value.includes(value)) return;
list.add({ value });
input.value = "";
},
});



return html`<div style="width: 100%;"><div style="display: flex; gap: 10px; align-items: center;">${input}${submitButton}</div>${list}</div>`;
return html`<div style="width: 100%;">
<div style="display: flex; gap: 10px; align-items: center;">${input}${submitButton}</div>
${list}
</div>`;
}

} else if (itemSchema?.type === "object" && this.renderTable) {

const instanceThis = this;

function updateFunction(path, value = this.data) {
Expand Down Expand Up @@ -962,7 +956,6 @@ export class JSONSchemaInput extends LitElement {
});
};


const list = (this.#list = new List({
items: this.#mapToList(),

Expand Down
41 changes: 21 additions & 20 deletions src/renderer/src/stories/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import searchSVG from "./assets/search.svg?raw";
import tippy from "tippy.js";
import { unsafeHTML } from "lit/directives/unsafe-html.js";


const ALTERNATIVE_MODES = ["input", "append"];

export class Search extends LitElement {
Expand Down Expand Up @@ -35,7 +34,7 @@ export class Search extends LitElement {
if (this.listMode === "input" && this.getAttribute("interacted") === "true") {
this.setAttribute("interacted", false);
this.#onSelect(this.getSelectedOption());
} else if (this.listMode !== 'list') {
} else if (this.listMode !== "list") {
this.setAttribute("active", false);
}
};
Expand Down Expand Up @@ -109,7 +108,8 @@ export class Search extends LitElement {
overflow: auto;
}
:host([listmode="input"]) ul, :host([listmode="append"]) ul {
:host([listmode="input"]) ul,
:host([listmode="append"]) ul {
position: absolute;
top: 38px;
left: 0;
Expand Down Expand Up @@ -140,7 +140,8 @@ export class Search extends LitElement {
font-size: 60%;
}
:host([listmode="input"]) svg, :host([listmode="append"]) svg {
:host([listmode="input"]) svg,
:host([listmode="append"]) svg {
position: absolute;
top: 50%;
padding: 0px;
Expand Down Expand Up @@ -319,7 +320,7 @@ export class Search extends LitElement {
this.setAttribute("interacted", true);
};

#ignore = false
#ignore = false;

render() {
this.categories = {};
Expand Down Expand Up @@ -370,7 +371,7 @@ export class Search extends LitElement {

listItemElement.addEventListener("click", (clickEvent) => {
clickEvent.stopPropagation();
if (this.#ignore) return this.#ignore = false
if (this.#ignore) return (this.#ignore = false);
this.#onSelect(option);
});

Expand All @@ -382,9 +383,8 @@ export class Search extends LitElement {
label.classList.add("label");
label.innerText = option.label;


if (option.description || option.link) {
const info = option.link ? document.createElement('a') : document.createElement("span");
const info = option.link ? document.createElement("a") : document.createElement("span");
if (option.link) {
info.setAttribute("data-link", true);
info.href = option.link;
Expand All @@ -394,11 +394,12 @@ export class Search extends LitElement {
info.innerText = "ℹ️";
label.append(info);

if (option.description) tippy(info, {
content: `<p>${option.description}</p>`,
allowHTML: true,
placement: "right",
});
if (option.description)
tippy(info, {
content: `<p>${option.description}</p>`,
allowHTML: true,
placement: "right",
});
}

container.appendChild(label);
Expand Down Expand Up @@ -482,14 +483,14 @@ export class Search extends LitElement {
@blur=${(blurEvent) => {
const relatedTarget = blurEvent.relatedTarget;
if (relatedTarget) {
if (relatedTarget.classList.contains("option")) return;
if (relatedTarget.hasAttribute("data-link")) {
this.#ignore = true
return
}
}
if (relatedTarget.classList.contains("option")) return;
if (relatedTarget.hasAttribute("data-link")) {
this.#ignore = true;
return;
}
}
this.#close();
this.#close();
}}
></input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export async function autocompleteFormatString(path) {
}
}
} else {

if (!parent.path) return;
if (!value) return;

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/src/stories/pages/uploads/UploadsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ export async function createDandiset(results = {}) {
});

const updateNIHInput = (embargoed) => {
const nihInput = form.getFormElement([ "nih_award_number" ]);
const nihInput = form.getFormElement(["nih_award_number"]);

// Show the NIH input if embargo is set
if (embargoed) nihInput.removeAttribute("hidden");
else nihInput.setAttribute("hidden", "");

// Make the NIH input required if embargo is set
nihInput.required = embargoed;
}
};

const form = new JSONSchemaForm({
schema: dandiCreateSchema,
Expand All @@ -73,7 +73,7 @@ export async function createDandiset(results = {}) {
validateOnChange: async (name, parent) => {
const value = parent[name];

if (name === 'embargo_status') return updateNIHInput(value);
if (name === "embargo_status") return updateNIHInput(value);

if (name === "nih_award_number") {
if (value)
Expand All @@ -97,7 +97,7 @@ export async function createDandiset(results = {}) {

content.append(form);
modal.append(content);

modal.onClose = async () => notify("Dandiset was not created.", "error");

return new Promise((resolve) => {
Expand Down

0 comments on commit 384ac4a

Please sign in to comment.