From 9beae3adef99ed67d1c2069cedb8346f52a0c128 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Wed, 14 Jun 2017 16:41:25 +0200 Subject: [PATCH] Converts ClearBrowsingDataPanel into redux component Resolves #9440 Auditors: @bridiver @bsclifton Test Plan: --- app/browser/menu.js | 8 +- app/browser/reducers/sitesReducer.js | 2 +- app/ledger.js | 3 +- .../components/main/clearBrowsingDataPanel.js | 77 +++++++++++++------ app/renderer/components/main/main.js | 9 +-- docs/appActions.md | 12 +-- js/actions/appActions.js | 27 +++++-- js/constants/appConstants.js | 4 +- js/stores/appStore.js | 36 +++++---- .../app/browser/reducers/sitesReducerTest.js | 3 +- 10 files changed, 119 insertions(+), 62 deletions(-) diff --git a/app/browser/menu.js b/app/browser/menu.js index 17469c71e22..e4ef286b454 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -693,11 +693,11 @@ const doAction = (action) => { } break case appConstants.APP_ON_CLEAR_BROWSING_DATA: - if (action.clearDataDetail.get('browserHistory')) { - appDispatcher.waitFor([appStore.dispatchToken], () => { + appDispatcher.waitFor([appStore.dispatchToken], () => { + if (appStore.getState().getIn(['clearBrowsingDataDefaults', 'browserHistory'])) { createMenu() - }) - } + } + }) break case windowConstants.WINDOW_CLICK_MENUBAR_SUBMENU: appDispatcher.waitFor([appStore.dispatchToken], () => { diff --git a/app/browser/reducers/sitesReducer.js b/app/browser/reducers/sitesReducer.js index a2ea7d0ecff..e006312a052 100644 --- a/app/browser/reducers/sitesReducer.js +++ b/app/browser/reducers/sitesReducer.js @@ -42,7 +42,7 @@ const sitesReducer = (state, action, immutableAction) => { state = siteCache.loadLocationSiteKeysCache(state) break case appConstants.APP_ON_CLEAR_BROWSING_DATA: - if (immutableAction.getIn(['clearDataDetail', 'browserHistory'])) { + if (state.getIn(['clearBrowsingDataDefaults', 'browserHistory'])) { state = state.set('sites', siteUtil.clearHistory(state.get('sites'))) filtering.clearHistory() } diff --git a/app/ledger.js b/app/ledger.js index 1217cd24e2f..6d69c486038 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -168,7 +168,8 @@ const doAction = (action) => { break case appConstants.APP_ON_CLEAR_BROWSING_DATA: - if (action.clearDataDetail.get('browserHistory') && !getSetting(settings.PAYMENTS_ENABLED)) reset(true) + // TODO + // if (action.clearDataDetail.get('browserHistory') && !getSetting(settings.PAYMENTS_ENABLED)) reset(true) break case appConstants.APP_IDLE_STATE_CHANGED: diff --git a/app/renderer/components/main/clearBrowsingDataPanel.js b/app/renderer/components/main/clearBrowsingDataPanel.js index 6e44f73733f..de0fa9186ea 100644 --- a/app/renderer/components/main/clearBrowsingDataPanel.js +++ b/app/renderer/components/main/clearBrowsingDataPanel.js @@ -7,6 +7,7 @@ const Immutable = require('immutable') const ipc = require('electron').ipcRenderer // Components +const ReduxComponent = require('../reduxComponent') const Dialog = require('../common/dialog') const Button = require('../common/button') const SwitchControl = require('../common/switchControl') @@ -20,6 +21,7 @@ const { // Actions const appActions = require('../../../../js/actions/appActions') +const windowActions = require('../../../../js/actions/windowActions') // Constants const messages = require('../../../../js/constants/messages') @@ -36,71 +38,100 @@ class ClearBrowsingDataPanel extends React.Component { this.onToggleAutofillData = this.onToggleSetting.bind(this, 'autofillData') this.onToggleSavedSiteSettings = this.onToggleSetting.bind(this, 'savedSiteSettings') this.onClear = this.onClear.bind(this) - this.state = { - clearBrowsingDataDetail: props.clearBrowsingDataDefaults ? props.clearBrowsingDataDefaults : Immutable.Map() - } + this.onCancel = this.onCancel.bind(this) } - onToggleSetting (setting) { - this.setState(({clearBrowsingDataDetail}) => ({ - clearBrowsingDataDetail: clearBrowsingDataDetail.update(setting, isChecked => !isChecked) - })) + + onToggleSetting (setting, e) { + appActions.onToggleBrowsingData(setting, e.target.value) } + onClear () { - appActions.onClearBrowsingData(this.state.clearBrowsingDataDetail) - this.props.onHide() - let detail = this.state.clearBrowsingDataDetail - if (detail.get('allSiteCookies') && detail.get('browserHistory') && - detail.get('cachedImagesAndFiles')) { + appActions.onClearBrowsingData() + this.onHide() + + if ( + this.props.allSiteCookies && + this.props.browserHistory && + this.props.cachedImagesAndFiles + ) { ipc.send(messages.PREFS_RESTART) } } + + onCancel () { + appActions.onCancelBrowsingData() + this.onHide() + } + + onHide () { + windowActions.setClearBrowsingDataPanelVisible(false) + } + + mergeProps (state, ownProps) { + const tempData = state.get('tempClearBrowsingData', Immutable.Map()) + const data = state.get('clearBrowsingDataDefaults', Immutable.Map()).merge(tempData) + + const props = {} + props.allSiteCookies = data.get('allSiteCookies') + props.browserHistory = data.get('browserHistory') + props.downloadHistory = data.get('downloadHistory') + props.cachedImagesAndFiles = data.get('cachedImagesAndFiles') + props.savedPasswords = data.get('savedPasswords') + props.allSiteCookies = data.get('allSiteCookies') + props.autocompleteData = data.get('autocompleteData') + props.autofillData = data.get('autofillData') + props.savedSiteSettings = data.get('savedSiteSettings') + + return props + } + render () { - return + return e.stopPropagation()}>