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

Migrate preview-panel.js to Stimulus PreviewController #10356

Draft
wants to merge 61 commits into
base: main
Choose a base branch
from

Conversation

laymonage
Copy link
Member

@laymonage laymonage commented Apr 19, 2023

I've been playing around with Stimulus by refactoring the preview panel and I must say I quite enjoyed it! I think Stimulus fits nicely with our JavaScript use case in the front-end.

Fixes #9360 and adds some more optimisation by debouncing the update. It's still in draft as I have yet to write tests and do more testing.

Fixes #11677.

Please check the following:

  • Do the tests still pass?1
  • Does the code comply with the style guide?
    • Run make lint from the Wagtail root.
  • For Python changes: Have you added tests to cover the new/fixed behaviour?
  • For front-end changes: Did you test on all of Wagtail’s supported environments?2
    • Please list the exact browser and operating system versions you tested:
    • Please list which assistive technologies 3 you tested:
  • For new features: Has the documentation been updated accordingly?

Please describe additional details for testing this change.

Footnotes

  1. Development Testing

  2. Browser and device support

  3. Accessibility Target

@laymonage laymonage self-assigned this Apr 19, 2023
@laymonage laymonage added the component:Preview Page lives preview functionality, viewing drafts label Apr 19, 2023
@squash-labs
Copy link

squash-labs bot commented Apr 19, 2023

Manage this branch in Squash

Test this branch here: https://laymonagepreview-panel-control-s7sqa.squash.io

Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

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

One comment, happy to help will a full review later if that helps.

Super great to see another bit of Stimulus work, hopefully the code feels easier to manage this way.

client/src/controllers/PreviewPanelController.ts Outdated Show resolved Hide resolved
@laymonage laymonage changed the title Migrate preview-panel.js to Stimulus PreviewPanelController Migrate preview-panel.js to Stimulus PreviewController May 23, 2023
Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

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

A few more drive-by comments.

client/src/controllers/PreviewController.ts Show resolved Hide resolved
client/src/controllers/PreviewController.ts Outdated Show resolved Hide resolved
client/src/controllers/PreviewController.ts Outdated Show resolved Hide resolved
client/src/controllers/PreviewController.ts Outdated Show resolved Hide resolved
client/src/controllers/PreviewController.ts Outdated Show resolved Hide resolved
@laymonage
Copy link
Member Author

Thanks for the comments @lb-, I believe I've addressed those. I think this is only missing unit tests before it's ready for review, will try to write them over the week.

@lb-
Copy link
Member

lb- commented Jul 31, 2023

Thanks @laymonage - happy to do a full review when ready.

this.handlePreview();
}

connect() {
Copy link
Member

Choose a reason for hiding this comment

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

Not strict but it's nice to have the connect method at the top (after declaring properties), as it's kind of the entry point to the controller.

'newTabButton',
'spinner',
'modeSelect',
'iframe',
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking it may be good to streamline these target names, removing the element type from the reference name + keeps it shorter.

The fact that it's an input/button is probably a duplicate as the html elements that are the target will be these types.

static targets = [
    'size',
    'newTab',
    'spinner',
    'mode',
    'iframe',

Also, not strict, but we have been sorting these alphabetically in other controllers.

@lb-
Copy link
Member

lb- commented Aug 27, 2023

@laymonage I needed the Promise handling of the debounce for a different PR so brought it over (hope that's ok), also refined types and added a full unit test suite.

I have adjusted the behaviour for the wait arg so if it's a non-number it will immediately run the code, this is super useful for a pattern where a Stimulus value may set a delay/wait but if it does not we just want the code to run straight away.

#10835

@laymonage
Copy link
Member Author

No worries @lb-, thanks for making the debounce function feature-complete. I've reviewed that PR and will rebase this and drop the debounce commit once that's merged.

@gasman gasman modified the milestones: 5.2, 5.3 Oct 13, 2023
Without typing Promise and Promise.resolve with R, it defaults to
unknown, so the R generic type can't be used.

Also, the debounced function's args should take the generic A parameter
instead of redefining it as any[].
This allows the use of the button-longrunning handling for the loading state.

Also, turn the button into an icon-only button as there might not be enough space when the panel is resized to the smallest size
If the event is dispatched in the loop, then the show event may be
dispatched before the hide event is dispatched. For example, if you're
switching from the checks panel to the preview panel, as the preview
panel is ordered before the checks panel in the DOM.

This could cause an issue with the preview panel code, where we listen
for the show event to activate the auto update, and listen to the hide
event to deactivate it. We're listening to both the preview and checks
side panels.

Without this fix, the preview auto-update will get deactivated upon
switching from the checks panel to the preview panel, as the hide event
is dispatched after the show event.
Test loading the last device size from localStorage
This allows developers to more easily customise the panel, e.g. customising the device sizes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:Preview Page lives preview functionality, viewing drafts
Projects
Status: No status
Status: 🏗 In progress
5 participants