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

Converts ClearBrowsingDataPanel into redux component #9457

Merged
merged 2 commits into from
Jun 20, 2017
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
8 changes: 4 additions & 4 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the change here from action.clearDataDetail to checking the state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we are not sending anything in the action anymore. We have everything that we need directly in the store already. We are saving data here already https://github.com/brave/browser-laptop/pull/9457/files#diff-23ca389e2bcb77191b5a9c10900eb3a3R697

Copy link
Contributor Author

Choose a reason for hiding this comment

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

createMenu()
})
}
}
})
break
case windowConstants.WINDOW_CLICK_MENUBAR_SUBMENU:
appDispatcher.waitFor([appStore.dispatchToken], () => {
Expand Down
2 changes: 1 addition & 1 deletion app/browser/reducers/sitesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
25 changes: 20 additions & 5 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const uuid = require('uuid')
const appActions = require('../js/actions/appActions')
const appConfig = require('../js/constants/appConfig')
const appConstants = require('../js/constants/appConstants')
const appDispatcher = require('../js/dispatcher/appDispatcher')
const messages = require('../js/constants/messages')
const settings = require('../js/constants/settings')
const request = require('../js/lib/request')
Expand Down Expand Up @@ -145,7 +144,7 @@ let notificationTryPaymentsMessage
let notificationTimeout = null

// TODO(bridiver) - create a better way to get setting changes
const doAction = (action) => {
const doAction = (state, action) => {
var i, publisher

/* TBD: handle
Expand All @@ -163,12 +162,26 @@ const doAction = (action) => {
}

switch (action.actionType) {
case appConstants.APP_SET_STATE:
init()
break

case appConstants.APP_BACKUP_KEYS:
state = backupKeys(state, action)
break

case appConstants.APP_RECOVER_WALLET:
state = recoverKeys(state, action)
break

case appConstants.APP_SHUTTING_DOWN:
quit()
break

case appConstants.APP_ON_CLEAR_BROWSING_DATA:
if (action.clearDataDetail.get('browserHistory') && !getSetting(settings.PAYMENTS_ENABLED)) reset(true)
if (state.getIn(['clearBrowsingDataDefaults', 'browserHistory']) && !getSetting(settings.PAYMENTS_ENABLED)) {
reset(true)
}
break

case appConstants.APP_IDLE_STATE_CHANGED:
Expand Down Expand Up @@ -264,6 +277,8 @@ const doAction = (action) => {
default:
break
}

return state
}

/*
Expand All @@ -272,7 +287,6 @@ const doAction = (action) => {

var init = () => {
try {
appDispatcher.register(doAction)
initialize(getSetting(settings.PAYMENTS_ENABLED))
} catch (ex) { console.log('ledger.js initialization failed: ' + ex.toString() + '\n' + ex.stack) }
}
Expand Down Expand Up @@ -2250,5 +2264,6 @@ module.exports = {
backupKeys: backupKeys,
quit: quit,
boot: boot,
reset: reset
reset: reset,
doAction
}
77 changes: 54 additions & 23 deletions app/renderer/components/main/clearBrowsingDataPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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 <Dialog onHide={this.props.onHide} testId='clearBrowsingDataPanel' isClickDismiss>
return <Dialog onHide={this.onHide} testId='clearBrowsingDataPanel' isClickDismiss>
<CommonFormSmall onClick={(e) => e.stopPropagation()}>
<CommonFormTitle data-l10n-id='clearBrowsingData' />
<CommonFormSection>
<SwitchControl
rightl10nId='browserHistory'
testId='browserHistorySwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('browserHistory')}
checkedOn={this.props.browserHistory}
onClick={this.onToggleBrowserHistory} />
<SwitchControl
rightl10nId='downloadHistory'
checkedOn={this.state.clearBrowsingDataDetail.get('downloadHistory')}
checkedOn={this.props.downloadHistory}
onClick={this.onToggleDownloadHistory} />
<SwitchControl
rightl10nId='cachedImagesAndFiles'
checkedOn={this.state.clearBrowsingDataDetail.get('cachedImagesAndFiles')}
checkedOn={this.props.cachedImagesAndFiles}
onClick={this.onToggleCachedImagesAndFiles} />
<SwitchControl
rightl10nId='savedPasswords'
checkedOn={this.state.clearBrowsingDataDetail.get('savedPasswords')}
checkedOn={this.props.savedPasswords}
onClick={this.onToggleSavedPasswords} />
<SwitchControl
rightl10nId='allSiteCookies'
checkedOn={this.state.clearBrowsingDataDetail.get('allSiteCookies')}
checkedOn={this.props.allSiteCookies}
onClick={this.onToggleAllSiteCookies} />
<SwitchControl
rightl10nId='autocompleteData'
testId='autocompleteDataSwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('autocompleteData')}
checkedOn={this.props.autocompleteData}
onClick={this.onToggleAutocompleteData} />
<SwitchControl
rightl10nId='autofillData'
testId='autofillDataSwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('autofillData')}
checkedOn={this.props.autofillData}
onClick={this.onToggleAutofillData} />
<SwitchControl
rightl10nId='savedSiteSettings'
testId='siteSettingsSwitch'
checkedOn={this.state.clearBrowsingDataDetail.get('savedSiteSettings')}
checkedOn={this.props.savedSiteSettings}
onClick={this.onToggleSavedSiteSettings} />
</CommonFormSection>
<CommonFormButtonWrapper>
<Button className='whiteButton'
l10nId='cancel'
testId='cancelButton'
onClick={this.props.onHide}
onClick={this.onCancel}
/>
<Button className='primaryButton'
l10nId='clear'
Expand All @@ -116,4 +147,4 @@ class ClearBrowsingDataPanel extends React.Component {
}
}

module.exports = ClearBrowsingDataPanel
module.exports = ReduxComponent.connect(ClearBrowsingDataPanel)
9 changes: 1 addition & 8 deletions app/renderer/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Main extends ImmutableComponent {
this.onClickWindow = this.onClickWindow.bind(this)
this.onHideSiteInfo = this.onHideSiteInfo.bind(this)
this.onHideBraveryPanel = this.onHideBraveryPanel.bind(this)
this.onHideClearBrowsingDataPanel = this.onHideClearBrowsingDataPanel.bind(this)
this.onHideAutofillCreditCardPanel = this.onHideAutofillCreditCardPanel.bind(this)
this.onTabContextMenu = this.onTabContextMenu.bind(this)
this.checkForTitleMode = debounce(this.checkForTitleMode.bind(this), 20)
Expand Down Expand Up @@ -530,10 +529,6 @@ class Main extends ImmutableComponent {
windowActions.setBraveryPanelDetail()
}

onHideClearBrowsingDataPanel () {
windowActions.setClearBrowsingDataPanelVisible(false)
}

onHideAutofillCreditCardPanel () {
windowActions.setAutofillCreditCardDetail()
}
Expand Down Expand Up @@ -684,9 +679,7 @@ class Main extends ImmutableComponent {
}
{
clearBrowsingDataPanelIsVisible
? <ClearBrowsingDataPanel
clearBrowsingDataDefaults={this.props.appState.get('clearBrowsingDataDefaults')}
onHide={this.onHideClearBrowsingDataPanel} />
? <ClearBrowsingDataPanel />
: null
}
{
Expand Down
18 changes: 13 additions & 5 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,10 @@ Adds information about pending basic auth login requests



### onClearBrowsingData(clearDataDetail)
### onClearBrowsingData()

Clears the data specified in clearDataDetail

**Parameters**

**clearDataDetail**: `object`, the app data to clear as per doc/state.md's clearBrowsingDataDefaults



### importBrowserData(selected)
Expand Down Expand Up @@ -1124,6 +1120,18 @@ Dispatches a message to indicate that the update log is being opened



### onToggleBrowsingData()

Save temp setting for clear browsing data



### onCancelBrowsingData()

Clear temp setting for clear browsing data




* * *

Expand Down
26 changes: 22 additions & 4 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,10 @@ const appActions = {

/**
* Clears the data specified in clearDataDetail
* @param {object} clearDataDetail - the app data to clear as per doc/state.md's clearBrowsingDataDefaults
*/
onClearBrowsingData: function (clearDataDetail) {
onClearBrowsingData: function () {
dispatch({
actionType: appConstants.APP_ON_CLEAR_BROWSING_DATA,
clearDataDetail
actionType: appConstants.APP_ON_CLEAR_BROWSING_DATA
})
},

Expand Down Expand Up @@ -1426,6 +1424,26 @@ const appActions = {
dispatch({
actionType: appConstants.APP_UPDATE_LOG_OPENED
})
},

/**
* Save temp setting for clear browsing data
*/
onToggleBrowsingData: function (property, newValue) {
dispatch({
actionType: appConstants.APP_ON_TOGGLE_BROWSING_DATA,
property,
newValue
})
},

/**
* Clear temp setting for clear browsing data
*/
onCancelBrowsingData: function () {
dispatch({
actionType: appConstants.APP_ON_CANCEL_BROWSING_DATA
})
}
}

Expand Down
4 changes: 3 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ const appConstants = {
APP_REMOVE_PASSWORD_SITE: _, /** @param {Object} passwordDetail */
APP_CLEAR_PASSWORDS: _,
APP_UPDATE_LOG_OPENED: _,
APP_URL_BAR_SELECTED_INDEX_CHANGED: _
APP_URL_BAR_SELECTED_INDEX_CHANGED: _,
APP_ON_TOGGLE_BROWSING_DATA: _,
APP_ON_CANCEL_BROWSING_DATA: _
}

module.exports = mapValuesByKeys(appConstants)
Loading