Merge top menu items contributed by plugins
Each plugin contributes a list single of menus, which are expected to be merged in existing top menu entries if they already exist: as stated in the doc and already implemented in GWT: "Plugins can also add additional menu items to Gerrit’s top menu entries by defining a MenuEntry that has the same name as a Gerrit top menu entry" Change-Id: I8540b93b71e9c9c1f043e16d2076bade4de9a49a
This commit is contained in:
@@ -179,11 +179,16 @@
|
||||
},
|
||||
|
||||
_computeLinks(defaultLinks, userLinks, adminLinks, topMenus, docBaseUrl) {
|
||||
const links = defaultLinks.slice();
|
||||
const links = defaultLinks.map(menu => {
|
||||
return {
|
||||
title: menu.title,
|
||||
links: menu.links.slice(),
|
||||
};
|
||||
});
|
||||
if (userLinks && userLinks.length > 0) {
|
||||
links.push({
|
||||
title: 'Your',
|
||||
links: userLinks,
|
||||
links: userLinks.slice(),
|
||||
});
|
||||
}
|
||||
const docLinks = this._getDocLinks(docBaseUrl, DOCUMENTATION_LINKS);
|
||||
@@ -196,13 +201,20 @@
|
||||
}
|
||||
links.push({
|
||||
title: 'Browse',
|
||||
links: adminLinks,
|
||||
links: adminLinks.slice(),
|
||||
});
|
||||
const topMenuLinks = [];
|
||||
links.forEach(link => { topMenuLinks[link.title] = link.links; });
|
||||
for (const m of topMenus) {
|
||||
links.push({
|
||||
title: m.name,
|
||||
links: m.items.map(this._fixCustomMenuItem),
|
||||
});
|
||||
const items = m.items.map(this._fixCustomMenuItem);
|
||||
if (m.name in topMenuLinks) {
|
||||
items.forEach(link => { topMenuLinks[m.name].push(link); });
|
||||
} else {
|
||||
links.push({
|
||||
title: m.name,
|
||||
links: topMenuLinks[m.name] = items,
|
||||
});
|
||||
}
|
||||
}
|
||||
return links;
|
||||
},
|
||||
|
@@ -191,6 +191,121 @@ limitations under the License.
|
||||
}]);
|
||||
});
|
||||
|
||||
test('merge top menus', () => {
|
||||
const adminLinks = [{
|
||||
name: 'Repos',
|
||||
url: '/repos',
|
||||
}];
|
||||
const topMenus = [{
|
||||
name: 'Plugins',
|
||||
items: [{
|
||||
name: 'Manage',
|
||||
target: '_blank',
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}],
|
||||
}, {
|
||||
name: 'Plugins',
|
||||
items: [{
|
||||
name: 'Create',
|
||||
target: '_blank',
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/create.html',
|
||||
}],
|
||||
}];
|
||||
assert.deepEqual(element._computeLinks([], [], adminLinks, topMenus), [{
|
||||
title: 'Browse',
|
||||
links: adminLinks,
|
||||
}, {
|
||||
title: 'Plugins',
|
||||
links: [{
|
||||
name: 'Manage',
|
||||
external: true,
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}, {
|
||||
name: 'Create',
|
||||
external: true,
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/create.html',
|
||||
}],
|
||||
}]);
|
||||
});
|
||||
|
||||
test('merge top menus in default links', () => {
|
||||
const defaultLinks = [{
|
||||
title: 'Faves',
|
||||
links: [{
|
||||
name: 'Pinterest',
|
||||
url: 'https://pinterest.com',
|
||||
}],
|
||||
}];
|
||||
const topMenus = [{
|
||||
name: 'Faves',
|
||||
items: [{
|
||||
name: 'Manage',
|
||||
target: '_blank',
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}],
|
||||
}];
|
||||
assert.deepEqual(element._computeLinks(defaultLinks, [], [], topMenus), [{
|
||||
title: 'Faves',
|
||||
links: defaultLinks[0].links.concat([{
|
||||
name: 'Manage',
|
||||
external: true,
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}]),
|
||||
}, {
|
||||
title: 'Browse',
|
||||
links: [],
|
||||
}]);
|
||||
});
|
||||
|
||||
test('merge top menus in user links', () => {
|
||||
const userLinks = [{
|
||||
name: 'Facebook',
|
||||
url: 'https://facebook.com',
|
||||
}];
|
||||
const topMenus = [{
|
||||
name: 'Your',
|
||||
items: [{
|
||||
name: 'Manage',
|
||||
target: '_blank',
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}],
|
||||
}];
|
||||
assert.deepEqual(element._computeLinks([], userLinks, [], topMenus), [{
|
||||
title: 'Your',
|
||||
links: userLinks.concat([{
|
||||
name: 'Manage',
|
||||
external: true,
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}]),
|
||||
}, {
|
||||
title: 'Browse',
|
||||
links: [],
|
||||
}]);
|
||||
});
|
||||
|
||||
test('merge top menus in admin links', () => {
|
||||
const adminLinks = [{
|
||||
name: 'Repos',
|
||||
url: '/repos',
|
||||
}];
|
||||
const topMenus = [{
|
||||
name: 'Browse',
|
||||
items: [{
|
||||
name: 'Manage',
|
||||
target: '_blank',
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}],
|
||||
}];
|
||||
assert.deepEqual(element._computeLinks([], [], adminLinks, topMenus), [{
|
||||
title: 'Browse',
|
||||
links: adminLinks.concat([{
|
||||
name: 'Manage',
|
||||
external: true,
|
||||
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
|
||||
}]),
|
||||
}]);
|
||||
});
|
||||
|
||||
test('register URL', () => {
|
||||
const config = {
|
||||
auth: {
|
||||
|
Reference in New Issue
Block a user