Skip to content

Commit

Permalink
Merge branch 'main' into use_pyinstaller_spec_files_per_platform
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD authored Sep 14, 2023
2 parents 6e1e1ef + 752a093 commit bb32343
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 25 deletions.
3 changes: 2 additions & 1 deletion schemas/json/dandi/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br/><small><b>Note:</b> <a href='https://dandiarchive.org' target='_blank'>The main archive</a> and <a href='https://gui-staging.dandiarchive.org' target='_blank'>the staging (testing) server</a> have different API keys.</small>"
}
},
"required": ["api_key"]
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/src/stories/DandiResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/src/stories/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,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;

Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/stories/JSONSchemaForm.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaultSchema = {
test: {
type: "string",
default: true,
description: "This is a test description",
},
warn: {
type: "string",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/stories/JSONSchemaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
`;
}
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/stories/pages/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Page extends LitElement {
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({
Expand Down Expand Up @@ -95,6 +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.unsavedUpdates = false;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -47,21 +47,17 @@ 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

this.unsavedUpdates = true; // Ensure that this saves automatically

this.to(1);
},
};

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`<div style="text-align: center;"><p>Your conversion failed. Please try again.</p></div>`;

const { dandiset_id } = this.info.globalState.upload?.info ?? {};

return DandiResults({ id: dandiset_id, files: conversion });
return new DandiResults({ id: dandiset_id, files: conversion });
}
}

Expand Down
28 changes: 16 additions & 12 deletions src/renderer/src/stories/pages/uploads/UploadsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -31,18 +31,29 @@ export async function uploadToDandi(info) {
return this.to("settings");
}

return await run(
"upload/folder",
const result = await run(
type ? `upload/${type}` : "upload",
{
...info,
staging: isStaging(info.dandiset_id), // Automatically detect staging IDs
api_key,
},
{ title: "Uploading to DANDI" }
).catch((e) => {
this.notify(e.message, "error");
notyf.open({
type: "error",
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}`,
});

return result;
}

export class UploadsPage extends Page {
Expand All @@ -58,14 +69,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, { ...globalState });

if (results)
notyf.open({
type: "success",
message: `${globalState.nwb_folder_path} successfully uploaded to Dandiset ${globalState.dandiset_id}`,
});

await uploadToDandi.call(this, { ...global.data.uploads });
global.data.uploads = {};
global.save();

Expand Down

0 comments on commit bb32343

Please sign in to comment.