Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Add compact bravery panel with Aphrodite #8990

Merged
merged 4 commits into from
May 23, 2017
Merged

Add compact bravery panel with Aphrodite #8990

merged 4 commits into from
May 23, 2017

Conversation

luixxiul
Copy link
Contributor

@luixxiul luixxiul commented May 21, 2017

Closes #8954: Add compact bravery panel with Aphrodite
Closes #8913: Refactor braveryPanel with Aphrodite
Closes #5726: The bravery panel should be much wider
Fixes #8953: Align 'Reload' text and icon
Fixes #8952: Set opacity to FormDropdown's wrappers and their titles
Fixes #8949: Rename 'general.blocked-count-badge' to 'shields.blocked-count-badge'
Addresses #7989: Refactor forms.less with Aphrodite
Addresses #7321: Refactor switchControl

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Test plan 1:

  1. Run tests locally; npm run test -- --grep='Bravery Panel'
  2. Open about:preferences#shields
  3. Enable the compact panel option
  4. Run manual tests described here: https://github.com/brave/browser-laptop/wiki/Manual-Tests#bravery-settings

Test Plan 2:

  1. Open about:preferences#shields
  2. Make sure 'Display block count badge on shields button' works

Test Plan 3:

  1. Open about:styles
  2. Click "Dropdowns"
  3. Make sure BraveryPanelDropdown is displayed

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

Suguru Hirahara added 3 commits May 22, 2017 01:59
Closes #8954

Fixes #8953: Align 'Reload' text and icon
Fixes #8952: Set opacity to FormDropdown's wrappers and their titles
Fixes #8949: Rename 'general.blocked-count-badge' to 'shields.blocked-count-badge'
Closes #5726: The bravery panel should be much wider
Addresses #8913: Refactor braveryPanel.js with Aphrodite
Addresses #7989: Refactor forms.less with Aphrodite

----

Replace display:flex with display:grid (grid makes it easier than flex to place elements)

Reorganize styles
- braveryPanelHeader
- braveryPanelStats
- braveryPanelBody
- controlWrapper

Based on Cezar's feedback
- Replace '.braveryPanelBody li' with braveryPanelBodyList
- Move data-l10n-id
- Move 'large' inside SwitchControl
- Create compactBraveryHeader and defaultBraveryPanelHeader

Also:
- BEM optimization
- Introduce 'gridStyles'
- Remove redundant divs and div wrappers from counters
- Update tests

Test plan
1. Run tests locally; npm run test -- --grep='Bravery Panel'
2. Open about:preferences#shields
3. Enable the compact panel option
4. Run manual tests described here: https://github.com/brave/browser-laptop/wiki/Manual-Tests#bravery-settings

Test Plan 2:
1. Open about:preferences#shields
2. Make sure 'Display block count badge on shields button' works
Closes #8913

Also:
- Add no-important to Aphrodite
- Add shields settings to state.md
- Remove .trackersBlockedStat which has not been used
- Create BraveryPanelDropdown
- Add BraveryPanelDropdown to about:styles

Addresses #7321: Refactor switchControl
- customWrapper
- customTopText
- customInfoButton

Remove reduntant classNames by replacing cx with css
(Note: some of the classNames were intentionally unchanged for readability)

Test Plan 1:
1. Run tests locally; npm run test -- --grep='Bravery Panel'
2. Open about:preferences#shields
3. Enable the compact panel option
4. Run manual tests described here: https://github.com/brave/browser-laptop/wiki/Manual-Tests#bravery-settings

Test Plan 2:
1. Open about:styles
2. Click "Dropdowns"
3. Make sure BraveryPanelDropdown is displayed
Related with #8986

- Reorganize const
@luixxiul luixxiul added this to the 0.16.100 milestone May 21, 2017
@luixxiul luixxiul self-assigned this May 21, 2017
@luixxiul
Copy link
Contributor Author

luixxiul commented May 21, 2017

On about:preferences#shields:

screenshot 2017-05-22 2 11 10

If the option is off:

screenshot 2017-05-22 2 10 57

If the option is on:

screenshot 2017-05-22 2 10 45

Updated to this one with #9078.
screenshot 2017-05-27 2 13 08

@Jacalz
Copy link
Contributor

Jacalz commented May 21, 2017

I must say that this looks amazing and I will most certainly use it 👍

@luixxiul
Copy link
Contributor Author

From:
screenshot 2017-05-22 4 06 32

To:
screenshot 2017-05-22 4 06 39

@@ -37,6 +38,12 @@ class SettingDropdown extends ImmutableComponent {
}
}

