Skip to content

Commit

Permalink
Improve embargoing and license specification process
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Mar 8, 2024
1 parent 1109009 commit da607f8
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 44 deletions.
17 changes: 15 additions & 2 deletions schemas/json/dandi/create.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},

"embargo_status": {
"title": "Would you like to embargo this Dandiset?",
"type": "boolean",
"description": "Embargoed Dandisets are hidden from public access until a specific time period has elapsed. Uploading data to the DANDI archive under embargo requires a relevant NIH award number, and the data will be automatically published when the embargo period expires.",
"default": false
Expand All @@ -36,15 +37,27 @@

"license": {
"type": "array",
"description": "Provide a set of licenses for this Dandiset. If you are unsure which license to use, we recommend using the <a href='https://creativecommons.org/public-domain/cc0/' target='_blank'>CC0 1.0</a> license.",
"items": {
"type": "string",
"enumLinks": {
"spdx:CC0-1.0": "https://creativecommons.org/public-domain/cc0/",
"spdx:CC-BY-4.0": "https://creativecommons.org/licenses/by/4.0/deed.en"
},
"enumKeywords": {
"spdx:CC0-1.0": ["No Rights Reserved"],
"spdx:CC-BY-4.0": ["Attribution 4.0 International"]
},
"enumLabels": {
"spdx:CC0-1.0": "CC0 1.0",
"spdx:CC-BY-4.0": "CC BY 4.0"
},
"enum": [
"spdx:CC0-1.0",
"spdx:CC-BY-4.0"
]
},
"uniqueItems": true,
"description": "Licenses associated with the item. <br><small><b>Note:</b> DANDI only supports a subset of <a href='https://creativecommons.org' target='_blank'>Creative Commons Licenses</a> applicable to datasets</small>"
"uniqueItems": true
},

"nih_award_number": {
Expand Down
12 changes: 8 additions & 4 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,14 @@ export class JSONSchemaForm extends LitElement {

const value = parent[name];

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

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 @@ -879,7 +881,9 @@ 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
93 changes: 70 additions & 23 deletions src/renderer/src/stories/JSONSchemaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ export class JSONSchemaInput extends LitElement {
:host {
margin-top: 1.45rem;
display: block;
}
:host(.invalid) .guided--input {
Expand Down Expand Up @@ -489,6 +488,7 @@ export class JSONSchemaInput extends LitElement {
return {
schema: { type: Object, reflect: false },
validateEmptyValue: { type: Boolean, reflect: true },
required: { type: Boolean, reflect: true },
};
}

Expand All @@ -499,7 +499,7 @@ export class JSONSchemaInput extends LitElement {
// pattern
// showLabel
controls = [];
required = false;
// required;
validateOnChange = true;

constructor(props) {
Expand Down Expand Up @@ -848,24 +848,6 @@ export class JSONSchemaInput extends LitElement {
const allowPatternProperties = isPatternProperties(this.pattern);
const allowAdditionalProperties = isAdditionalProperties(this.pattern);

const addButton = new Button({
size: "small",
});

addButton.innerText = `Add ${canAddProperties ? "Property" : "Item"}`;

const buttonDiv = document.createElement("div");
Object.assign(buttonDiv.style, { width: "fit-content" });
buttonDiv.append(addButton);

const disableButton = ({ message, submessage }) => {
addButton.setAttribute("disabled", true);
tippy(buttonDiv, {
content: `<div style="padding: 10px;">${message} <br><small>${submessage}</small></div>`,
allowHTML: true,
});
};

// Provide default item types
if (isArray) {
const hasItemsRef = "items" in schema && "$ref" in schema.items;
Expand All @@ -874,11 +856,55 @@ 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 === "object" && this.renderTable) {
else if (itemSchema?.type === "string") {
console.error('JUST SEARCH STRINGS')

const list = new List({
items: this.value,
onChange: ({ items }) => {
this.#updateData(fullPath, items.length ? items.map((o) => o.value) : undefined);
if (validateOnChange) this.#triggerValidation(name, path);
},
});


const search = new Search({
options: itemSchema.enum.map((v) => {
return {
key: v,
value: v,
label: itemSchema.enumLabels?.[v] ?? v,
keywords: itemSchema.enumKeywords?.[v],
description: itemSchema.enumDescriptions?.[v],
link: itemSchema.enumLinks?.[v],
};
}),
value: this.value,
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 })
// search.value = ''
// search.requestUpdate()
},
});

list.classList.add("schema-input");

search.style.height = "auto";

console.log(search)

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

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

const instanceThis = this;

function updateFunction(path, value = this.data) {
Expand All @@ -897,6 +923,25 @@ export class JSONSchemaInput extends LitElement {
if (table) return table;
}

const addButton = new Button({
size: "small",
});

addButton.innerText = `Add ${canAddProperties ? "Property" : "Item"}`;

const buttonDiv = document.createElement("div");
Object.assign(buttonDiv.style, { width: "fit-content" });
buttonDiv.append(addButton);

const disableButton = ({ message, submessage }) => {
addButton.setAttribute("disabled", true);
tippy(buttonDiv, {
content: `<div style="padding: 10px;">${message} <br><small>${submessage}</small></div>`,
allowHTML: true,
});
};


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

Expand Down Expand Up @@ -965,6 +1010,8 @@ export class JSONSchemaInput extends LitElement {
category: schema.enumCategories?.[v],
label: schema.enumLabels?.[v] ?? v,
keywords: schema.enumKeywords?.[v],
description: schema.enumDescriptions?.[v],
link: schema.enumLinks?.[v],
};
});

Expand All @@ -978,7 +1025,7 @@ export class JSONSchemaInput extends LitElement {
keywords: schema.enumKeywords?.[this.value],
},
showAllWhenEmpty: false,
listMode: "click",
listMode: "input",
onSelect: async ({ value, key }) => {
const result = value ?? key;
this.#updateData(fullPath, result);
Expand Down
59 changes: 46 additions & 13 deletions src/renderer/src/stories/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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 {
constructor({
value,
Expand All @@ -25,13 +28,15 @@ export class Search extends LitElement {
this.headerStyles = headerStyles;
if (onSelect) this.onSelect = onSelect;

document.addEventListener("click", () => this.submit());
// document.addEventListener("click", () => this.#close());
}

submit = () => {
if (this.listMode === "click" && this.getAttribute("interacted") === "true") {
#close = () => {
if (this.listMode === "input" && this.getAttribute("interacted") === "true") {
this.setAttribute("interacted", false);
this.#onSelect(this.getSelectedOption());
} else if (this.listMode !== 'list') {
this.setAttribute("active", false);
}
};

Expand Down Expand Up @@ -104,7 +109,7 @@ export class Search extends LitElement {
overflow: auto;
}
:host([listmode="click"]) ul {
:host([listmode="input"]) ul, :host([listmode="append"]) ul {
position: absolute;
top: 38px;
left: 0;
Expand All @@ -125,7 +130,17 @@ export class Search extends LitElement {
height: 20px;
}
:host([listmode="click"]) svg {
a {
text-decoration: none;
}
a:after {
content: "🔗";
padding-left: 2px;
font-size: 60%;
}
:host([listmode="input"]) svg, :host([listmode="append"]) svg {
position: absolute;
top: 50%;
padding: 0px;
Expand Down Expand Up @@ -218,7 +233,8 @@ export class Search extends LitElement {
});

this.#initialize();
if (this.listMode !== "click") this.#populate();

if (!ALTERNATIVE_MODES.includes(this.listMode)) this.#populate();
}

onSelect = (id, value) => {};
Expand All @@ -230,7 +246,7 @@ export class Search extends LitElement {
#onSelect = (option) => {
const input = this.shadowRoot.querySelector("input");

if (this.listMode === "click") {
if (this.listMode === "input") {
input.value = this.#displayValue(option);
this.setAttribute("active", false);
return this.onSelect(option);
Expand Down Expand Up @@ -303,6 +319,8 @@ export class Search extends LitElement {
this.setAttribute("interacted", true);
};

#ignore = false

render() {
this.categories = {};

Expand Down Expand Up @@ -352,6 +370,7 @@ export class Search extends LitElement {

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

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

const info = document.createElement("span");

if (option.description) {
if (option.description || option.link) {
const info = option.link ? document.createElement('a') : document.createElement("span");
if (option.link) {
info.setAttribute("data-link", true);
info.href = option.link;
info.target = "_blank";
}

info.innerText = "ℹ️";
label.append(info);

tippy(info, {
if (option.description) tippy(info, {
content: `<p>${option.description}</p>`,
allowHTML: true,
placement: "right",
Expand Down Expand Up @@ -443,7 +468,7 @@ export class Search extends LitElement {
})}>
<input placeholder="Type here to search" value=${valueToDisplay} @click=${(clickEvent) => {
clickEvent.stopPropagation();
if (this.listMode === "click") {
if (ALTERNATIVE_MODES.includes(this.listMode)) {
const input = clickEvent.target.value;
this.#populate(input);
}
Expand All @@ -455,8 +480,16 @@ export class Search extends LitElement {
}}
@blur=${(blurEvent) => {
if (blurEvent.relatedTarget.classList.contains("option")) return;
this.submit();
const relatedTarget = blurEvent.relatedTarget;
if (relatedTarget) {
if (relatedTarget.classList.contains("option")) return;
if (relatedTarget.hasAttribute("data-link")) {
this.#ignore = true
return
}
}
this.#close();
}}
></input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ export async function autocompleteFormatString(path) {
}
}
} else {
if (!parent.path || !parent.path.includes(value))

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

if (!parent.path.includes(value))
return [
{
type: "error",
Expand Down
Loading

0 comments on commit da607f8

Please sign in to comment.