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

#4464 temp render slice 1 #4584

Merged
merged 22 commits into from Nov 3, 2022
Merged

#4464 temp render slice 1 #4584

merged 22 commits into from Nov 3, 2022

Conversation

BLoe
Copy link
Collaborator

@BLoe BLoe commented Oct 31, 2022

What does this PR do?

Reviewer Tips

  • Start by looking at the new runRendererPipeline field on BlockOptions in core.ts
  • Look at the implementation of this function in reducePipeline.ts
  • Look at the new brick DisplayTemporaryInfo
  • If you want to follow through all the wiring up to the sidebar from there, it's probably easier to check out the branch and use your IDE, but it follows the exact same pattern as the regular panels, just with a x close button in the sidebar tab header

Demo

https://www.loom.com/share/5d663eb547954b26b01d2e4f8eb25b2c

Future Work

  • I think I want to take a shot at untangling some of the type dependencies soon...

Checklist

  • Add tests
  • Run Storybook and manually confirm that all stories are working
  • Designate a primary reviewer - @BALEHOK

@codecov
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Merging #4584 (98165f3) into main (5ca79ec) will increase coverage by 0.04%.
The diff coverage is 46.32%.

@@            Coverage Diff             @@
##             main    #4584      +/-   ##
==========================================
+ Coverage   50.87%   50.92%   +0.04%     
==========================================
  Files         916      917       +1     
  Lines       27183    27307     +124     
  Branches     5519     5533      +14     
==========================================
+ Hits        13830    13905      +75     
- Misses      12420    12465      +45     
- Partials      933      937       +4     
Impacted Files Coverage Δ
src/blocks/transformers/registerTransformers.ts 0.00% <0.00%> (ø)
...ponents/documentBuilder/render/DocumentContext.tsx 63.63% <0.00%> (-14.15%) ⬇️
src/contentScript/executor.ts 0.00% <0.00%> (ø)
src/contentScript/messenger/registration.ts 0.00% <ø> (ø)
src/contentScript/sidebarController.tsx 9.70% <0.00%> (-0.96%) ⬇️
src/core.ts 100.00% <ø> (ø)
src/development/headers.ts 0.00% <0.00%> (ø)
src/pageEditor/exampleExtensionConfig.ts 0.00% <ø> (ø)
src/sidebar/PanelBody.tsx 65.21% <0.00%> (-1.95%) ⬇️
src/sidebar/messenger/api.ts 100.00% <ø> (ø)
... and 17 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

