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

#3566: add support for switching active sidebar panel via brick; automatically switch when using Page Editor #3567

Merged
merged 7 commits into from Jun 6, 2022

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Jun 5, 2022

What does this PR do?

  • Closes Add support for switching the active sidebar panel via brick #3566
  • Add forcePanel and panelHeading options to the Show Sidebar brick
  • By default, the Show Sidebar brick will activate a panel from the current blueprint
  • User can also specify a panelHeading to match to activate
  • When rendering a panel via the Page Editor, switch over to that panel
  • When selecting an extension in the Page Editor, switch over to that panel
  • Keep a stable panel order in the sidebar (just based on sorting extensions UUIDs; non-intuitive, but it's stable)

Considerations/Discussion

  • In the future we might want to make panelHeading support a regex. Technically, panel headers can vary dynamically (templating over the reader for the panel). However, that's not currently possible with sidebar panels made with the Page Editor

Reviewer Notes

  • Take a look at sidebarController first. It's the module that handles the sidebar in the content script
  • Take a look at sidebarSlice next. It's the Redux slice for the Sidebar App
  • Take a look at SidebarApp.tsx. It has the listener bridge between the messenger/contentScript and the redux state

Tasks Remaining

  • Fix race condition in updateDynamicElement and show sidebar brick when trying to show a panel on initial load

Out of scope

  • Reduce/eliminate panel flickering

Checklist

  • Add tests
  • Designate a primary reviewer: @BALEHOK

@twschiller twschiller changed the title #3566: add support for switching active sidebar panel via brick #3566: [WIP] add support for switching active sidebar panel via brick Jun 5, 2022
@twschiller twschiller marked this pull request as draft June 5, 2022 17:43
@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2022

Codecov Report

Merging #3567 (0afbab4) into main (76ab769) will decrease coverage by 0.10%.
The diff coverage is 16.07%.

@@            Coverage Diff             @@
##             main    #3567      +/-   ##
==========================================
- Coverage   45.27%   45.16%   -0.11%     
==========================================
  Files         790      791       +1     
  Lines       23215    23293      +78     
  Branches     4819     4843      +24     
==========================================
+ Hits        10510    10521      +11     
- Misses      11823    11878      +55     
- Partials      882      894      +12     
Impacted Files Coverage Δ
src/blocks/effects/sidebar.ts 0.00% <0.00%> (ø)
src/contentScript/lifecycle.ts 0.00% <ø> (ø)
src/contentScript/messenger/registration.ts 0.00% <ø> (ø)
src/contentScript/nativeEditor/dynamic.ts 0.00% <0.00%> (ø)
src/core.ts 100.00% <ø> (ø)
src/pageEditor/sidebar/InstalledEntry.tsx 69.23% <0.00%> (-2.77%) ⬇️
src/sidebar/SidebarApp.tsx 0.00% <0.00%> (ø)
src/sidebar/messenger/registration.ts 0.00% <ø> (ø)
src/sidebar/protocol.tsx 0.00% <0.00%> (ø)
src/sidebar/sidebarSlice.ts 0.00% <0.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76ab769...0afbab4. Read the comment docs.

@twschiller twschiller changed the title #3566: [WIP] add support for switching active sidebar panel via brick #3566: add support for switching active sidebar panel via brick Jun 5, 2022
@twschiller twschiller added this to the 1.6.5 milestone Jun 5, 2022
@twschiller twschiller requested a review from BLoe June 5, 2022 18:52
@twschiller twschiller self-assigned this Jun 5, 2022
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export function getHTMLElement(): JQuery {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to a utility file because it's not specific to the sidebar

@twschiller twschiller marked this pull request as ready for review June 5, 2022 19:47
@twschiller twschiller changed the title #3566: add support for switching active sidebar panel via brick #3566: add support for switching active sidebar panel via brick; automatically switch when using Page Editor Jun 5, 2022
@twschiller twschiller requested review from BALEHOK and BLoe and removed request for BLoe June 6, 2022 00:05
@@ -133,6 +130,8 @@ export function showSidebar(callbacks = extensionCallbacks): string {

let nonce = container?.dataset?.nonce;

const isShowing = Boolean(nonce);

if (!nonce) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT:

Suggested change
if (!nonce) {
if (!isShowing) {

@@ -151,15 +150,57 @@ export function showSidebar(callbacks = extensionCallbacks): string {
}
}

if (!isEmpty(activateOptions)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why activateOptions can't be null by default? Then the check will be simpler:

Suggested change
if (!isEmpty(activateOptions)) {
if (activateOptions != null) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why activateOptions can't be null by default? Then the check will be simpler

I think keeping track of null vs. non-null is generally more error-prone. If there's a valid "empty"/default value I like to use that instead

);
});
}

// TODO: Drop `nonce` if not used by the caller
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 TODO still relevant?

Copy link
Contributor Author

@twschiller twschiller Jun 6, 2022

Choose a reason for hiding this comment

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

is this TODO still relevant?

Not sure, didn't want to spend the time double-checking all the call sites. It's not hurting anything to leave the value in

@@ -29,7 +29,7 @@ import {
hideSidebarForm,
PANEL_HIDING_EVENT,
showSidebarForm,
} from "@/contentScript/sidebar";
} from "@/contentScript/sidebarController";
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@twschiller twschiller enabled auto-merge (squash) June 6, 2022 14:49
@twschiller twschiller merged commit fc8e3e3 into main Jun 6, 2022
@twschiller twschiller deleted the feature/3566-active-sidebar-panel branch June 6, 2022 14:54
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.

Add support for switching the active sidebar panel via brick
3 participants