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

#5078: support showing panel as popover #5023

Merged
merged 7 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = {
"@testing-library/jest-dom",
"webext-dynamic-content-scripts/including-active-tab", // Automatic registration
"regenerator-runtime/runtime", // Automatic registration
"@/vendors/hoverintent/hoverintent", // JQuery plugin
],
},
],
Expand Down
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"htmlparser2": "^8.0.0",
"http-status-codes": "^2.1.4",
"idb": "^7.1.1",
"iframe-resizer": "^4.3.2",
"immer": "^9.0.18",
"intro.js": "^6.0.0",
"is-promise": "^4.0.0",
Expand Down Expand Up @@ -185,6 +186,7 @@
"@types/gapi.client.sheets": "^4.0.20201030",
"@types/google.picker": "0.0.39",
"@types/holderjs": "^2.9.2",
"@types/iframe-resizer": "^3.5.9",
"@types/intro.js": "^5.1.0",
"@types/jest": "^29.2.6",
"@types/jquery": "^3.5.6",
Expand Down
1 change: 1 addition & 0 deletions scripts/webpack.scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = mergeWithShared({
// Exclude some troublesome/unnecessary dependencies
"webextension-polyfill": "{}",
rollbar: "{init(){}}",
"@/vendors/hoverintent/hoverintent": "{}",
},
resolve: {
// Mock any modules that appear in __mocks__
Expand Down
6 changes: 0 additions & 6 deletions src/baseRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export class Registry<
}

private notifyAll() {
console.debug(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logging is super noisy

"Notifying %d registry cache listener(s) for %s",
this.listeners.length,
[...this.kinds].join(", ")
);

for (const listener of this.listeners) {
listener.onCacheChanged();
}
Expand Down
123 changes: 84 additions & 39 deletions src/blocks/transformers/temporaryInfo/DisplayTemporaryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ import {
import { type PanelPayload } from "@/sidebar/types";
import {
stopWaitingForTemporaryPanels,
cancelTemporaryPanelsForExtension,
cancelTemporaryPanels,
waitForTemporaryPanel,
} from "@/blocks/transformers/temporaryInfo/temporaryPanelProtocol";
import { CancelError, PropError } from "@/errors/businessErrors";
import { BusinessError, CancelError, PropError } from "@/errors/businessErrors";
import { getThisFrame } from "webext-messenger";
import { showModal } from "@/blocks/transformers/ephemeralForm/modalUtils";
import { IS_ROOT_AWARE_BRICK_PROPS } from "@/blocks/rootModeHelpers";
import { showPopover } from "@/blocks/transformers/temporaryInfo/popoverUtils";

type Location = "panel" | "modal";
type Location = "panel" | "modal" | "popover";

export async function createFrameSource(
nonce: string,
Expand All @@ -62,6 +66,10 @@ class DisplayTemporaryInfo extends Transformer {
);
}

override async isRootAware(): Promise<boolean> {
return true;
}

inputSchema: Schema = {
type: "object",
properties: {
Expand All @@ -76,10 +84,11 @@ class DisplayTemporaryInfo extends Transformer {
},
location: {
type: "string",
enum: ["panel", "modal"],
enum: ["panel", "modal", "popover"],
default: "panel",
description: "The location of the information (default='panel')",
},
...IS_ROOT_AWARE_BRICK_PROPS,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking same approach as other PR for upgrading the brick to be root aware

},
required: ["body"],
};
Expand All @@ -89,65 +98,101 @@ class DisplayTemporaryInfo extends Transformer {
title,
body: bodyPipeline,
location = "panel",
isRootAware = false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safe default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the brick isRootAware() "safe default" true, but the transform() input param one is false?

Copy link
Contributor Author

@twschiller twschiller Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this PR for more details on the approach: #4910

The idea is that:

  • isRootAware is overridden so the runtime sees the brick as root aware
  • The brick exposes an isRootAware param, but it defaults to false in calls for backward compatability. It controls whether the brick actually considers the root or not in brick execution
  • In the JSONSchema, isRootAware defaults to "true", so new calls create in the Page Editor pass true
  • The Brick Configuration looks at the arg to determine which fields to show

}: BlockArg<{
title: string;
location: Location;
body: PipelineExpression;
isRootAware: boolean;
}>,
{
logger: {
context: { extensionId },
},
root,
ctxt,
runPipeline,
runRendererPipeline,
}: BlockOptions
): Promise<UnknownObject | null> {
expectContext("contentScript");

const target = isRootAware ? root : document;

const nonce = uuidv4();
const controller = new AbortController();

const payload = (await runRendererPipeline(bodyPipeline?.__value__ ?? [], {
key: "body",
counter: 0,
})) as PanelPayload;

if (location === "panel") {
await ensureSidebar();
const payload = (await runRendererPipeline(
bodyPipeline?.__value__ ?? [],
{
key: "body",
counter: 0,
},
{},
target
)) as PanelPayload;

switch (location) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to a "switch" statement. The whitespace in the diff is bad

case "panel": {
await ensureSidebar();

showTemporarySidebarPanel({
extensionId,
nonce,
heading: title,
payload,
});

window.addEventListener(
PANEL_HIDING_EVENT,
() => {
controller.abort();
},
{
signal: controller.signal,
}
);

controller.signal.addEventListener("abort", () => {
hideTemporarySidebarPanel(nonce);
void stopWaitingForTemporaryPanels([nonce]);
});

break;
}

showTemporarySidebarPanel({
extensionId,
nonce,
heading: title,
payload,
});
case "modal": {
const frameSource = await createFrameSource(nonce, location);
showModal(frameSource, controller);
break;
}

window.addEventListener(
PANEL_HIDING_EVENT,
() => {
controller.abort();
},
{
signal: controller.signal,
case "popover": {
const frameSource = await createFrameSource(nonce, location);
if (target === document) {
throw new BusinessError("Target must be an element for popover");
}
);

controller.signal.addEventListener("abort", () => {
hideTemporarySidebarPanel(nonce);
void stopWaitingForTemporaryPanels([nonce]);
});
} else if (location === "modal") {
const frameSource = await createFrameSource(nonce, location);
showModal(frameSource, controller);
} else {
throw new PropError(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- dynamic check for validated value
`Invalid location: ${location}`,
this.id,
"location",
location
);
await cancelTemporaryPanelsForExtension(extensionId);

const onHide = async () => {
await cancelTemporaryPanels([nonce]);
};

showPopover(frameSource, target as HTMLElement, onHide, controller);

break;
}

default: {
throw new PropError(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- dynamic check for validated value
`Invalid location: ${location}`,
this.id,
"location",
location
);
}
}

let result = null;
Expand Down
Loading