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

[0.69.x] allow shields read-only view to show actual resources blocked #3077

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
getToggleStateViaEventTarget,
getTabIndexValueBasedOnProps,
blockedResourcesSize,
maybeDisableResourcesRow
shouldDisableResourcesRow
} from '../../../helpers/shieldsUtils'

// Types
Expand Down Expand Up @@ -83,8 +83,8 @@ export default class AdsTrackersControl extends React.PureComponent<Props, State
return maybeBlockResource(ads) && maybeBlockResource(trackers)
}

get maybeDisableResourcesRow (): boolean {
return maybeDisableResourcesRow(this.totalAdsTrackersBlocked)
get shouldDisableResourcesRow (): boolean {
return shouldDisableResourcesRow(this.totalAdsTrackersBlocked)
}

get tabIndex (): number {
Expand Down Expand Up @@ -122,7 +122,7 @@ export default class AdsTrackersControl extends React.PureComponent<Props, State
<>
<BlockedInfoRow id='adsTrackersControl'>
<BlockedInfoRowData
disabled={this.maybeDisableResourcesRow}
disabled={this.shouldDisableResourcesRow}
tabIndex={this.tabIndex}
onClick={this.onOpen3rdPartyTrackersBlocked}
onKeyDown={this.onOpen3rdPartyTrackersBlockedViaKeyboard}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getLocale } from '../../../background/api/localeAPI'

// Helpers
import {
maybeDisableResourcesRow,
shouldDisableResourcesRow,
getTabIndexValueBasedOnProps,
blockedResourcesSize
} from '../../../helpers/shieldsUtils'
Expand All @@ -36,14 +36,14 @@ interface CommonProps {
setBlockedListOpen: () => void
}

interface HTTPSUpgradesProps {
interface DeviceRecognitionProps {
fingerprinting: BlockFPOptions
fingerprintingBlocked: number
fingerprintingBlockedResources: Array<string>
blockFingerprinting: (event: string) => void
}

export type Props = CommonProps & HTTPSUpgradesProps
export type Props = CommonProps & DeviceRecognitionProps

interface State {
deviceRecognitionOpen: boolean
Expand All @@ -62,9 +62,9 @@ export default class DeviceRecognitionControl extends React.PureComponent<Props,
return blockedResourcesSize(fingerprintingBlocked)
}

get maybeDisableResourcesRow (): boolean {
get shouldDisableResourcesRow (): boolean {
const { fingerprintingBlocked } = this.props
return maybeDisableResourcesRow(fingerprintingBlocked)
return shouldDisableResourcesRow(fingerprintingBlocked)
}

get tabIndex (): number {
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class DeviceRecognitionControl extends React.PureComponent<Props,
<>
<BlockedInfoRowForSelect id='deviceRecognitionControl'>
<BlockedInfoRowDataForSelect
disabled={this.maybeDisableResourcesRow}
disabled={this.shouldDisableResourcesRow}
tabIndex={this.tabIndex}
onClick={this.onOpenDeviceRecognition}
onKeyDown={this.onOpenDeviceRecognitionViaKeyboard}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getLocale } from '../../../background/api/localeAPI'
// Helpers
import {
maybeBlockResource,
maybeDisableResourcesRow,
shouldDisableResourcesRow,
getTabIndexValueBasedOnProps,
blockedResourcesSize,
getToggleStateViaEventTarget
Expand Down Expand Up @@ -59,9 +59,9 @@ export default class HTTPSUpgradesControl extends React.PureComponent<Props, Sta
this.state = { connectionsUpgradedOpen: false }
}

get maybeDisableResourcesRow (): boolean {
get shouldDisableResourcesRow (): boolean {
const { httpsRedirected } = this.props
return maybeDisableResourcesRow(httpsRedirected)
return shouldDisableResourcesRow(httpsRedirected)
}

get httpsRedirectedDisplay (): string {
Expand Down Expand Up @@ -109,7 +109,7 @@ export default class HTTPSUpgradesControl extends React.PureComponent<Props, Sta
<>
<BlockedInfoRow id='httpsUpgradesControl'>
<BlockedInfoRowData
disabled={this.maybeDisableResourcesRow}
disabled={this.shouldDisableResourcesRow}
tabIndex={this.tabIndex}
onClick={this.onOpenConnectionsUpgradedToHTTPS}
onKeyDown={this.onOpenConnectionsUpgradedToHTTPSViaKeyboard}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getLocale } from '../../../background/api/localeAPI'

// Helpers
import {
maybeDisableResourcesRow,
shouldDisableResourcesRow,
blockedResourcesSize,
maybeBlockResource,
getTabIndexValueBasedOnProps,
Expand Down Expand Up @@ -71,14 +71,12 @@ interface State {
export default class ScriptsControls extends React.PureComponent<Props, State> {
constructor (props: Props) {
super(props)
this.state = {
scriptsBlockedOpen: false
}
this.state = { scriptsBlockedOpen: false }
}

get maybeDisableResourcesRow (): boolean {
get shouldDisableResourcesRow (): boolean {
const { javascriptBlocked } = this.props
return maybeDisableResourcesRow(javascriptBlocked)
return shouldDisableResourcesRow(javascriptBlocked)
}

get javascriptBlockedDisplay (): string {
Expand Down Expand Up @@ -142,7 +140,7 @@ export default class ScriptsControls extends React.PureComponent<Props, State> {
<>
<BlockedInfoRow id='scriptsControl' extraColumn={true}>
<BlockedInfoRowData
disabled={this.maybeDisableResourcesRow}
disabled={this.shouldDisableResourcesRow}
tabIndex={this.tabIndex}
onClick={this.onOpenScriptsBlocked}
onKeyDown={this.onOpenScriptsBlockedViaKeyboard}
Expand All @@ -152,7 +150,7 @@ export default class ScriptsControls extends React.PureComponent<Props, State> {
<BlockedInfoRowText>{getLocale('scriptsBlocked')}</BlockedInfoRowText>
</BlockedInfoRowData>
{
this.maybeDisableResourcesRow === false
this.shouldDisableResourcesRow === false
&& (
<LinkAction
size='small'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,86 @@ import {
ArrowUpIcon,
ArrowDownIcon,
BlockedInfoRowStats,
BlockedListStatic,
dummyData
BlockedListStatic
} from 'brave-ui/features/shields'

// Group components
import StaticResourcesList from '../../shared/resourcesBlockedList/staticResourcesList'

// Helpers
// Locale
import { getLocale } from '../../../background/api/localeAPI'

// Helpers
import {
sumAdsAndTrackers,
blockedResourcesSize,
shouldDisableResourcesRow,
mergeAdsAndTrackersResources
} from '../../../helpers/shieldsUtils'

// Types
import { BlockOptions } from '../../../types/other/blockTypes'

interface Props {
ads: BlockOptions
adsBlocked: number
adsBlockedResources: Array<string>
trackers: BlockOptions
trackersBlocked: number
trackersBlockedResources: Array<string>
}

interface State {
dummyThirdPartyTrackersBlockedOpen: boolean
trackersBlockedOpen: boolean
}

export default class AdsTrackersControl extends React.PureComponent<{}, State> {
constructor (props: {}) {
export default class AdsTrackersControl extends React.PureComponent<Props, State> {
constructor (props: Props) {
super(props)
this.state = { dummyThirdPartyTrackersBlockedOpen: false }
this.state = { trackersBlockedOpen: false }
}
onClickFakeThirdPartyTrackersBlocked = () => {
this.setState({ dummyThirdPartyTrackersBlockedOpen: !this.state.dummyThirdPartyTrackersBlockedOpen })

get totalAdsTrackersBlocked (): number {
const { adsBlocked, trackersBlocked } = this.props
return sumAdsAndTrackers(adsBlocked, trackersBlocked)
}

get totalAdsTrackersBlockedDisplay (): string {
return blockedResourcesSize(this.totalAdsTrackersBlocked)
}

get totalAdsTrackersBlockedList (): Array<string> {
const { adsBlockedResources, trackersBlockedResources } = this.props
return mergeAdsAndTrackersResources(adsBlockedResources, trackersBlockedResources)
}

get shouldDisableResourcesRow (): boolean {
return shouldDisableResourcesRow(this.totalAdsTrackersBlocked)
}

triggerOpen3rdPartyTrackersBlocked = () => {
if (!this.shouldDisableResourcesRow) {
this.setState({ trackersBlockedOpen: !this.state.trackersBlockedOpen })
}
}

render () {
const { dummyThirdPartyTrackersBlockedOpen } = this.state
const { trackersBlockedOpen } = this.state
return (
<BlockedInfoRowDetails>
<BlockedInfoRowSummary onClick={this.onClickFakeThirdPartyTrackersBlocked}>
<BlockedInfoRowData disabled={false}>
<BlockedInfoRowSummary onClick={this.triggerOpen3rdPartyTrackersBlocked}>
<BlockedInfoRowData disabled={this.shouldDisableResourcesRow}>
{
dummyThirdPartyTrackersBlockedOpen
trackersBlockedOpen
? <ArrowUpIcon />
: <ArrowDownIcon />
}
<BlockedInfoRowStats>{2}</BlockedInfoRowStats>
<BlockedInfoRowStats>{this.totalAdsTrackersBlockedDisplay}</BlockedInfoRowStats>
<BlockedInfoRowText>{getLocale('thirdPartyTrackersBlocked')}</BlockedInfoRowText>
</BlockedInfoRowData>
</BlockedInfoRowSummary>
<BlockedListStatic>
<StaticResourcesList list={dummyData.otherBlockedResources} />
<StaticResourcesList list={this.totalAdsTrackersBlockedList} />
</BlockedListStatic>
</BlockedInfoRowDetails>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,76 @@ import {
BlockedInfoRowForSelectSummary,
BlockedInfoRowDataForSelect,
BlockedListStatic,
BlockedInfoRowText,
dummyData
BlockedInfoRowText
} from 'brave-ui/features/shields'

// Group components
import StaticResourcesList from '../../shared/resourcesBlockedList/staticResourcesList'

// Helpers
// Locale
import { getLocale } from '../../../background/api/localeAPI'

// Helpers
import {
blockedResourcesSize,
shouldDisableResourcesRow
} from '../../../helpers/shieldsUtils'

// Types
import { BlockFPOptions } from '../../../types/other/blockTypes'

interface Props {
fingerprinting: BlockFPOptions
fingerprintingBlocked: number
fingerprintingBlockedResources: Array<string>
}

interface State {
dummyThirdPartyFingerprintingBlockedOpen: boolean
deviceRecognitionOpen: boolean
}

export default class AdsTrackersControl extends React.PureComponent<{}, State> {
constructor (props: {}) {
export default class DeviceRecognitionControl extends React.PureComponent<Props, State> {
constructor (props: Props) {
super(props)
this.state = { dummyThirdPartyFingerprintingBlockedOpen: false }
this.state = { deviceRecognitionOpen: false }
}

get totalDeviceRecognitonAttemptsDisplay (): string {
const { fingerprintingBlocked } = this.props
return blockedResourcesSize(fingerprintingBlocked)
}

onClickFakeThirdPartyFingerprintingBlocked = () => {
this.setState({ dummyThirdPartyFingerprintingBlockedOpen: !this.state.dummyThirdPartyFingerprintingBlockedOpen })
get shouldDisableResourcesRow (): boolean {
const { fingerprintingBlocked } = this.props
return shouldDisableResourcesRow(fingerprintingBlocked)
}

triggerOpenDeviceRecognition = () => {
if (!this.shouldDisableResourcesRow) {
this.setState({ deviceRecognitionOpen: !this.state.deviceRecognitionOpen })
}
}

render () {
const { dummyThirdPartyFingerprintingBlockedOpen } = this.state
const { deviceRecognitionOpen } = this.state
const { fingerprintingBlockedResources } = this.props
return (
<BlockedInfoRowDetails>
<BlockedInfoRowForSelectSummary onClick={this.onClickFakeThirdPartyFingerprintingBlocked}>
<BlockedInfoRowDataForSelect disabled={false}>
<BlockedInfoRowForSelectSummary onClick={this.triggerOpenDeviceRecognition}>
<BlockedInfoRowDataForSelect disabled={this.shouldDisableResourcesRow}>
{
dummyThirdPartyFingerprintingBlockedOpen
deviceRecognitionOpen
? <ArrowUpIcon />
: <ArrowDownIcon />
}
<BlockedInfoRowStats>{2}</BlockedInfoRowStats>
<BlockedInfoRowStats>{this.totalDeviceRecognitonAttemptsDisplay}</BlockedInfoRowStats>
<BlockedInfoRowText>
<span>{getLocale('thirdPartyFingerprintingBlocked')}</span>
</BlockedInfoRowText>
</BlockedInfoRowDataForSelect>
</BlockedInfoRowForSelectSummary>
<BlockedListStatic>
<StaticResourcesList list={dummyData.otherBlockedResources} />
<StaticResourcesList list={fingerprintingBlockedResources} />
</BlockedListStatic>
</BlockedInfoRowDetails>
)
Expand Down
Loading