From fc84ec33bf35893b2df248ceb7f8645e8987413a Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 7 Sep 2023 11:24:17 -0700 Subject: [PATCH 01/12] Ensure pages always save once --- src/renderer/src/stories/Dashboard.js | 3 +++ src/renderer/src/stories/pages/Page.js | 4 +++- .../src/stories/pages/guided-mode/data/GuidedStructure.js | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/stories/Dashboard.js b/src/renderer/src/stories/Dashboard.js index 3d3240331..68a3c01a3 100644 --- a/src/renderer/src/stories/Dashboard.js +++ b/src/renderer/src/stories/Dashboard.js @@ -229,10 +229,13 @@ export class Dashboard extends LitElement { pageState = state.pages[id] = { visited: false, active: false, + saved: false, pageLabel: page.info.label, pageTitle: page.info.title, }; + info.states =pageState + state.active = false; pageState.active = false; diff --git a/src/renderer/src/stories/pages/Page.js b/src/renderer/src/stories/pages/Page.js index bbcc0d0a6..3eb6b1e45 100644 --- a/src/renderer/src/stories/pages/Page.js +++ b/src/renderer/src/stories/pages/Page.js @@ -63,8 +63,9 @@ export class Page extends LitElement { to = async (transition) => { this.beforeTransition(); + // Otherwise note unsaved updates if present - if (this.unsavedUpdates) { + if (this.unsavedUpdates || this.info.states?.saved) { if (transition === 1) await this.save(); // Save before a single forward transition else { Swal.fire({ @@ -95,6 +96,7 @@ export class Page extends LitElement { save = async (overrides, runBeforeSave = true) => { if (runBeforeSave) await this.beforeSave(); save(this, overrides); + this.info.states.saved = true this.unsavedUpdates = false; }; diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js index 93938a8ca..5b32d2821 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js @@ -75,6 +75,8 @@ export class GuidedStructurePage extends Page { }; async updated() { + + console.log(this.info) const selected = this.info.globalState.interfaces; if (Object.keys(selected).length > 0) this.list.emptyMessage = "Loading valid interfaces..."; From 75c85e7a96601fc60387da5cb20a675189b210cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 18:29:24 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/Dashboard.js | 2 +- src/renderer/src/stories/pages/Page.js | 3 +-- .../src/stories/pages/guided-mode/data/GuidedStructure.js | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/stories/Dashboard.js b/src/renderer/src/stories/Dashboard.js index 68a3c01a3..a75846ca6 100644 --- a/src/renderer/src/stories/Dashboard.js +++ b/src/renderer/src/stories/Dashboard.js @@ -234,7 +234,7 @@ export class Dashboard extends LitElement { pageTitle: page.info.title, }; - info.states =pageState + info.states = pageState; state.active = false; pageState.active = false; diff --git a/src/renderer/src/stories/pages/Page.js b/src/renderer/src/stories/pages/Page.js index 3eb6b1e45..c4a52659b 100644 --- a/src/renderer/src/stories/pages/Page.js +++ b/src/renderer/src/stories/pages/Page.js @@ -63,7 +63,6 @@ export class Page extends LitElement { to = async (transition) => { this.beforeTransition(); - // Otherwise note unsaved updates if present if (this.unsavedUpdates || this.info.states?.saved) { if (transition === 1) await this.save(); // Save before a single forward transition @@ -96,7 +95,7 @@ export class Page extends LitElement { save = async (overrides, runBeforeSave = true) => { if (runBeforeSave) await this.beforeSave(); save(this, overrides); - this.info.states.saved = true + this.info.states.saved = true; this.unsavedUpdates = false; }; diff --git a/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js b/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js index 5b32d2821..d5f82e0a7 100644 --- a/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js +++ b/src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js @@ -75,8 +75,7 @@ export class GuidedStructurePage extends Page { }; async updated() { - - console.log(this.info) + console.log(this.info); const selected = this.info.globalState.interfaces; if (Object.keys(selected).length > 0) this.list.emptyMessage = "Loading valid interfaces..."; From ad6f4fc0d81302d62ca7125e2ad93c25035527ef Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 7 Sep 2023 16:08:51 -0700 Subject: [PATCH 03/12] Add instructions to DANDI api_key input --- schemas/json/dandi/global.json | 3 ++- src/renderer/src/stories/JSONSchemaForm.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/schemas/json/dandi/global.json b/schemas/json/dandi/global.json index 15ad771c0..c58151ee7 100644 --- a/schemas/json/dandi/global.json +++ b/schemas/json/dandi/global.json @@ -2,7 +2,8 @@ "properties": { "api_key": { "type": "string", - "format": "password" + "format": "password", + "description": "Log in to DANDI, click on your user initials in the top-right corner, and copy your API key from the resulting pop-up.
Note: Production and staging servers have different API keys and different logins" } }, "required": ["api_key"] diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index f16987160..0ffdd0fbe 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -1,4 +1,6 @@ import { LitElement, css, html } from "lit"; +import { unsafeHTML } from "lit/directives/unsafe-html.js"; + import { Accordion } from "./Accordion"; import { checkStatus } from "../validation"; @@ -424,7 +426,7 @@ export class JSONSchemaForm extends LitElement { ${interactiveInput} ${info.description ? html`

- ${capitalize(info.description)}${info.description.slice(-1)[0] === "." ? "" : "."} + ${unsafeHTML(capitalize(info.description))}${info.description.slice(-1)[0] === "." ? "" : "."}

` : ""}
From 39bc950db2e2b7354d1b9285c6e91edcfa3aaf7d Mon Sep 17 00:00:00 2001 From: Garrett Date: Tue, 12 Sep 2023 16:15:05 -0700 Subject: [PATCH 04/12] Update GuidedUpload.js --- .../src/stories/pages/guided-mode/options/GuidedUpload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js b/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js index d05b9bcd9..13987af4b 100644 --- a/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js +++ b/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js @@ -17,7 +17,7 @@ export class GuidedUploadPage extends Page { beforeSave = () => { const globalState = this.info.globalState; - const isNewDandiset = globalState.upload.dandiset_id !== this.localState.dandiset_id; + const isNewDandiset = globalState.upload?.dandiset_id !== this.localState.dandiset_id; merge({ upload: this.localState }, globalState); // Merge the local and global states if (isNewDandiset) delete globalState.upload.results; // Clear the preview results entirely if a new dandiset }; From e4cd9a47795f6dd4219fd9d39f898022e79404e0 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Wed, 13 Sep 2023 08:27:44 -0700 Subject: [PATCH 05/12] Update schemas/json/dandi/global.json Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- schemas/json/dandi/global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/json/dandi/global.json b/schemas/json/dandi/global.json index c58151ee7..c841a1cf8 100644 --- a/schemas/json/dandi/global.json +++ b/schemas/json/dandi/global.json @@ -3,7 +3,7 @@ "api_key": { "type": "string", "format": "password", - "description": "Log in to DANDI, click on your user initials in the top-right corner, and copy your API key from the resulting pop-up.
Note: Production and staging servers have different API keys and different logins" + "description": "Log in to DANDI, click on your user initials in the top-right corner, and copy your API key from the resulting pop-up.
Note: The main archive and the staging (testing) server have different API keys." } }, "required": ["api_key"] From 516b0e1c77d979383f20cb4fa2ad7f3d2e7fbe70 Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 13 Sep 2023 10:55:22 -0700 Subject: [PATCH 06/12] Fix upload url used for Guided Mode and break out staging determination --- .../pages/guided-mode/options/GuidedUpload.js | 6 ++--- .../guided-mode/results/GuidedResults.js | 7 +++--- .../src/stories/pages/uploads/UploadsPage.js | 24 +++++++++++-------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js b/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js index 13987af4b..213902f54 100644 --- a/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js +++ b/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js @@ -47,12 +47,12 @@ export class GuidedUploadPage extends Page { if (!result || !result.isConfirmed) return this.to(1); } - const results = await uploadToDandi.call(this, { + globalUploadInfo.results = await uploadToDandi.call(this, { ...globalUploadInfo.info, project: globalState.project.name, }); - globalUploadInfo.results = results; // Save the preview results + global.data.uploads = {}; this.unsavedUpdates = true; // Ensure that this saves automatically @@ -61,7 +61,7 @@ export class GuidedUploadPage extends Page { }; render() { - const state = (this.localState = merge(this.info.globalState.upload ?? { info: {}, results: null }, {})); + const state = (this.localState = merge(this.info.globalState.upload ?? { info: {} }, {})); this.form = new JSONSchemaForm({ schema: dandiUploadSchema, diff --git a/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js b/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js index fc3d64df2..17c27432b 100644 --- a/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js +++ b/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js @@ -2,6 +2,7 @@ import { css, html } from "lit"; import { Page } from "../../Page.js"; import { get } from "dandi"; +import { isStaging } from "../../uploads/UploadsPage.js"; export class GuidedResultsPage extends Page { constructor(...args) { @@ -23,15 +24,13 @@ export class GuidedResultsPage extends Page { } }; - const { dandiset_id, staging } = this.info.globalState.upload?.info ?? {}; + const { dandiset_id } = this.info.globalState.upload?.info ?? {}; const elIds = ["name", "modified"]; const otherElIds = ["embargo_status"]; - const liveId = dandiset_id; // '000552' // From Huszar - const isStaging = staging; //false - const dandiset = await get(liveId, isStaging ? "staging" : undefined); + const dandiset = await get(dandiset_id, isStaging(dandiset_id) ? "staging" : undefined); otherElIds.forEach((str) => handleId(str, dandiset)); elIds.forEach((str) => handleId(str, dandiset.draft_version)); diff --git a/src/renderer/src/stories/pages/uploads/UploadsPage.js b/src/renderer/src/stories/pages/uploads/UploadsPage.js index a21742392..2114c07b3 100644 --- a/src/renderer/src/stories/pages/uploads/UploadsPage.js +++ b/src/renderer/src/stories/pages/uploads/UploadsPage.js @@ -14,7 +14,9 @@ import { run } from "../guided-mode/options/utils.js"; import { notyf } from "../../../dependencies/globals.js"; import Swal from "sweetalert2"; -export async function uploadToDandi(info) { +export const isStaging = (id) => parseInt(id) >= 100000; // Automatically detect staging IDs + +export async function uploadToDandi(info, type = 'project' in info ? '' : "folder") { if (!global.data.DANDI?.api_key) { await Swal.fire({ title: "Your DANDI API key is not configured.", @@ -26,13 +28,21 @@ export async function uploadToDandi(info) { return this.to("settings"); } - info.staging = parseInt(info.dandiset_id) >= 100000; // Automatically detect staging IDs + info.staging = isStaging(info.dandiset_id); info.api_key = global.data.DANDI.api_key; - return await run("upload/folder", info, { title: "Uploading to DANDI" }).catch((e) => { + const result = await run(type ? `upload/${type}` : 'upload', info, { title: "Uploading to DANDI" }).catch((e) => { this.notify(e.message, "error"); throw e; }); + + + if (result) notyf.open({ + type: "success", + message: `${info.project ?? info.nwb_folder_path} successfully uploaded to Dandiset ${info.dandiset_id}`, + }); + + return result } export class UploadsPage extends Page { @@ -48,13 +58,7 @@ export class UploadsPage extends Page { label: defaultButtonMessage, onClick: async () => { await this.form.validate(); // Will throw an error in the callback - const results = await uploadToDandi.call(this, { ...global.data.uploads }); - if (results) - notyf.open({ - type: "success", - message: `${global.data.uploads.nwb_folder_path} successfully uploaded to Dandiset ${global.data.uploads.dandiset_id}`, - }); - + await uploadToDandi.call(this, { ...global.data.uploads }); global.data.uploads = {}; global.save(); this.requestUpdate(); From e0c8b77b1279bc57d5a6373608c5a23d3c8ba694 Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 13 Sep 2023 10:56:37 -0700 Subject: [PATCH 07/12] Update GuidedUpload.js --- .../src/stories/pages/guided-mode/options/GuidedUpload.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js b/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js index 213902f54..24a9c3f99 100644 --- a/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js +++ b/src/renderer/src/stories/pages/guided-mode/options/GuidedUpload.js @@ -52,10 +52,6 @@ export class GuidedUploadPage extends Page { project: globalState.project.name, }); - global.data.uploads = {}; - - this.unsavedUpdates = true; // Ensure that this saves automatically - this.to(1); }, }; From ea8d2776214ff714bb46e523c065ef8d81c3122c Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 13 Sep 2023 10:59:59 -0700 Subject: [PATCH 08/12] Update DandiResults.js --- src/renderer/src/stories/DandiResults.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/renderer/src/stories/DandiResults.js b/src/renderer/src/stories/DandiResults.js index 86cb1e29b..8f1c4cd52 100644 --- a/src/renderer/src/stories/DandiResults.js +++ b/src/renderer/src/stories/DandiResults.js @@ -36,8 +36,7 @@ export class DandiResults extends LitElement { const otherElIds = ["embargo_status"]; - const liveId = this.id; // '000552' // From Huszar - const dandiset = await get(liveId, isStaging(this.id) ? "staging" : undefined); + const dandiset = await get(this.id, isStaging(this.id) ? "staging" : undefined); otherElIds.forEach((str) => handleId(str, dandiset)); elIds.forEach((str) => handleId(str, dandiset.draft_version)); From a56b6939f4aa624aae1dcfde5c583a08709342dc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:00:16 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../src/stories/pages/uploads/UploadsPage.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/stories/pages/uploads/UploadsPage.js b/src/renderer/src/stories/pages/uploads/UploadsPage.js index 5ba0e8a9b..d141a438d 100644 --- a/src/renderer/src/stories/pages/uploads/UploadsPage.js +++ b/src/renderer/src/stories/pages/uploads/UploadsPage.js @@ -32,7 +32,7 @@ export async function uploadToDandi(info) { } const result = await run( - type ? `upload/${type}` : 'upload', + type ? `upload/${type}` : "upload", { ...info, staging: isStaging(info.dandiset_id), // Automatically detect staging IDs @@ -42,18 +42,18 @@ export async function uploadToDandi(info) { ).catch((e) => { notyf.open({ type: "error", - message: e.message - }) + message: e.message, + }); throw e; }); + if (result) + notyf.open({ + type: "success", + message: `${info.project ?? info.nwb_folder_path} successfully uploaded to Dandiset ${info.dandiset_id}`, + }); - if (result) notyf.open({ - type: "success", - message: `${info.project ?? info.nwb_folder_path} successfully uploaded to Dandiset ${info.dandiset_id}`, - }); - - return result + return result; } export class UploadsPage extends Page { From 97bd3133bf3ac78f85698506dff8a535766366fd Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 13 Sep 2023 11:03:24 -0700 Subject: [PATCH 10/12] Fix results page and type toggle after merge --- .../src/stories/pages/guided-mode/results/GuidedResults.js | 4 ++-- src/renderer/src/stories/pages/uploads/UploadsPage.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js b/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js index 43e5ad642..882041d34 100644 --- a/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js +++ b/src/renderer/src/stories/pages/guided-mode/results/GuidedResults.js @@ -9,14 +9,14 @@ export class GuidedResultsPage extends Page { } render() { - const { conversion } = this.info.globalState.conversion; + const { conversion } = this.info.globalState; if (!conversion) return html`

Your conversion failed. Please try again.

`; const { dandiset_id } = this.info.globalState.upload?.info ?? {}; - return DandiResults({ id: dandiset_id, files: conversion }); + return new DandiResults({ id: dandiset_id, files: conversion }); } } diff --git a/src/renderer/src/stories/pages/uploads/UploadsPage.js b/src/renderer/src/stories/pages/uploads/UploadsPage.js index 5ba0e8a9b..0f0f3f1a0 100644 --- a/src/renderer/src/stories/pages/uploads/UploadsPage.js +++ b/src/renderer/src/stories/pages/uploads/UploadsPage.js @@ -18,7 +18,7 @@ import { DandiResults } from "../../DandiResults.js"; export const isStaging = (id) => parseInt(id) >= 100000; -export async function uploadToDandi(info) { +export async function uploadToDandi(info, type = 'project' in info ? '' : 'folder') { const api_key = global.data.DANDI?.api_key; if (!api_key) { await Swal.fire({ From c2d076585a68607602913b522248897688458843 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:03:48 +0000 Subject: [PATCH 11/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/src/stories/pages/uploads/UploadsPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/src/stories/pages/uploads/UploadsPage.js b/src/renderer/src/stories/pages/uploads/UploadsPage.js index e4f7c3736..2e4691212 100644 --- a/src/renderer/src/stories/pages/uploads/UploadsPage.js +++ b/src/renderer/src/stories/pages/uploads/UploadsPage.js @@ -18,7 +18,7 @@ import { DandiResults } from "../../DandiResults.js"; export const isStaging = (id) => parseInt(id) >= 100000; -export async function uploadToDandi(info, type = 'project' in info ? '' : 'folder') { +export async function uploadToDandi(info, type = "project" in info ? "" : "folder") { const api_key = global.data.DANDI?.api_key; if (!api_key) { await Swal.fire({ From 37e1090e34477faaea3f74dc92cb3fe958637221 Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 13 Sep 2023 14:04:14 -0700 Subject: [PATCH 12/12] Fix merge --- src/renderer/src/stories/JSONSchemaForm.js | 5 ----- src/renderer/src/stories/JSONSchemaForm.stories.js | 1 + src/renderer/src/stories/JSONSchemaInput.js | 2 ++ 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/stories/JSONSchemaForm.js b/src/renderer/src/stories/JSONSchemaForm.js index 5f06e8627..aa2912722 100644 --- a/src/renderer/src/stories/JSONSchemaForm.js +++ b/src/renderer/src/stories/JSONSchemaForm.js @@ -416,11 +416,6 @@ export class JSONSchemaForm extends LitElement { > ${interactiveInput} - ${info.description - ? html`

- ${unsafeHTML(capitalize(info.description))}${info.description.slice(-1)[0] === "." ? "" : "."} -

` - : ""}
diff --git a/src/renderer/src/stories/JSONSchemaForm.stories.js b/src/renderer/src/stories/JSONSchemaForm.stories.js index 97dad2eb3..a59857ef8 100644 --- a/src/renderer/src/stories/JSONSchemaForm.stories.js +++ b/src/renderer/src/stories/JSONSchemaForm.stories.js @@ -22,6 +22,7 @@ const defaultSchema = { test: { type: "string", default: true, + description: "This is a test description", }, warn: { type: "string", diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index b6bfd37cd..fde0b43af 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -77,6 +77,8 @@ export class JSONSchemaInput extends LitElement { width: 100%; padding-top: 4px; color: dimgray !important; + margin: 0 0 1em; + line-height: 1.4285em; } `; }