class BraveryPanelDropdown extends ImmutableComponent {
render () {
return <FormDropdown data-isBraveryPanel='true' {...this.props} />
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if you just let data-isBraveryPanel works. Above you're passing true as a string, which would evaluate prop to true anyway, so would any other string. For example, data-isBraveryPanel='brave' would be true as well.

You can double-check that if you pass data-isBraveryPanel={true}which will evaluate to boolean. Standardjs will warn you saying that it is not necessary:

Value must be omitted for boolean attributes

I would just <FormDropdown data-isBraveryPanel {...this.props} />.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with 5670822

[css(styles.braveryPanel__stats__item_count_clickable)]: !!adsBlockedStat,
[css(styles.braveryPanel__stats__item_count_disabled)]: !shieldsUp || adControl === 'allowAdsAndTracking',
[css(gridStyles.row1col1)]: !compactBraveryPanel,
[css(gridStyles.row1col1)]: compactBraveryPanel,
Copy link
Contributor

Choose a reason for hiding this comment

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

if gridStyles.row1col1 appear in both conditions then you could only [css(gridStyles.row1col1)]: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I just missed that.

[css(gridStyles.row1col1)]: compactBraveryPanel,
[css(styles.braveryPanel__stats__item_count_adsBlockedStat)]: true,
[css(styles.braveryPanel__stats__item, styles.braveryPanel__stats__item_count)]: !compactBraveryPanel,
[css(styles.braveryPanel_compact__stats__item_count)]: compactBraveryPanel
Copy link
Contributor

Choose a reason for hiding this comment

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

since all styles use Aphrodite we could make use of its recommended syntax as well:

className={css(
  !!adsBlockedStat && styles.braveryPanel__stats__item_count_clickable,
  (!shieldsUp || adControl === 'allowAdsAndTracking') && styles.braveryPanel__stats__item_count_disabled,
  gridStyles.row1col1,
  styles.braveryPanel__stats__item_count_adsBlockedStat,
  !compactBraveryPanel && styles.braveryPanel__stats__item,
  !compactBraveryPanel && styles.braveryPanel__stats__item_count,
  compactBraveryPanel && styles.braveryPanel_compact__stats__item_count 
)}

it may seem weird at first but it looks for the first assumption and only execute the latest if condition evaluates to true. condition && style would write nothing if condition is false.

Same tip applies for next cases. Let me know if you need a hand rewriting it

Copy link
Contributor

Choose a reason for hiding this comment

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

that's an example however. I would make (!shieldsUp || adControl === 'allowAdsAndTracking') a variable for better readability and put styles that don't need conditionals (such as gridStyles.row1col1) at first for the same reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have already tried ^^ once but don't you think it is hard to read? (well it is, at least for me..)

In this case I would stick to cx for readability of classNames in BEM, still I'm fine with your suggestion too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's an example however.

I'm going to try that and compare it with the current version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with 6b041ce

whiteSpace: 'nowrap',
overflow: 'hidden'
}
const editGlobalMarginBottom = '.25rem'
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind having relative units but curious why we have it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I set 1rem to padding of braveryPanel_compact__body and I wanted to set .25rem as 25% of that padding. We know 1rem=16px, so it should be clear that .25rem=16px*25% and .75rem=16px*75% without doing math (no matter how easy it is in this case).

Using px sometimes makes it hard to know how and why this value has been set so. that's why I prefer relative units for elements which I added by myself. I avoided converting the units of other elements which already have existed because we can trust the value.

},
row8col1: {
gridRow: 8,
gridColumn: 1
Copy link
Contributor

Choose a reason for hiding this comment

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

grid ftw ++

right: '20px',
userSelect: 'none',
cursor: 'default',
color: '#3B3B3B',
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move it to global.js and so other colors? you can copy browserButton way and create an object like:

braveryPanel: {
  color: '#3B3B3B'
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done with a237c9d

@cezaraugusto cezaraugusto requested a review from diracdeltas May 22, 2017 04:51
@cezaraugusto
Copy link
Contributor

comments aside, changes look great and new look will please a lot of users. Can't wait to see this landing

Copy link
Contributor Author

@luixxiul luixxiul left a comment

Choose a reason for hiding this comment

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

Addressed feedbacks.

Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

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

this looks incredible ++

I would leave a comment but I think we have a lot of improvements here so I created #9016 to keep track of that. Will label as ready-for-merge feel free to merge once squashed.

- Replace cx with css
- Fix data-isBraveryPanel
- Move color properties to global.js

Also:
- Add braveryPanel__stats__item_label_clickable
- Add braveryPanel__stats__item_label_disabled
- Remove globalStyles.color.statsGray
  It is no longer used: https://github.com/brave/browser-laptop/blob/b831100570616921b388ab4f79fc60b751616642/less/forms.less#L89
@luixxiul luixxiul merged commit 8d01a21 into brave:master May 23, 2017
@luixxiul
Copy link
Contributor Author

@cezaraugusto thanks! Let's discuss the follow ups there.

@bsclifton
Copy link
Member

Great job with this, @luixxiul! 😻

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants