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

Fix broken UI in Clear Browsing Data on Exit dialog (uplift to 1.45.x) #15565

Merged
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 @@ -14,33 +14,55 @@ import type {SettingsClearBrowsingDataDialogElement as BraveSettingsClearBrowsin

const BaseElement = WebUIListenerMixin(SettingsClearBrowsingDataDialogElement)
export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement {
ready() {
override ready() {
super.ready()
this.addOnExitElements_();
this.addWebUIListener(
'update-counter-text', this.updateOnExitCountersText.bind(this));
}

attached() {
super.attached()
this.listen(this.$.tabs, 'selected-item-changed',
'onSelectedTabChanged_');
this.listen(this.$$('#on-exit-tab'), 'clear-data-on-exit-page-change',
'updateSaveButtonState_');
this.listen(this.$$('#saveOnExitSettingsConfirm'), 'click',
'saveOnExitSettings_');
override connectedCallback() {
super.connectedCallback()

this.onSelectedTabChangedCallback_ = this.onSelectedTabChanged_.bind(this);
this.$.tabs.addEventListener('selected-item-changed',
this.onSelectedTabChangedCallback_);

this.updateSaveButtonStateCallback_ = this.updateSaveButtonState_.bind(this);
this.shadowRoot.querySelector('#on-exit-tab').addEventListener(
'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_);

this.saveOnExitSettingsCallback_ = this.saveOnExitSettings_.bind(this);
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').addEventListener(
'click', this.saveOnExitSettingsCallback_);
}

detached() {
super.detached()
this.unlisten(this.$.tabs, 'selected-item-changed',
'onSelectedTabChanged_');
this.unlisten(this.$$('#on-exit-tab'), 'clear-data-on-exit-page-change',
'updateSaveButtonState_');
this.unlisten(this.$$('#saveOnExitSettingsConfirm'), 'click',
'saveOnExitSettings_');
override disconnectedCallback() {
super.disconnectedCallback()

if (this.onSelectedTabChangedCallback_) {
this.$.tabs.removeEventListener('selected-item-changed',
this.onSelectedTabChangedCallback_);
this.onSelectedTabChangedCallback_ = null;
}

if (this.saveOnExitSettingsCallback_) {
this.shadowRoot.querySelector('#on-exit-tab').removeEventListener(
'clear-data-on-exit-page-change', this.updateSaveButtonStateCallback_);
this.updateSaveButtonStateCallback_ = null;
}

if (this.saveOnExitSettingsCallback_) {
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').removeEventListener(
'click', this.saveOnExitSettingsCallback_);
this.saveOnExitSettingsCallback_ = null;
}
}

private onSelectedTabChangedCallback_: (() => void) | null = null
private updateSaveButtonStateCallback_: (() => void) | null = null
private saveOnExitSettingsCallback_: (() => void) | null = null

/**
* Adds OnExit tab and Save button to the DOM.
* @private
Expand Down Expand Up @@ -76,7 +98,7 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement {
// Data type deletion preferences are named "browser.clear_data.<datatype>".
// Strip the common prefix, i.e. use only "<datatype>".
const matches = prefName.match(/^browser\.clear_data\.(\w+)$/);
this.$$('#on-exit-tab').setCounter(matches[1], text);
this.shadowRoot.querySelector('#on-exit-tab').setCounter(matches[1], text);
}

/**
Expand All @@ -88,26 +110,26 @@ export class BraveSettingsClearBrowsingDataDialogElement extends BaseElement {
if (!tab) {
return;
}
const isOnExitTab = (this.$.tabs.selectedItem.id == 'on-exit-tab');
const isOnExitTab = (tab.id === 'on-exit-tab');
this.$.clearBrowsingDataConfirm.hidden = isOnExitTab;
this.$$('#saveOnExitSettingsConfirm').hidden = !isOnExitTab;
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').hidden = !isOnExitTab;
}

/**
* Updates Save button enabled state based on on-exit-tab's changed state.
* @private
*/
updateSaveButtonState_() {
this.$$('#saveOnExitSettingsConfirm').disabled =
!this.$$('#on-exit-tab').isModified;
this.shadowRoot.querySelector('#saveOnExitSettingsConfirm').disabled =
!this.shadowRoot.querySelector('#on-exit-tab').isModified;
}

/**
* Saves on exit settings selections.
* @private
*/
saveOnExitSettings_() {
const changed = this.$$('#on-exit-tab').getChangedSettings();
const changed = this.shadowRoot.querySelector('#on-exit-tab').getChangedSettings();
changed.forEach((change) => {
this.set('prefs.' + change.key + '.value', change.value);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<style include="settings-shared">

settings-checkbox {
--settings-row-two-line-min-height: 48px;
--settings-checkbox-label: {
Expand Down Expand Up @@ -61,4 +60,3 @@
no-set-pref>
</settings-checkbox>
</div>
</template>