Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Appzi feedback form #606

Merged
merged 14 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -263,20 +268,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,
},
});

});


Expand Down
31 changes: 31 additions & 0 deletions src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,36 @@
<nwb-dashboard></nwb-dashboard>

<script type="module" src="./src/index"></script>
<script async src="https://w.appzi.io/w.js?token=hUmCm"></script>
<script defer>

let appziFeedbackWidget

function iframe(title) {
const iframes = Array.from(document.querySelectorAll('iframe')) // get all iframes
return Array.from(iframes).find((iframe) => iframe.title === title);
}

const interval = setInterval(() => {
const appziFeedbackButton = iframe('Feedback Button');
if (appziFeedbackButton) clearInterval(interval)
else return

appziFeedbackButton.contentWindow.document.querySelector('div').addEventListener('click', () => {
if (!appziFeedbackWidget) setTimeout(() => appziFeedbackWidget = iframe('Feedback Widget'), 200)
})

}, 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)
const message = "You have unsaved changes. Are you sure you want to leave?";
event.returnValue = message;
return message;
});

</script>

</body>
</html>
6 changes: 3 additions & 3 deletions src/renderer/src/stories/BasicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,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;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/DandiResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class DandiResults extends LitElement {
`;
}

constructor(props) {
constructor(props = {}) {
super();
Object.assign(this, props);
}
Expand Down
14 changes: 9 additions & 5 deletions src/renderer/src/stories/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -133,6 +129,14 @@ export class Dashboard extends LitElement {
}
};

window.history.pushState = function (state) {
pushPopListener({ state: state });
return pushState.apply(window.history, arguments);
};

window.addEventListener("popstate", pushPopListener);
window.addEventListener("pushstate", pushPopListener);

this.#updated();
}

Expand Down
12 changes: 6 additions & 6 deletions src/renderer/src/stories/JSONSchemaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ export class JSONSchemaInput extends LitElement {
// required;
validateOnChange = true;

constructor(props = {}) {
super();
Object.assign(this, props);
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
Expand All @@ -525,12 +531,6 @@ export class JSONSchemaInput extends LitElement {
return error;
};

constructor(props) {
super();
Object.assign(this, props);
if (props.validateEmptyValue === false) this.validateEmptyValue = true; // False is treated as required but not triggered if empty
}

// onUpdate = () => {}
// onValidate = () => {}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/OptionalSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class OptionalSection extends LitElement {

changed;

constructor(props) {
constructor(props = {}) {
super();
this.header = props.header ?? "";
this.description = props.description ?? "";
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/stories/SimpleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,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() {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/stories/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,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 ?? {}) };
}

getRowName = (row) =>
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/stories/preview/inspector/InspectorList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,7 +115,7 @@ export class InspectorListItem extends LitElement {
`;
}

constructor(props) {
constructor(props = {}) {
super();
this.ORIGINAL_TYPE = props.type;
Object.assign(this, props);
Expand Down
Loading