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 ea5f032491..bb9b627902 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 @@ -757,6 +757,10 @@ }); }, + getDefaultPreferences() { + return this._fetchSharedCacheURL('/config/server/preferences'); + }, + getPreferences() { return this.getLoggedIn().then(loggedIn => { if (loggedIn) {