-
Notifications
You must be signed in to change notification settings - Fork 22
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
#4464 temp render slice 1 #4584
Changes from all commits
bf4b2f7
e9f8aa9
0d67c08
12351c7
b7dd88b
6438fb7
ad8319e
d9759db
2f9c893
e8897b2
9d2ea02
699bb9f
c8c2f67
c2ac95e
dc59d4d
1ce4396
af91d9e
6ff8457
aa36d96
3391db3
a322daa
98165f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ describe("FormData block", () => { | |
logger: null, | ||
root: null, | ||
runPipeline: neverPromise, | ||
runRendererPipeline: neverPromise, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}); | ||
|
||
expect(result).toEqual({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ import TryExcept from "./controlFlow/TryExcept"; | |
import ForEachElement from "@/blocks/transformers/controlFlow/ForEachElement"; | ||
import { RandomNumber } from "@/blocks/transformers/randomNumber"; | ||
import Retry from "@/blocks/transformers/controlFlow/Retry"; | ||
import DisplayTemporaryInfo from "@/blocks/transformers/temporaryInfo/DisplayTemporaryInfo"; | ||
|
||
function registerTransformers() { | ||
registerBlock(new JQTransformer()); | ||
|
@@ -81,6 +82,9 @@ function registerTransformers() { | |
registerBlock(new TryExcept()); | ||
registerBlock(new ForEachElement()); | ||
registerBlock(new Retry()); | ||
|
||
// Render Pipelines | ||
registerBlock(new DisplayTemporaryInfo()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
export default registerTransformers; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (C) 2022 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import DisplayTemporaryInfo from "@/blocks/transformers/temporaryInfo/DisplayTemporaryInfo"; | ||
import blockRegistry from "@/blocks/registry"; | ||
import { | ||
simpleInput, | ||
teapotBlock, | ||
testOptions, | ||
throwBlock, | ||
} from "@/runtime/pipelineTests/pipelineTestHelpers"; | ||
import { makePipelineExpression } from "@/runtime/expressionCreators"; | ||
import { DocumentRenderer } from "@/blocks/renderers/document"; | ||
import { getExampleBlockConfig } from "@/pageEditor/exampleBlockConfigs"; | ||
import { reducePipeline } from "@/runtime/reducePipeline"; | ||
import { BusinessError } from "@/errors/businessErrors"; | ||
import { | ||
PanelPayload, | ||
RendererError, | ||
TemporaryPanelEntry, | ||
} from "@/sidebar/types"; | ||
import { showTemporarySidebarPanel } from "@/contentScript/sidebarController"; | ||
|
||
jest.mock("@/background/messenger/api", () => { | ||
const actual = jest.requireActual("@/background/messenger/api"); | ||
return { | ||
...actual, | ||
getLoggingConfig: jest.fn().mockResolvedValue({ | ||
logValues: true, | ||
}), | ||
}; | ||
}); | ||
|
||
jest.mock("@/contentScript/sidebarController", () => ({ | ||
ensureSidebar: jest.fn(), | ||
showTemporarySidebarPanel: jest.fn(), | ||
})); | ||
|
||
jest.mock("@/blocks/transformers/temporaryInfo/temporaryPanelProtocol", () => ({ | ||
waitForTemporaryPanel: jest.fn(), | ||
stopWaitingForTemporaryPanels: jest.fn(), | ||
})); | ||
|
||
describe("DisplayTemporaryInfo", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙌 |
||
const displayTemporaryInfoBlock = new DisplayTemporaryInfo(); | ||
const renderer = new DocumentRenderer(); | ||
|
||
beforeEach(() => { | ||
blockRegistry.clear(); | ||
blockRegistry.register( | ||
teapotBlock, | ||
throwBlock, | ||
renderer, | ||
displayTemporaryInfoBlock | ||
); | ||
}); | ||
|
||
test("it returns payload", async () => { | ||
const config = getExampleBlockConfig(renderer.id); | ||
const pipeline = { | ||
id: displayTemporaryInfoBlock.id, | ||
config: { | ||
title: "Test Temp Panel", | ||
body: makePipelineExpression([{ id: renderer.id, config }]), | ||
}, | ||
}; | ||
let payload: PanelPayload; | ||
(showTemporarySidebarPanel as jest.Mock).mockImplementation( | ||
(entry: TemporaryPanelEntry) => { | ||
payload = entry.payload; | ||
} | ||
); | ||
|
||
await reducePipeline(pipeline, simpleInput({}), testOptions("v3")); | ||
|
||
// Check structure for RendererPayload | ||
expect(payload).toHaveProperty("blockId", renderer.id); | ||
expect(payload).toHaveProperty("args"); | ||
expect(payload).toHaveProperty("ctxt"); | ||
}); | ||
|
||
test("it returns error", async () => { | ||
const message = "display info test error"; | ||
|
||
const pipeline = { | ||
id: displayTemporaryInfoBlock.id, | ||
config: { | ||
title: "Test Temp Panel", | ||
body: makePipelineExpression([ | ||
{ id: throwBlock.id, config: { message } }, | ||
{ id: renderer.id, config: getExampleBlockConfig(renderer.id) }, | ||
]), | ||
}, | ||
}; | ||
|
||
let payload: PanelPayload; | ||
(showTemporarySidebarPanel as jest.Mock).mockImplementation( | ||
(entry: TemporaryPanelEntry) => { | ||
payload = entry.payload; | ||
} | ||
); | ||
|
||
await reducePipeline(pipeline, simpleInput({}), testOptions("v3")); | ||
|
||
// Check structure for RendererError | ||
expect(payload).toHaveProperty("error"); | ||
const error = payload as RendererError; | ||
const errorMessage = (error.error as BusinessError).message; | ||
expect(errorMessage).toStrictEqual(message); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright (C) 2022 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { Transformer } from "@/types"; | ||
import { uuidv4, validateRegistryId } from "@/types/helpers"; | ||
import { BlockArg, BlockOptions, Schema } from "@/core"; | ||
import { PipelineExpression } from "@/runtime/mapArgs"; | ||
import { expectContext } from "@/utils/expectContext"; | ||
import { | ||
ensureSidebar, | ||
hideTemporarySidebarPanel, | ||
PANEL_HIDING_EVENT, | ||
showTemporarySidebarPanel, | ||
} from "@/contentScript/sidebarController"; | ||
import { PanelPayload } from "@/sidebar/types"; | ||
import { | ||
waitForTemporaryPanel, | ||
stopWaitingForTemporaryPanels, | ||
} from "@/blocks/transformers/temporaryInfo/temporaryPanelProtocol"; | ||
|
||
class DisplayTemporaryInfo extends Transformer { | ||
static BLOCK_ID = validateRegistryId("@pixiebrix/display"); | ||
defaultOutputKey = "infoOutput"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future, this will probably be something like "userResponse". This is OK for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, wasn't sure what to call this right now... |
||
|
||
constructor() { | ||
super( | ||
DisplayTemporaryInfo.BLOCK_ID, | ||
"Display Temporary Information", | ||
"A display title for the information, shown in the tab name" | ||
); | ||
} | ||
|
||
inputSchema: Schema = { | ||
type: "object", | ||
properties: { | ||
title: { | ||
type: "string", | ||
description: "A display title for the temporary document", | ||
BLoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
body: { | ||
$ref: "https://app.pixiebrix.com/schemas/pipeline#", | ||
description: "The render pipeline for the temporary document", | ||
}, | ||
}, | ||
required: ["body"], | ||
}; | ||
|
||
async transform( | ||
{ | ||
title, | ||
body: bodyPipeline, | ||
}: BlockArg<{ | ||
title: string; | ||
body: PipelineExpression; | ||
}>, | ||
{ | ||
logger: { | ||
context: { extensionId }, | ||
}, | ||
ctxt, | ||
runPipeline, | ||
runRendererPipeline, | ||
}: BlockOptions | ||
): Promise<unknown> { | ||
expectContext("contentScript"); | ||
|
||
const nonce = uuidv4(); | ||
const controller = new AbortController(); | ||
|
||
await ensureSidebar(); | ||
|
||
const payload = (await runRendererPipeline(bodyPipeline?.__value__ ?? [], { | ||
key: "body", | ||
counter: 0, | ||
})) as PanelPayload; | ||
|
||
showTemporarySidebarPanel({ | ||
extensionId, | ||
nonce, | ||
heading: title, | ||
payload, | ||
}); | ||
|
||
window.addEventListener( | ||
PANEL_HIDING_EVENT, | ||
() => { | ||
controller.abort(); | ||
}, | ||
{ | ||
signal: controller.signal, | ||
} | ||
); | ||
|
||
controller.signal.addEventListener("abort", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment here on expected behavior: https://github.com/pixiebrix/pixiebrix-extension/pull/4584/files#r1009988567 I think we want to await the abort signal (currently from the user clicking the |
||
hideTemporarySidebarPanel(nonce); | ||
void stopWaitingForTemporaryPanels([nonce]); | ||
}); | ||
|
||
try { | ||
await waitForTemporaryPanel(nonce); | ||
} finally { | ||
controller.abort(); | ||
} | ||
|
||
return {}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer returning |
||
} | ||
|
||
export default DisplayTemporaryInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