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

Feature/gh 1239 #131

Merged
merged 5 commits into from Jul 12, 2018
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Blocked Count in Category respects Smart Block active status
  • Loading branch information
IAmThePan committed Jul 12, 2018
commit f697bb2483e71d36e6c2bb5eb92a43df143208de
@@ -68,7 +68,8 @@ class Blocking extends React.Component {
// Update the summary blocking count whenever the blocking component updated.
// This will also show pending blocking changes if the panel is re-opened
// before a page refresh
updateSummaryBlockingCount(this.props.categories, this.props.smartBlock, this.props.actions.updateTrackerCounts);
const smartBlock = this.props.smartBlockActive && this.props.smartBlock || { blocked: {}, unblocked: {} };
updateSummaryBlockingCount(this.props.categories, smartBlock, this.props.actions.updateTrackerCounts);
}
/**
* Filter trackers by category, or reset filters. Trigger action.
@@ -106,7 +107,8 @@ class Blocking extends React.Component {
updated_categories.forEach((category) => {
let count = 0;
category.trackers.forEach((tracker) => {
if ((tracker.blocked && !tracker.ss_allowed) || tracker.ss_blocked) {
const isSbBlocked = this.props.smartBlockActive && tracker.warningSmartBlock;
if ((tracker.blocked && !tracker.ss_allowed) || isSbBlocked || tracker.ss_blocked) {
tracker.shouldShow = true;
count++;
} else {
@@ -253,6 +255,7 @@ class Blocking extends React.Component {
sitePolicy={this.props.sitePolicy}
paused_blocking={this.props.paused_blocking}
selected_app_ids={this.props.selected_app_ids}
smartBlockActive={this.props.smartBlockActive}
smartBlock={this.props.smartBlock}
/>
{(this.state.disableBlocking && this.props.is_expanded) ?
@@ -267,6 +270,7 @@ class Blocking extends React.Component {
sitePolicy={this.props.sitePolicy}
paused_blocking={this.props.paused_blocking}
language={this.props.language}
smartBlockActive={this.props.smartBlockActive}
smartBlock={this.props.smartBlock}
/>
}
@@ -55,7 +55,8 @@ class BlockingHeader extends React.Component {

if (typeof this.props.actions.updateTrackerCounts === 'function') {
// if we're on GlobalSettings, we don't need to run this function
updateSummaryBlockingCount(this.props.categories, this.props.smartBlock, this.props.actions.updateTrackerCounts);
const smartBlock = this.props.smartBlockActive && this.props.smartBlock || { blocked: {}, unblocked: {} };
updateSummaryBlockingCount(this.props.categories, smartBlock, this.props.actions.updateTrackerCounts);
}
}
/**
@@ -117,13 +118,15 @@ class BlockingHeader extends React.Component {
}

this.props.actions.updateBlockAllTrackers({
allBlocked,
smartBlockActive: this.props.smartBlockActive,
smartBlock: this.props.smartBlock,
allBlocked,
});

if (typeof this.props.actions.updateTrackerCounts === 'function') {
// if we're on GlobalSettings, we don't need to run this function
updateSummaryBlockingCount(this.props.categories, this.props.smartBlock, this.props.actions.updateTrackerCounts);
const smartBlock = this.props.smartBlockActive && this.props.smartBlock || { blocked: {}, unblocked: {} };
updateSummaryBlockingCount(this.props.categories, smartBlock, this.props.actions.updateTrackerCounts);
}

this.props.actions.showNotification({
@@ -43,6 +43,7 @@ class Categories extends React.Component {
sitePolicy={this.props.sitePolicy}
paused_blocking={this.props.paused_blocking}
language={this.props.language}
smartBlockActive={this.props.smartBlockActive}
smartBlock={this.props.smartBlock}
/>
));
@@ -119,6 +119,7 @@ class Category extends React.Component {
}

this.props.actions.updateCategoryBlocked({
smartBlockActive: this.props.smartBlockActive,
smartBlock: this.props.smartBlock,
category: this.props.category.id,
blocked,
@@ -233,6 +234,7 @@ class Category extends React.Component {
sitePolicy={this.props.sitePolicy}
paused_blocking={this.props.paused_blocking}
language={this.props.language}
smartBlockActive={this.props.smartBlockActive}
smartBlock={this.props.smartBlock}
/>
}
@@ -148,10 +148,11 @@ class Tracker extends React.Component {
}

this.props.actions.updateTrackerBlocked({
smartBlockActive: this.props.smartBlockActive,
smartBlock: this.props.smartBlock,
app_id: this.props.tracker.id,
cat_id: this.props.cat_id,
blocked,
smartBlock: this.props.smartBlock,
});

this.props.actions.showNotification({
@@ -70,6 +70,7 @@ class Trackers extends React.Component {
sitePolicy={this.props.sitePolicy}
paused_blocking={this.props.paused_blocking}
language={this.props.language}
smartBlockActive={this.props.smartBlockActive}
smartBlock={this.props.smartBlock}
/>
));
@@ -32,6 +32,7 @@ const mapStateToProps = (state, ownProps) => Object.assign({}, state.blocking, {
pageHost: state.summary.pageHost,
paused_blocking: state.summary.paused_blocking,
sitePolicy: state.summary.sitePolicy,
smartBlockActive: state.panel.enable_smart_block,
smartBlock: state.panel.smartBlock,
});
/**
@@ -71,14 +71,14 @@ export function updateSummaryBlockingCount(categories = [], smartBlock, updateTr
* @memberOf PanelUtils
* @param {Object} state current state
* @param {Object} action current action which provides data
*
* @return {Object} updated categories and selected app ids
*/
export function updateBlockAllTrackers(state, action) {
const blocked = !action.data.allBlocked;
const updated_app_ids = JSON.parse(JSON.stringify(state.selected_app_ids)) || {};
const updated_categories = JSON.parse(JSON.stringify(state.categories)) || [];
const smartBlock = action.data.smartBlock || { blocked: {}, unblocked: {} };
const smartBlockActive = action.data.smartBlockActive;
const smartBlock = smartBlockActive && action.data.smartBlock || { blocked: {}, unblocked: {} };

updated_categories.forEach((category) => {
category.num_blocked = 0;
@@ -118,8 +118,8 @@ export function updateBlockAllTrackers(state, action) {
* @return {Object} updated categories and selected app ids
*/
export function updateCategoryBlocked(state, action) {
const { blocked } = action.data;
const smartBlock = action.data.smartBlock || { blocked: {}, unblocked: {} };
const { blocked, smartBlockActive } = action.data;
const smartBlock = smartBlockActive && action.data.smartBlock || { blocked: {}, unblocked: {} };
const updated_app_ids = JSON.parse(JSON.stringify(state.selected_app_ids)) || {};
const updated_categories = JSON.parse(JSON.stringify(state.categories)); // deep clone
const catIndex = updated_categories.findIndex(item => item.id === action.data.category);
@@ -205,8 +205,8 @@ export function updateTrackerBlocked(state, action) {
return {};
}

const { blocked } = action.data;
const smartBlock = action.data.smartBlock || { blocked: {}, unblocked: {} };
const { blocked, smartBlockActive } = action.data;
const smartBlock = smartBlockActive && action.data.smartBlock || { blocked: {}, unblocked: {} };
const updated_app_ids = JSON.parse(JSON.stringify(state.selected_app_ids)) || {};
const updated_categories = JSON.parse(JSON.stringify(state.categories)) || []; // deep clone
const catIndex = updated_categories.findIndex(item => item.id === action.data.cat_id);
@@ -409,15 +409,16 @@ class PanelData {
const pageBlocks = this._confData.get('site_specific_blocks')[pageHost] || [];
const categories = {};
const categoryArray = [];
const smartBlockActive = this._confData.get('enable_smart_block');
const smartBlock = tabInfo.getTabInfo(tab_id, 'smartBlock');

trackerList.forEach((tracker) => {
let category = tracker.cat;
const blocked = selectedAppIds.hasOwnProperty(tracker.id);
const ss_allowed = pageUnblocks.includes(+tracker.id);
const ss_blocked = pageBlocks.includes(+tracker.id);
const sb_blocked = smartBlock.blocked.hasOwnProperty(`${tracker.id}`);
const sb_allowed = smartBlock.unblocked.hasOwnProperty(`${tracker.id}`);
const sb_blocked = smartBlockActive && smartBlock.blocked.hasOwnProperty(`${tracker.id}`);
const sb_allowed = smartBlockActive && smartBlock.unblocked.hasOwnProperty(`${tracker.id}`);

if (t(`category_${category}`) === `category_${category}`) {
category = 'uncategorized';
ProTip! Use n and p to navigate between commits in a pull request.