From dbad8574fbef2395c6045aadf2fdd0c78d0dcb2d Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Fri, 3 May 2019 11:46:58 +0200 Subject: [PATCH] polygerrit-ui: hide project-aware top menus from header Project-aware topmenu links need to be shown only when a project is selected: so special handling must be handled, as it was in GWT. As opposed to GWT however, it does not make sense to show these in header in any case, since there is no notion of 'current project' in menu anymore. So we just hide them for now, and we may show them in the project page as well (but in a separate patch). Change-Id: I180e63b648d2fc228e61c2ad0d485d3ab8ab31f4 --- .../core/gr-main-header/gr-main-header.js | 5 ++- .../gr-main-header/gr-main-header_test.html | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js index a77c66d169..78b2e33cb9 100644 --- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js +++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js @@ -206,7 +206,10 @@ const topMenuLinks = []; links.forEach(link => { topMenuLinks[link.title] = link.links; }); for (const m of topMenus) { - const items = m.items.map(this._fixCustomMenuItem); + const items = m.items.map(this._fixCustomMenuItem).filter(link => { + // Ignore GWT project links + return !link.url.includes('${projectName}'); + }); if (m.name in topMenuLinks) { items.forEach(link => { topMenuLinks[m.name].push(link); }); } else { diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html index 582ca61db0..03586eaea6 100644 --- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html +++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html @@ -191,6 +191,37 @@ limitations under the License. }]); }); + test('ignore top project menus', () => { + const adminLinks = [{ + name: 'Repos', + url: '/repos', + }]; + const topMenus = [{ + name: 'Projects', + items: [{ + name: 'Project Settings', + target: '_blank', + url: '/plugins/myplugin/${projectName}', + }, { + name: 'Project List', + target: '_blank', + url: '/plugins/myplugin/index.html', + }], + }]; + assert.deepEqual(element._computeLinks([], [], adminLinks, topMenus), [{ + title: 'Browse', + links: adminLinks, + }, + { + title: 'Projects', + links: [{ + name: 'Project List', + external: true, + url: '/plugins/myplugin/index.html', + }], + }]); + }); + test('merge top menus', () => { const adminLinks = [{ name: 'Repos',