From 155929451eff7c689daf6132708e661c39b0b4c7 Mon Sep 17 00:00:00 2001 From: Garrett Date: Fri, 27 Oct 2023 12:22:10 -0700 Subject: [PATCH 1/4] Fix global saving when undefined --- schemas/json/dandi/global.json | 2 +- schemas/json/dandi/upload.json | 2 +- .../stories/pages/settings/SettingsPage.js | 23 +++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/schemas/json/dandi/global.json b/schemas/json/dandi/global.json index 0daf4ef16..7b72776b5 100644 --- a/schemas/json/dandi/global.json +++ b/schemas/json/dandi/global.json @@ -11,7 +11,7 @@ "staging_api_key": { "type": "string", "format": "password", - "description": "Your DANDI API key from the staging (testing) server" + "description": "Your DANDI API key from the staging server" } }, "required": ["main_api_key"] diff --git a/schemas/json/dandi/upload.json b/schemas/json/dandi/upload.json index a7cfbb62a..0ee9b1431 100644 --- a/schemas/json/dandi/upload.json +++ b/schemas/json/dandi/upload.json @@ -2,7 +2,7 @@ "properties": { "dandiset_id": { "type": "string", - "description": "The unique identifier for your dandiset. Will automatically determine whether to upload to the main DANDI archive or the development staging server." + "description": "The unique identifier for your dandiset, manually created on the main archive or staging server." }, "cleanup": { "type": "boolean", diff --git a/src/renderer/src/stories/pages/settings/SettingsPage.js b/src/renderer/src/stories/pages/settings/SettingsPage.js index c65617574..6b82481c5 100644 --- a/src/renderer/src/stories/pages/settings/SettingsPage.js +++ b/src/renderer/src/stories/pages/settings/SettingsPage.js @@ -21,9 +21,9 @@ import { header } from "../../forms/utils"; const dandiAPITokenRegex = /^[a-f0-9]{40}$/; -const setUndefinedIfNotDeclared = (schema, resolved) => { - for (let prop in schema.properties) { - const propInfo = schema.properties[prop]; +const setUndefinedIfNotDeclared = (schemaProps, resolved) => { + for (const prop in schemaProps) { + const propInfo = schemaProps[prop]?.properties; if (propInfo) setUndefinedIfNotDeclared(propInfo, resolved[prop]); else if (!(prop in resolved)) resolved[prop] = undefined; } @@ -46,15 +46,18 @@ export class SettingsPage extends Page { return (this.#notification = this.notify(message, type)); }; - beforeSave = () => { + beforeSave = async () => { + + await this.form.validate() + const { resolved } = this.form; - for (let prop in schema.properties) { - const propInfo = schema.properties[prop]; - const res = resolved[prop]; - if (propInfo) setUndefinedIfNotDeclared(propInfo, res); - } + setUndefinedIfNotDeclared(schema.properties, resolved); + + + console.log('Merging', resolved, global.data ) + - merge(this.form.resolved, global.data); + merge(resolved, global.data); global.save(); // Save the changes, even if invalid on the form this.#openNotyf("Global settings changes saved", "success"); From 6470973a818bfd823d01b8c212f1b014ed3eb210 Mon Sep 17 00:00:00 2001 From: Garrett Date: Fri, 27 Oct 2023 13:21:11 -0700 Subject: [PATCH 2/4] Update DANDI api key presentation and validation --- src/renderer/src/stories/Modal.ts | 10 ++- .../guided-mode/options/GuidedStubPreview.js | 4 + .../guided-mode/results/GuidedResults.js | 2 + .../stories/pages/settings/SettingsPage.js | 13 +--- .../src/stories/pages/uploads/UploadsPage.js | 74 +++++++++++++++++-- .../preview/inspector/InspectorList.js | 5 +- src/renderer/src/validation/dandi.ts | 19 +++++ 7 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 src/renderer/src/validation/dandi.ts diff --git a/src/renderer/src/stories/Modal.ts b/src/renderer/src/stories/Modal.ts index 83363090f..8edc06309 100644 --- a/src/renderer/src/stories/Modal.ts +++ b/src/renderer/src/stories/Modal.ts @@ -12,6 +12,7 @@ export interface ModalProps { showCloseButton?: boolean, width?: string height?: string + closeText?: string } export class Modal extends LitElement { @@ -128,6 +129,10 @@ export class Modal extends LitElement { height: { type: String, reflext: true + }, + closeText: { + type: String, + reflect: true } }; } @@ -141,6 +146,8 @@ export class Modal extends LitElement { declare width: ModalProps['width'] declare height: ModalProps['height'] + declare closeText: ModalProps['closeText'] + constructor(props: ModalProps = {}) { super(); @@ -150,6 +157,7 @@ export class Modal extends LitElement { this.onClose = props.onClose this.onOpen = props.onOpen this.showCloseButton = props.showCloseButton ?? true + this.closeText = props.closeText this.width = props.width this.height = props.height @@ -173,7 +181,7 @@ export class Modal extends LitElement {