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

Persisted advanced controls area in Shields v2 #13985

Merged
merged 1 commit into from
Jul 5, 2022
Merged

Conversation

nullhook
Copy link
Contributor

@nullhook nullhook commented Jun 28, 2022

Resolves brave/brave-browser#23188

This PR utilizes the existing pref which was used on previous Shields version to keep the advanced controls area expanded.

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • Open browser
  • Visit a site and click the on the lion icon on the right in location bar
  • Click on "Advanced controls" button

After you've expanded once, you should be able to see the Advanced controls expanded by default in the following use cases:

  • In a new browser window instance
  • wait 2-3min idle so the current panel instance destroys and open a new one
  • restart the whole browser and see if advanced controls content is expanded

@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Jun 28, 2022
@@ -43,3 +47,18 @@ void ShieldsPanelHandler::GetPosition(GetPositionCallback callback) {
brave_browser_window_->GetShieldsBubbleRect().y());
std::move(callback).Run(vec);
}

void ShieldsPanelHandler::SetAdvancedViewEnabled(bool is_enabled) {
DCHECK(profile_);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

even though we have a check in an upper layer it doesn't hurt to have one here.

@nullhook nullhook requested a review from petemill June 28, 2022 08:25
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

Do you think we need to address the case where I open shields in 1 window, then open it in another window and expand advanced controls. When I return to shields in the first window the advanced controls will be collapsed? We'd need to either

  • observe the pref changed in the c++ and call a JS callback when it changes, or
  • fetch the pref when window visibility changes

What do you think @nullhook?

const toggleIsExpanded = () => {
setIsExpanded(prevState => {
const newState = !prevState
getPanelBrowserAPI().panelHandler.setAdvancedViewEnabled(newState)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be inside the callback to compute the state value? Seems weird. Possible performance impact though doesn't seem different to doing it outside the function.
On a similar note, do you even need the function, since toggleIsExpanded isn't memo-ized it'll always have access to the current value.

const newValue = !isExpanded
setIsExpanded(newValue)
getPanelBrowserAPI().panelHandler.setAdvancedViewEnabled(newValue)

Copy link
Contributor Author

@nullhook nullhook Jul 5, 2022

Choose a reason for hiding this comment

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

The state updater function accesses it's own previous state so I don't see any weirdness? but I do get what you did with closure. To keep it simple, i'll move the logic outside of state updater function.

@nullhook nullhook force-pushed the shields-btn-expand branch from 0293c1e to 86482e9 Compare July 5, 2022 17:20
@nullhook
Copy link
Contributor Author

nullhook commented Jul 5, 2022

Do you think we need to address the case where I open shields in 1 window, then open it in another window and expand advanced controls. When I return to shields in the first window the advanced controls will be collapsed? We'd need to either

  • observe the pref changed in the c++ and call a JS callback when it changes, or
  • fetch the pref when window visibility changes

What do you think @nullhook?

Good catch. I've added a visibility observer to solve this.

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@nullhook nullhook force-pushed the shields-btn-expand branch from 86482e9 to dce511b Compare July 5, 2022 18:14
@nullhook nullhook requested a review from petemill July 5, 2022 18:14
@@ -1,5 +1,6 @@
import * as React from 'react'
import getPanelBrowserAPI, { UIHandlerReceiver, SiteBlockInfo, SiteSettings } from '../api/panel_browser_api'
import { loadTimeData } from '../../../../common/loadTimeData'
Copy link
Member

Choose a reason for hiding this comment

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

note that you can use '$web-common/loadTimeData' for this path

Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

beautiful!

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@nullhook nullhook merged commit adbdb2f into master Jul 5, 2022
@nullhook nullhook deleted the shields-btn-expand branch July 5, 2022 23:18
@github-actions github-actions bot added this to the 1.43.x - Nightly milestone Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Persist "Advanced Controls" section in Shields v2 panel
3 participants