Skip to content

Commit

Permalink
Merge branch 'main' into disable-schema-props
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Nov 9, 2023
2 parents d28fdc4 + ec056cb commit e600a37
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/renderer/src/stories/JSONSchemaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ export class JSONSchemaForm extends LitElement {

const schema = this.schema ?? {};

this.resolved = merge(this.results, {}); // Track resolved values as a copy of the user-specified results
this.resolved = structuredClone(this.results); // Track resolved values as a copy of the user-specified results

// Register default properties
resolveProperties(schema.properties, this.resolved, this.globals);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/pages/FormPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class GuidedFormPage extends Page {
? this.info.globalStatePath.reduce((acc, key) => acc[key] ?? (acc[key] = {}), this.info.globalState)
: {};

const results = (this.localState = merge({ [key]: temp[key] ?? (temp[key] = {}) }, {})); // Keep a local copy of the results
const results = (this.localState = structuredClone({ [key]: temp[key] ?? (temp[key] = {}) })); // Keep a local copy of the results

const form = (this.form = new JSONSchemaForm({
...this.info.formOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class GuidedMetadataPage extends ManagedPage {
icon: globalIcon,
label: "Edit Global Metadata",
onClick: () => {
this.#globalModal.form.results = merge(this.info.globalState.project, {});
this.#globalModal.form.results = structuredClone(this.info.globalState.project);
this.#globalModal.open = true;
},
}),
Expand Down Expand Up @@ -230,7 +230,7 @@ export class GuidedMetadataPage extends ManagedPage {
render() {
this.#resetLoadState(); // Reset on each render

this.localState = { results: merge(this.info.globalState.results, {}) };
this.localState = { results: structuredClone(this.info.globalState.results ?? {}) };

this.forms = this.mapSessions(this.createForm, this.localState);

Expand Down Expand Up @@ -258,7 +258,7 @@ export class GuidedMetadataPage extends ManagedPage {
{
subject,
session,
globalState: merge(this.localState, merge(this.info.globalState, {})),
globalState: merge(this.localState, structuredClone(this.info.globalState)),
},
],
{ title: "Running conversion preview" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class GuidedSourceDataPage extends ManagedPage {
icon: globalIcon,
label: "Edit Global Source Data",
onClick: () => {
this.#globalModal.form.results = merge(this.info.globalState.project?.SourceData, {});
this.#globalModal.form.results = structuredClone(this.info.globalState.project.SourceData ?? {});
this.#globalModal.open = true;
},
}),
Expand Down Expand Up @@ -204,7 +204,7 @@ export class GuidedSourceDataPage extends ManagedPage {
}

render() {
this.localState = { results: merge(this.info.globalState.results, {}) };
this.localState = { results: structuredClone(this.info.globalState.results ?? {}) };

this.forms = this.mapSessions(this.createForm, this.localState);

Expand Down
10 changes: 10 additions & 0 deletions src/renderer/src/stories/pages/guided-mode/data/GuidedStructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ export class GuidedStructurePage extends Page {

beforeSave = async () => {
this.info.globalState.interfaces = { ...this.list.object };

// Remove extra interfaces from results
if (this.info.globalState.results) {
this.mapSessions(({ info }) => {
Object.keys(info.source_data).forEach((key) => {
if (!this.info.globalState.interfaces[key]) delete info.source_data[key];
})
})
}

await this.save(undefined, false); // Interrim save, in case the schema request fails
await this.getSchema();
};
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/pages/guided-mode/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function resolveGlobalOverrides(subject, globalState) {
const subjectMetadataCopy = { ...globalState.subjects[subject] };
delete subjectMetadataCopy.sessions; // Remove extra key from metadata

const overrides = merge(globalState.project, {}); // Copy project-wide metadata
const overrides = structuredClone(globalState.project ?? {}); // Copy project-wide metadata
merge(subjectMetadataCopy, overrides.Subject);

return overrides;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const emptyMessage = "No issues detected in these files!";
export class GuidedInspectorPage extends Page {
constructor(...args) {
super(...args);
this.style.height = "100%"; // Fix main section
Object.assign(this.style, {
display: 'flex',
flexDirection: 'column'
})
}

header = {
Expand Down Expand Up @@ -84,6 +89,9 @@ export class GuidedInspectorPage extends Page {
content: html`We suggest editing the Global Metadata on the <b>previous page</b> to fix any issues shared
across files.`,
})}
<br>
${until(
(async () => {
if (fileArr.length <= 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { html } from "lit";
import { JSONSchemaForm } from "../../../JSONSchemaForm.js";
import { Page } from "../../Page.js";
import { run } from "./utils.js";
import { onThrow } from "../../../../errors";
import { merge } from "../../utils.js";
import Swal from "sweetalert2";
Expand Down Expand Up @@ -65,7 +64,7 @@ export class GuidedUploadPage extends Page {
};

render() {
const state = (this.localState = merge(this.info.globalState.upload ?? { info: {} }, {}));
const state = (this.localState = structuredClone(this.info.globalState.upload ?? { info: {} }));

const promise = onServerOpen(async () => {
await fetch(new URL("cpus", baseUrl))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class GuidedSubjectsPage extends Page {
icon: globalIcon,
label: "Edit Global Metadata",
onClick: () => {
this.#globalModal.form.results = merge(this.info.globalState.project?.Subject, {});
this.#globalModal.form.results = structuredClone(this.info.globalState.project.Subject ?? {});
this.#globalModal.open = true;
},
}),
Expand Down Expand Up @@ -98,7 +98,7 @@ export class GuidedSubjectsPage extends Page {
}

render() {
const subjects = (this.localState = merge(this.info.globalState.subjects ?? {}, {}));
const subjects = (this.localState = structuredClone(this.info.globalState.subjects ?? {}));

// Ensure all the proper subjects are in the global state
const toHave = Object.keys(this.info.globalState.results);
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/src/stories/pages/settings/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@ export class SettingsPage extends Page {
};

beforeSave = async () => {
await this.form.validate();

const { resolved } = this.form;
setUndefinedIfNotDeclared(schema.properties, resolved);

merge(resolved, global.data);

global.save(); // Save the changes, even if invalid on the form
this.#openNotyf("Global settings changes saved", "success");
this.#openNotyf(`Global settings changes saved.`, "success");
};

render() {
this.localState = merge(global.data, {});

this.localState = structuredClone(global.data);

// NOTE: API Keys and Dandiset IDs persist across selected project
this.form = new JSONSchemaForm({
Expand Down
22 changes: 17 additions & 5 deletions src/renderer/src/stories/pages/uploads/UploadsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { onThrow } from "../../../errors";
const folderPathKey = "filesystem_paths";
import dandiUploadSchema from "../../../../../../schemas/dandi-upload.schema";
import dandiStandaloneSchema from "../../../../../../schemas/json/dandi/standalone.json";
const dandiSchema = merge(dandiStandaloneSchema, merge(dandiUploadSchema, {}), { arrays: true });

const dandiSchema = merge(dandiStandaloneSchema, merge(dandiUploadSchema, {}, { clone: true }), { arrays: true });

import { Button } from "../../Button.js";
import { global } from "../../../progress/index.js";
Expand Down Expand Up @@ -50,7 +51,8 @@ export async function uploadToDandi(info, type = "project" in info ? "project" :
const staging = isStaging(dandiset_id); // Automatically detect staging IDs

const whichAPIKey = staging ? "staging_api_key" : "main_api_key";
let api_key = global.data.DANDI?.api_keys?.[whichAPIKey];
const DANDI = global.data.DANDI
let api_key = DANDI?.api_keys?.[whichAPIKey];

const errors = await validateDANDIApiKey(api_key, staging);

Expand All @@ -64,7 +66,7 @@ export async function uploadToDandi(info, type = "project" in info ? "project" :

const input = new JSONSchemaInput({
path: [whichAPIKey],
info: dandiGlobalSchema.properties.api_keys.properties[whichAPIKey],
info: dandiGlobalSchema.properties.api_keys.properties[whichAPIKey]
});

input.style.padding = "25px";
Expand All @@ -78,7 +80,7 @@ export async function uploadToDandi(info, type = "project" in info ? "project" :
return (notification = this.notify(message, type));
};

modal.onClose = async () => notify("Your DANDI API key was not set", "error");
modal.onClose = async () => notify("The updated DANDI API key was not set", "error");

api_key = await new Promise((resolve) => {
const button = new Button({
Expand All @@ -90,7 +92,15 @@ export async function uploadToDandi(info, type = "project" in info ? "project" :
const errors = await validateDANDIApiKey(input.value, staging);
if (!errors || !errors.length) {
modal.remove();
global.data.DANDI.api_keys[whichAPIKey] = value;

merge({
DANDI: {
api_keys: {
[whichAPIKey]: value
}
}
}, global.data)

global.save();
resolve(value);
} else {
Expand All @@ -107,6 +117,8 @@ export async function uploadToDandi(info, type = "project" in info ? "project" :

document.body.append(modal);
});

console.log(api_key)
}

const result = await run(
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/src/stories/pages/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ export function merge(toMerge = {}, target = {}, mergeOpts = {}) {
for (const [k, v] of Object.entries(toMerge)) {
const targetV = target[k];
// if (isPrivate(k)) continue;
if (mergeOpts.arrays && Array.isArray(v) && Array.isArray(targetV))
target[k] = [...targetV, ...v]; // Merge array entries together
if (mergeOpts.arrays && Array.isArray(v) && Array.isArray(targetV)) target[k] = [...targetV, ...v]; // Merge array entries together
else if (v === undefined) {
delete target[k]; // Remove matched values
// if (mergeOpts.remove !== false) delete target[k]; // Remove matched values
} else if (isObject(v)) {
if (isObject(targetV)) target[k] = merge(v, targetV, mergeOpts);
else target[k] = v; // Replace object values
else {
if (mergeOpts.clone) target[k] = merge(v, {}, mergeOpts); // Replace primitive values
else target[k] = v; // Replace object values
}
} else target[k] = v; // Replace primitive values
}

Expand Down

0 comments on commit e600a37

Please sign in to comment.