From 39bc950db2e2b7354d1b9285c6e91edcfa3aaf7d Mon Sep 17 00:00:00 2001 From: Garrett Date: Tue, 12 Sep 2023 16:15:05 -0700 Subject: [PATCH 1/7] 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 516b0e1c77d979383f20cb4fa2ad7f3d2e7fbe70 Mon Sep 17 00:00:00 2001 From: Garrett Date: Wed, 13 Sep 2023 10:55:22 -0700 Subject: [PATCH 2/7] 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 3/7] 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 4/7] 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 5/7] [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 6/7] 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 7/7] [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({