From 8f4dd2890968b0c6ff08eb051d1f14316b5cfabc Mon Sep 17 00:00:00 2001 From: Paladox none Date: Fri, 16 Feb 2018 12:32:35 +0000 Subject: [PATCH] Add reset button to my menu in settings Bug: Issue 8375 Change-Id: Icb54c712e1bea6a625aca5e91c87207bf0dbd3b1 --- .../gr-settings-view/gr-settings-view.html | 7 +++- .../gr-settings-view/gr-settings-view.js | 16 ++++++--- .../gr-settings-view_test.html | 36 +++++++++++++++++++ .../gr-rest-api-interface.js | 4 +++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html index 64dd5067d6..894c8946c6 100644 --- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html +++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.html @@ -334,11 +334,16 @@ limitations under the License.

diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js index 117321dc6e..215aaa13c5 100644 --- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js +++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js @@ -162,7 +162,7 @@ this.prefs = prefs; this._showNumber = !!prefs.legacycid_in_change_table; this._copyPrefs('_localPrefs', 'prefs'); - this._cloneMenu(); + this._cloneMenu(prefs.my); this._cloneChangeTableColumns(); })); @@ -226,9 +226,9 @@ } }, - _cloneMenu() { + _cloneMenu(prefs) { const menu = []; - for (const item of this.prefs.my) { + for (const item of prefs) { menu.push({ name: item.name, url: item.url, @@ -343,12 +343,20 @@ _handleSaveMenu() { this.set('prefs.my', this._localMenu); - this._cloneMenu(); + this._cloneMenu(this.prefs.my); return this.$.restAPI.savePreferences(this.prefs).then(() => { this._menuChanged = false; }); }, + _handleResetMenuButton() { + return this.$.restAPI.getDefaultPreferences().then(data => { + if (data && data.my) { + this._cloneMenu(data.my); + } + }); + }, + _handleSaveWatchedProjects() { this.$.watchedProjectsEditor.save(); }, diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html index c42cb5ffb8..b208ba2938 100644 --- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html +++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view_test.html @@ -407,6 +407,42 @@ limitations under the License. assert.isTrue(element.prefs.legacycid_in_change_table); }); + test('reset menu item back to default', done => { + const originalMenu = { + my: [ + {url: '/first/url', name: 'first name', target: '_blank'}, + {url: '/second/url', name: 'second name', target: '_blank'}, + {url: '/third/url', name: 'third name', target: '_blank'}, + ], + }; + + stub('gr-rest-api-interface', { + getDefaultPreferences() { return Promise.resolve(originalMenu); }, + }); + + const updatedMenu = [ + {url: '/first/url', name: 'first name', target: '_blank'}, + {url: '/second/url', name: 'second name', target: '_blank'}, + {url: '/third/url', name: 'third name', target: '_blank'}, + {url: '/fourth/url', name: 'fourth name', target: '_blank'}, + ]; + + element.set('_localMenu', updatedMenu); + + element._handleResetMenuButton().then(() => { + assertMenusEqual(element._localMenu, originalMenu.my); + done(); + }); + }); + + test('test that reset button is called', () => { + const overlayOpen = sandbox.stub(element, '_handleResetMenuButton'); + + MockInteractions.tap(element.$.resetMenu); + + assert.isTrue(overlayOpen.called); + }); + suite('_getFilterDocsLink', () => { test('with http: docs base URL', () => { const base = 'http://example.com/'; diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js index 305fc6ff93..2c061f6a84 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js @@ -756,6 +756,10 @@ }); }, + getDefaultPreferences() { + return this._fetchSharedCacheURL('/config/server/preferences'); + }, + getPreferences() { return this.getLoggedIn().then(loggedIn => { if (loggedIn) {