From b6efe657defbeab13c838ba5af1318197bd42e5d Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Thu, 8 Feb 2024 11:09:55 -0800 Subject: [PATCH 1/4] Add appzi and fix CORS --- src/main/main.ts | 14 +++++++++++--- src/renderer/index.html | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 84bf8ee7d..96160d7de 100755 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -263,20 +263,28 @@ function initialize() { const win = globals.mainWindow = new BrowserWindow(windowOptions); - // Avoid CORS for Dandiset creation + // Avoid CORS (for all requests) for Dandiset creation win.webContents.session.webRequest.onBeforeSendHeaders( (details, callback) => { callback({ requestHeaders: { Origin: '*', ...details.requestHeaders } }); }, ); + const accessControlHeader = 'Access-Control-Allow-Origin' + win.webContents.session.webRequest.onHeadersReceived((details, callback) => { - callback({ + + const accessHeader = [accessControlHeader, accessControlHeader.toLowerCase()].find(key => details.responseHeaders?.[key]) ?? accessControlHeader + const origins = details.responseHeaders?.[accessHeader] ?? [] + if (origins.includes("*")) return callback(details) + + return callback({ responseHeaders: { - 'Access-Control-Allow-Origin': ['*'], + [accessHeader]: ['*'], ...details.responseHeaders, }, }); + }); diff --git a/src/renderer/index.html b/src/renderer/index.html index 243b3af79..9d406a8ab 100755 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -32,5 +32,7 @@ + + From 728832f98b31eab51f4720968db9037417bc271a Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Tue, 12 Mar 2024 09:55:47 -0700 Subject: [PATCH 2/4] Update appzi token Co-authored-by: Ryan Ly --- src/renderer/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/index.html b/src/renderer/index.html index 9d406a8ab..e4aa0bbc9 100755 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -32,7 +32,7 @@ - + From 142224de90f0d8201ff8226921138cabd3d98081 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Tue, 12 Mar 2024 13:47:15 -0700 Subject: [PATCH 3/4] Avoid reloading on Appzi form submission --- src/main/main.ts | 5 ++++ src/renderer/index.html | 29 +++++++++++++++++++ src/renderer/src/stories/BasicTable.js | 6 ++-- src/renderer/src/stories/DandiResults.js | 2 +- src/renderer/src/stories/Dashboard.js | 14 +++++---- src/renderer/src/stories/JSONSchemaInput.js | 2 +- src/renderer/src/stories/OptionalSection.js | 2 +- src/renderer/src/stories/SimpleTable.js | 6 ++-- src/renderer/src/stories/Table.js | 4 +-- .../preview/inspector/InspectorList.js | 4 +-- 10 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index dd8a1bf62..02e20b985 100755 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -230,6 +230,11 @@ function initialize() { return { action: 'deny' }; }); + globals.mainWindow.webContents.on('will-prevent-unload', () => { + return true // Avoid page refresh on Appzi feedback form submission + }); + + // globals.mainWindow.webContents.once("dom-ready", () => { // if (updatechecked == false) { // autoUpdater.checkForUpdatesAndNotify(); diff --git a/src/renderer/index.html b/src/renderer/index.html index e4aa0bbc9..1898e8f86 100755 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -33,6 +33,35 @@ + diff --git a/src/renderer/src/stories/BasicTable.js b/src/renderer/src/stories/BasicTable.js index c56e8329e..d0f8e2675 100644 --- a/src/renderer/src/stories/BasicTable.js +++ b/src/renderer/src/stories/BasicTable.js @@ -139,10 +139,10 @@ export class BasicTable extends LitElement { return this.#schema; } - set schema(schema) { + set schema(schema = {}) { this.#schema = schema; - this.#itemSchema = schema.items; - this.#itemProps = { ...this.#itemSchema.properties }; + this.#itemSchema = schema.items ?? {}; + this.#itemProps = { ...this.#itemSchema.properties ?? {} }; } #rendered; diff --git a/src/renderer/src/stories/DandiResults.js b/src/renderer/src/stories/DandiResults.js index bf5c67312..3ece28b9e 100644 --- a/src/renderer/src/stories/DandiResults.js +++ b/src/renderer/src/stories/DandiResults.js @@ -12,7 +12,7 @@ export class DandiResults extends LitElement { `; } - constructor(props) { + constructor(props = {}) { super(); Object.assign(this, props); } diff --git a/src/renderer/src/stories/Dashboard.js b/src/renderer/src/stories/Dashboard.js index 6099785f9..9d4f897ec 100644 --- a/src/renderer/src/stories/Dashboard.js +++ b/src/renderer/src/stories/Dashboard.js @@ -117,12 +117,8 @@ export class Dashboard extends LitElement { // Handle all pop and push state updates const pushState = window.history.pushState; - window.history.pushState = function (state) { - if (typeof window.onpushstate == "function") window.onpushstate({ state: state }); - return pushState.apply(window.history, arguments); - }; - window.onpushstate = window.onpopstate = (popEvent) => { + const pushPopListener = (popEvent) => { if (popEvent.state) { const titleString = popEvent.state.title ?? popEvent.state.label; document.title = `${titleString} - ${this.name}`; @@ -131,8 +127,16 @@ export class Dashboard extends LitElement { if (page === this.page) return; // Do not rerender current page this.setMain(page); } + } + + window.history.pushState = function (state) { + pushPopListener({ state: state }); + return pushState.apply(window.history, arguments); }; + window.addEventListener("popstate", pushPopListener) + window.addEventListener("pushstate", pushPopListener) + this.#updated(); } diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index b9a884e34..7084b2024 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -502,7 +502,7 @@ export class JSONSchemaInput extends LitElement { required = false; validateOnChange = true; - constructor(props) { + constructor(props = {}) { super(); Object.assign(this, props); if (props.validateEmptyValue === false) this.validateEmptyValue = true; // False is treated as required but not triggered if empty diff --git a/src/renderer/src/stories/OptionalSection.js b/src/renderer/src/stories/OptionalSection.js index 0dcde2050..c207aee99 100644 --- a/src/renderer/src/stories/OptionalSection.js +++ b/src/renderer/src/stories/OptionalSection.js @@ -36,7 +36,7 @@ export class OptionalSection extends LitElement { changed; - constructor(props) { + constructor(props = {}) { super(); this.header = props.header ?? ""; this.description = props.description ?? ""; diff --git a/src/renderer/src/stories/SimpleTable.js b/src/renderer/src/stories/SimpleTable.js index 412483722..bd41b779b 100644 --- a/src/renderer/src/stories/SimpleTable.js +++ b/src/renderer/src/stories/SimpleTable.js @@ -867,10 +867,10 @@ export class SimpleTable extends LitElement { return this.#schema; } - set schema(schema) { + set schema(schema = {}) { this.#schema = schema; - this.#itemSchema = this.#schema.items; - this.#itemProps = { ...this.#itemSchema.properties }; + this.#itemSchema = this.#schema.items ?? {}; + this.#itemProps = { ...this.#itemSchema.properties ?? {} }; } render() { diff --git a/src/renderer/src/stories/Table.js b/src/renderer/src/stories/Table.js index ec956b466..c5abbc149 100644 --- a/src/renderer/src/stories/Table.js +++ b/src/renderer/src/stories/Table.js @@ -211,8 +211,8 @@ export class Table extends LitElement { set schema(schema) { this.#schema = schema; - this.#itemSchema = schema.items; - this.#itemProps = { ...this.#itemSchema.properties }; + this.#itemSchema = schema.items ?? {}; + this.#itemProps = { ...this.#itemSchema.properties ?? {} }; } updated() { diff --git a/src/renderer/src/stories/preview/inspector/InspectorList.js b/src/renderer/src/stories/preview/inspector/InspectorList.js index 5af09fc02..8f4aee9fd 100644 --- a/src/renderer/src/stories/preview/inspector/InspectorList.js +++ b/src/renderer/src/stories/preview/inspector/InspectorList.js @@ -43,7 +43,7 @@ export class InspectorList extends List { ]; } - constructor(props) { + constructor(props = {}) { const { items } = props; const aggregatedItems = Object.values(aggregateMessages(items)).map((items) => { const aggregate = { ...items.pop() }; // Create a base object for the aggregation @@ -115,7 +115,7 @@ export class InspectorListItem extends LitElement { `; } - constructor(props) { + constructor(props = {}) { super(); this.ORIGINAL_TYPE = props.type; Object.assign(this, props); From fb18efb75e00af69b7b24e5ff006edb111caee57 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:51:15 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/renderer/index.html | 2 +- src/renderer/src/stories/BasicTable.js | 2 +- src/renderer/src/stories/Dashboard.js | 6 +++--- src/renderer/src/stories/JSONSchemaInput.js | 1 - src/renderer/src/stories/SimpleTable.js | 2 +- src/renderer/src/stories/Table.js | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/renderer/index.html b/src/renderer/index.html index 1898e8f86..95ed7325b 100755 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -52,7 +52,7 @@ }) }, 100) - + window.addEventListener('beforeunload', (ev) => { const isOpen = appziFeedbackWidget ? ! appziFeedbackWidget.parentElement.parentElement.classList.length : false if (!isOpen) return // Allow reload if feedback widget is closed (e.g. hot reloading) diff --git a/src/renderer/src/stories/BasicTable.js b/src/renderer/src/stories/BasicTable.js index d0f8e2675..2582ec1d6 100644 --- a/src/renderer/src/stories/BasicTable.js +++ b/src/renderer/src/stories/BasicTable.js @@ -142,7 +142,7 @@ export class BasicTable extends LitElement { set schema(schema = {}) { this.#schema = schema; this.#itemSchema = schema.items ?? {}; - this.#itemProps = { ...this.#itemSchema.properties ?? {} }; + this.#itemProps = { ...(this.#itemSchema.properties ?? {}) }; } #rendered; diff --git a/src/renderer/src/stories/Dashboard.js b/src/renderer/src/stories/Dashboard.js index 9d4f897ec..554b3bccc 100644 --- a/src/renderer/src/stories/Dashboard.js +++ b/src/renderer/src/stories/Dashboard.js @@ -127,15 +127,15 @@ export class Dashboard extends LitElement { if (page === this.page) return; // Do not rerender current page this.setMain(page); } - } + }; window.history.pushState = function (state) { pushPopListener({ state: state }); return pushState.apply(window.history, arguments); }; - window.addEventListener("popstate", pushPopListener) - window.addEventListener("pushstate", pushPopListener) + window.addEventListener("popstate", pushPopListener); + window.addEventListener("pushstate", pushPopListener); this.#updated(); } diff --git a/src/renderer/src/stories/JSONSchemaInput.js b/src/renderer/src/stories/JSONSchemaInput.js index 3fac81d03..304d90afa 100644 --- a/src/renderer/src/stories/JSONSchemaInput.js +++ b/src/renderer/src/stories/JSONSchemaInput.js @@ -511,7 +511,6 @@ export class JSONSchemaInput extends LitElement { if (props.validateEmptyValue === false) this.validateEmptyValue = true; // False is treated as required but not triggered if empty } - // Print the default value of the schema if not caught onUncaughtSchema = (schema) => { // In development, show uncaught schemas diff --git a/src/renderer/src/stories/SimpleTable.js b/src/renderer/src/stories/SimpleTable.js index bd41b779b..7544eb08d 100644 --- a/src/renderer/src/stories/SimpleTable.js +++ b/src/renderer/src/stories/SimpleTable.js @@ -870,7 +870,7 @@ export class SimpleTable extends LitElement { set schema(schema = {}) { this.#schema = schema; this.#itemSchema = this.#schema.items ?? {}; - this.#itemProps = { ...this.#itemSchema.properties ?? {} }; + this.#itemProps = { ...(this.#itemSchema.properties ?? {}) }; } render() { diff --git a/src/renderer/src/stories/Table.js b/src/renderer/src/stories/Table.js index c5abbc149..92b4c514d 100644 --- a/src/renderer/src/stories/Table.js +++ b/src/renderer/src/stories/Table.js @@ -212,7 +212,7 @@ export class Table extends LitElement { set schema(schema) { this.#schema = schema; this.#itemSchema = schema.items ?? {}; - this.#itemProps = { ...this.#itemSchema.properties ?? {} }; + this.#itemProps = { ...(this.#itemSchema.properties ?? {}) }; } updated() {