rootOverride ?? root,
{
...options,
headless: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only important difference from the call in runPipeline above.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would comment on this in the code. Helpful for people coming back to it later

@@ -32,6 +32,7 @@ describe("parse compile error", () => {
root: null,
logger: new ConsoleLogger(),
runPipeline: neverPromise,
runRendererPipeline: neverPromise,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -53,6 +53,7 @@ describe("FormData block", () => {
logger: null,
root: null,
runPipeline: neverPromise,
runRendererPipeline: neverPromise,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -49,22 +49,33 @@ export type RendererError = {
* @see PanelEntry
* @see FormEntry
*/
export type EntryType = "panel" | "form";
export type EntryType = "panel" | "form" | "temporaryPanel";
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

state.temporaryPanels,
(x) => x.extensionId === panel.extensionId
);

Copy link
Contributor

@twschiller twschiller Nov 1, 2022

Choose a reason for hiding this comment

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

Not sure if it needs to be included in this PR or the next, but we need to call cancel on the other panels from the extension:

See equivalent behavior here for forms:
https://github.com/pixiebrix/pixiebrix-extension/pull/4584/files#diff-f38df102e6740716f2c8515f48e1aa4d043d02404c8b8e2cfbf4e4c0db041c8fR121

@@ -43,6 +44,7 @@ export type SidebarState = SidebarEntries & {
export const emptySidebarState: SidebarState = {
panels: [],
forms: [],
temporaryPanels: [],
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -113,3 +120,14 @@ export async function showForm(sequence: number, entry: FormEntry) {
export async function hideForm(sequence: number, nonce: UUID) {
runListeners("onHideForm", sequence, { nonce });
}

export async function showTemporaryPanel(
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

src/sidebar/Tabs.tsx Outdated Show resolved Hide resolved
@@ -81,12 +98,15 @@ const ConnectedSidebar: React.VFC = () => {
// Use ignoreApiError to avoid showing error on intermittent network issues or PixieBrix API degradation
ignoreApiError
>
{sidebarState.panels?.length || sidebarState.forms?.length ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -56,6 +57,11 @@ export function getSubPipelineFlavor(
return PipelineFlavor.NoEffect;
}

if (parentNodeId === DisplayTemporaryInfo.BLOCK_ID) {
// Temporary Info renderer shouldn't have side effects
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -21,7 +21,7 @@ import "./cryptoNodePolyfill.js";
import blockRegistry from "@/blocks/registry";

// Maintaining this number is a simple way to ensure bricks don't accidentally get dropped
const EXPECTED_HEADER_COUNT = 104;
const EXPECTED_HEADER_COUNT = 105;
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

if (blockId === DisplayTemporaryInfo.BLOCK_ID) {
return {
title: "Example info",
body: makePipelineExpression([createNewBlock(DocumentRenderer.BLOCK_ID)]),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

);

// Already using errors for control flow, keeping in this way for conciseness
// noinspection ExceptionCaughtLocallyJS
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a WebStorm thing?
Can it be disabled in a config rather than in code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's to suppress an IntelliJ inspection. I can turn off the inspection in project settings instead I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this is already used in sidebarExtension.ts - line 192 (where this logic is borrowed from), so I don't think it's that big a deal to leave it here as well.


// Already using errors for control flow, keeping in this way for conciseness
// noinspection ExceptionCaughtLocallyJS
throw new BusinessError("Pipeline does not include a renderer");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little bit confused. Does it throw in case when reducePipelineExpression successfully completes?

Copy link
Collaborator Author

@BLoe BLoe Nov 2, 2022

Choose a reason for hiding this comment

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

Yes, because that means the pipeline does not have a renderer, and this pipeline expects a renderer. It's definitely a little weird to use errors for control flow like this (hence the IDE warning), but it's already how it's done for regular sidebar panels in sidebarExtension.ts, so I'm using the same logic here.

} finally {
controller.abort();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer returning {} instead of undefined. Not a big deal since neither can be used, so returning a value in the future is not backward incompatible

* Resolve some temporary panels' deferred promises
* @param nonces The nonces of the panels to resolve
*/
export async function resolveTemporaryPanels(nonces: UUID[]) {
Copy link
Contributor

@twschiller twschiller Nov 3, 2022

Choose a reason for hiding this comment

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

NIT: I'd prefer this method name to refer to what the method does from a business perspective vs. the code perspective. E.g., what's the impact of resolving the temporary panels?

I think it's something to the effect of "closeTemporaryPanels" or "completeTemporaryPanels"?

"resolve" to me seems to only mean something in the world of promises

I guess this matches what we have for form though. So definitely just a thought/NIT...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I guess I was just trying to follow the way the form one is named. I agree it's not the greatest name though. I can change both names to something better.

Copy link
Collaborator Author

@BLoe BLoe Nov 3, 2022

Choose a reason for hiding this comment

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

The form function is named that way to distinguish between resolve and cancel I think, which both "close" the form.


panels.set(nonce, registration);

return registration.promise;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

resolveTemporaryPanels: jest.fn(),
}));

describe("DisplayTemporaryInfo", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

Copy link
Contributor

@twschiller twschiller left a comment

Choose a reason for hiding this comment

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

See comment on return value from the brick of undefined vs. {}

Excited to get this merged!

@twschiller twschiller added this to the 1.7.12 milestone Nov 3, 2022
@BLoe BLoe merged commit f3aba14 into main Nov 3, 2022
@BLoe BLoe deleted the feature/4464-temp-render-slice-1 branch November 3, 2022 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Temporary pop-up Slice 1: Add the “Display Temporary Information” brick
3 participants