Update URL generation for groups

This change brings router abstraction to the group views (details,
members and audit log). The app params for these views are refactored to
use `Gerrit.Nav.View.GROUP` rather than `Gerrit.Nav.View.ADMIN`.

Change-Id: Ifa3e19c509c7f2f72e34bb05279bb3a45057cf2d
This commit is contained in:
Wyatt Allen
2017-10-19 15:06:54 -07:00
parent 3dad636aad
commit c172767012
9 changed files with 140 additions and 40 deletions

View File

@@ -20,6 +20,7 @@ limitations under the License.
<link rel="import" href="../../../bower_components/iron-input/iron-input.html"> <link rel="import" href="../../../bower_components/iron-input/iron-input.html">
<link rel="import" href="../../../styles/gr-table-styles.html"> <link rel="import" href="../../../styles/gr-table-styles.html">
<link rel="import" href="../../../styles/shared-styles.html"> <link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../shared/gr-confirm-dialog/gr-confirm-dialog.html"> <link rel="import" href="../../shared/gr-confirm-dialog/gr-confirm-dialog.html">
<link rel="import" href="../../shared/gr-list-view/gr-list-view.html"> <link rel="import" href="../../shared/gr-list-view/gr-list-view.html">
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html"> <link rel="import" href="../../shared/gr-overlay/gr-overlay.html">

View File

@@ -93,7 +93,7 @@
}, },
_computeGroupUrl(id) { _computeGroupUrl(id) {
return this.getUrl(this._path + '/', id); return Gerrit.Nav.getUrlForGroup(id);
}, },
_getCreateGroupCapability() { _getCreateGroupCapability() {

View File

@@ -21,6 +21,7 @@ limitations under the License.
<link rel="import" href="../../../styles/gr-menu-page-styles.html"> <link rel="import" href="../../../styles/gr-menu-page-styles.html">
<link rel="import" href="../../../styles/gr-page-nav-styles.html"> <link rel="import" href="../../../styles/gr-page-nav-styles.html">
<link rel="import" href="../../../styles/shared-styles.html"> <link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../shared/gr-page-nav/gr-page-nav.html"> <link rel="import" href="../../shared/gr-page-nav/gr-page-nav.html">
<link rel="import" href="../../shared/gr-placeholder/gr-placeholder.html"> <link rel="import" href="../../shared/gr-placeholder/gr-placeholder.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html"> <link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">

View File

@@ -148,14 +148,13 @@
linkCopy.subsection = { linkCopy.subsection = {
name: this._groupName, name: this._groupName,
view: 'gr-group', view: 'gr-group',
url: `/admin/groups/${this.encodeURL(this._groupId + '', true)}`, url: Gerrit.Nav.getUrlForGroup(this._groupId),
children: [ children: [
{ {
name: 'Members', name: 'Members',
detailType: 'members', detailType: 'members',
view: 'gr-group-members', view: 'gr-group-members',
url: `/admin/groups/${this.encodeURL(this._groupId, true)}` + url: Gerrit.Nav.getUrlForGroupMembers(this._groupId),
',members',
}, },
], ],
}; };
@@ -165,8 +164,7 @@
name: 'Audit Log', name: 'Audit Log',
detailType: 'audit-log', detailType: 'audit-log',
view: 'gr-group-audit-log', view: 'gr-group-audit-log',
url: '/admin/groups/' + url: Gerrit.Nav.getUrlForGroupLog(this._groupId),
`${this.encodeURL(this._groupId + '', true)},audit-log`,
} }
); );
} }
@@ -187,19 +185,31 @@
}, },
_paramsChanged(params) { _paramsChanged(params) {
this.set('_showGroup', params.adminView === 'gr-group'); const isGroupView = params.view === Gerrit.Nav.View.GROUP;
this.set('_showGroupAuditLog', params.adminView === 'gr-group-audit-log'); const isAdminView = params.view === Gerrit.Nav.View.ADMIN;
this.set('_showGroupList', params.adminView === 'gr-admin-group-list');
this.set('_showGroupMembers', params.adminView === 'gr-group-members'); this.set('_showGroup', isGroupView && !params.detail);
this.set('_showProjectCommands', this.set('_showGroupAuditLog', isGroupView &&
params.detail === Gerrit.Nav.GroupDetailView.LOG);
this.set('_showGroupMembers', isGroupView &&
params.detail === Gerrit.Nav.GroupDetailView.MEMBERS);
this.set('_showGroupList', isAdminView &&
params.adminView === 'gr-admin-group-list');
this.set('_showProjectCommands', isAdminView &&
params.adminView === 'gr-project-commands'); params.adminView === 'gr-project-commands');
this.set('_showProjectMain', params.adminView === 'gr-project'); this.set('_showProjectMain', isAdminView &&
this.set('_showProjectList', params.adminView === 'gr-project');
this.set('_showProjectList', isAdminView &&
params.adminView === 'gr-project-list'); params.adminView === 'gr-project-list');
this.set('_showProjectDetailList', this.set('_showProjectDetailList', isAdminView &&
params.adminView === 'gr-project-detail-list'); params.adminView === 'gr-project-detail-list');
this.set('_showPluginList', params.adminView === 'gr-plugin-list'); this.set('_showPluginList', isAdminView &&
this.set('_showProjectAccess', params.adminView === 'gr-project-access'); params.adminView === 'gr-plugin-list');
this.set('_showProjectAccess', isAdminView &&
params.adminView === 'gr-project-access');
if (params.project !== this._projectName) { if (params.project !== this._projectName) {
this._projectName = params.project || ''; this._projectName = params.project || '';
// Reloads the admin menu. // Reloads the admin menu.

View File

@@ -75,6 +75,7 @@ limitations under the License.
}]; }];
element.params = { element.params = {
view: 'admin',
adminView: 'gr-project-list', adminView: 'gr-project-list',
}; };
@@ -206,7 +207,7 @@ limitations under the License.
assert.isTrue(element.reload.called); assert.isTrue(element.reload.called);
done(); done();
}); });
element.params = {group: 1, adminView: 'gr-group'}; element.params = {group: 1, view: Gerrit.Nav.View.GROUP};
element._groupName = 'oldName'; element._groupName = 'oldName';
flushAsynchronousOperations(); flushAsynchronousOperations();
element.$$('gr-group').fire('name-changed', {name: newName}); element.$$('gr-group').fire('name-changed', {name: newName});

View File

@@ -47,6 +47,11 @@ limitations under the License.
// - `leftSide`, optional, Boolean, if a `lineNum` is provided, a value // - `leftSide`, optional, Boolean, if a `lineNum` is provided, a value
// of true selects the line from base of the patch range. False by // of true selects the line from base of the patch range. False by
// default. // default.
//
// - Gerrit.Nav.View.GROUP:
// - `groupId`, required, String, the ID of the group.
// - `detail`, optional, String, the name of the group detail view.
// Takes any value from Gerrit.Nav.GroupDetailView.
window.Gerrit = window.Gerrit || {}; window.Gerrit = window.Gerrit || {};
@@ -71,6 +76,12 @@ limitations under the License.
EDIT: 'edit', EDIT: 'edit',
SEARCH: 'search', SEARCH: 'search',
SETTINGS: 'settings', SETTINGS: 'settings',
GROUP: 'group',
},
GroupDetailView: {
MEMBERS: 'members',
LOG: 'log',
}, },
/** @type {Function} */ /** @type {Function} */
@@ -315,6 +326,41 @@ limitations under the License.
} }
this._navigate(relativeUrl); this._navigate(relativeUrl);
}, },
/**
* @param {string} groupId
* @return {string}
*/
getUrlForGroup(groupId) {
return this._getUrlFor({
view: Gerrit.Nav.View.GROUP,
groupId,
});
},
/**
* @param {string} groupId
* @return {string}
*/
getUrlForGroupLog(groupId) {
return this._getUrlFor({
view: Gerrit.Nav.View.GROUP,
groupId,
detail: Gerrit.Nav.GroupDetailView.LOG,
});
},
/**
* @param {string} groupId
* @return {string}
*/
getUrlForGroupMembers(groupId) {
return this._getUrlFor({
view: Gerrit.Nav.View.GROUP,
groupId,
detail: Gerrit.Nav.GroupDetailView.MEMBERS,
});
},
}; };
})(window); })(window);
</script> </script>

View File

@@ -204,6 +204,8 @@
url = this._generateDashboardUrl(params); url = this._generateDashboardUrl(params);
} else if (params.view === Views.DIFF || params.view === Views.EDIT) { } else if (params.view === Views.DIFF || params.view === Views.EDIT) {
url = this._generateDiffOrEditUrl(params); url = this._generateDiffOrEditUrl(params);
} else if (params.view === Views.GROUP) {
url = this._generateGroupUrl(params);
} else { } else {
throw new Error('Can\'t generate'); throw new Error('Can\'t generate');
} }
@@ -313,6 +315,20 @@
} }
}, },
/**
* @param {!Object} params
* @return {string}
*/
_generateGroupUrl(params) {
let url = `/admin/groups/${this.encodeURL(params.groupId + '', true)}`;
if (params.detail === Gerrit.Nav.GroupDetailView.MEMBERS) {
url += ',members';
} else if (params.detail === Gerrit.Nav.GroupDetailView.LOG) {
url += ',audit-log';
}
return url;
},
/** /**
* Given an object of parameters, potentially including a `patchNum` or a * Given an object of parameters, potentially including a `patchNum` or a
* `basePatchNum` or both, return a string representation of that range. If * `basePatchNum` or both, return a string representation of that range. If
@@ -765,20 +781,25 @@
this._redirect('/admin/groups/' + encodeURIComponent(data.params[0])); this._redirect('/admin/groups/' + encodeURIComponent(data.params[0]));
}, },
_handleGroupRoute(data) {
this._setParams({
view: Gerrit.Nav.View.GROUP,
groupId: data.params[0],
});
},
_handleGroupAuditLogRoute(data) { _handleGroupAuditLogRoute(data) {
this._setParams({ this._setParams({
view: Gerrit.Nav.View.ADMIN, view: Gerrit.Nav.View.GROUP,
adminView: 'gr-group-audit-log', detail: Gerrit.Nav.GroupDetailView.LOG,
detailType: 'audit-log',
groupId: data.params[0], groupId: data.params[0],
}); });
}, },
_handleGroupMembersRoute(data) { _handleGroupMembersRoute(data) {
this._setParams({ this._setParams({
view: Gerrit.Nav.View.ADMIN, view: Gerrit.Nav.View.GROUP,
adminView: 'gr-group-members', detail: Gerrit.Nav.GroupDetailView.MEMBERS,
detailType: 'members',
groupId: data.params[0], groupId: data.params[0],
}); });
}, },
@@ -810,14 +831,6 @@
}); });
}, },
_handleGroupRoute(data) {
this._setParams({
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-group',
groupId: data.params[0],
});
},
_handleProjectCommandsRoute(data) { _handleProjectCommandsRoute(data) {
this._setParams({ this._setParams({
view: Gerrit.Nav.View.ADMIN, view: Gerrit.Nav.View.ADMIN,

View File

@@ -365,6 +365,36 @@ limitations under the License.
'/dashboard/user?name=query&title=custom%20dashboard'); '/dashboard/user?name=query&title=custom%20dashboard');
}); });
}); });
suite('groups', () => {
test('group info', () => {
const params = {
view: Gerrit.Nav.View.GROUP,
groupId: 1234,
};
assert.equal(element._generateUrl(params), '/admin/groups/1234');
});
test('group members', () => {
const params = {
view: Gerrit.Nav.View.GROUP,
groupId: 1234,
detail: 'members',
};
assert.equal(element._generateUrl(params),
'/admin/groups/1234,members');
});
test('group audit log', () => {
const params = {
view: Gerrit.Nav.View.GROUP,
groupId: 1234,
detail: 'log',
};
assert.equal(element._generateUrl(params),
'/admin/groups/1234,audit-log');
});
});
}); });
suite('param normalization', () => { suite('param normalization', () => {
@@ -804,9 +834,8 @@ limitations under the License.
test('_handleGroupAuditLogRoute', () => { test('_handleGroupAuditLogRoute', () => {
const data = {params: {0: 1234}}; const data = {params: {0: 1234}};
assertDataToParams(data, '_handleGroupAuditLogRoute', { assertDataToParams(data, '_handleGroupAuditLogRoute', {
view: Gerrit.Nav.View.ADMIN, view: Gerrit.Nav.View.GROUP,
adminView: 'gr-group-audit-log', detail: 'log',
detailType: 'audit-log',
groupId: 1234, groupId: 1234,
}); });
}); });
@@ -814,9 +843,8 @@ limitations under the License.
test('_handleGroupMembersRoute', () => { test('_handleGroupMembersRoute', () => {
const data = {params: {0: 1234}}; const data = {params: {0: 1234}};
assertDataToParams(data, '_handleGroupMembersRoute', { assertDataToParams(data, '_handleGroupMembersRoute', {
view: Gerrit.Nav.View.ADMIN, view: Gerrit.Nav.View.GROUP,
adminView: 'gr-group-members', detail: 'members',
detailType: 'members',
groupId: 1234, groupId: 1234,
}); });
}); });
@@ -872,8 +900,7 @@ limitations under the License.
test('_handleGroupRoute', () => { test('_handleGroupRoute', () => {
const data = {params: {0: 4321}}; const data = {params: {0: 4321}};
assertDataToParams(data, '_handleGroupRoute', { assertDataToParams(data, '_handleGroupRoute', {
view: Gerrit.Nav.View.ADMIN, view: Gerrit.Nav.View.GROUP,
adminView: 'gr-group',
groupId: 4321, groupId: 4321,
}); });
}); });

View File

@@ -138,7 +138,8 @@
this.set('_showChangeView', view === Gerrit.Nav.View.CHANGE); this.set('_showChangeView', view === Gerrit.Nav.View.CHANGE);
this.set('_showDiffView', view === Gerrit.Nav.View.DIFF); this.set('_showDiffView', view === Gerrit.Nav.View.DIFF);
this.set('_showSettingsView', view === Gerrit.Nav.View.SETTINGS); this.set('_showSettingsView', view === Gerrit.Nav.View.SETTINGS);
this.set('_showAdminView', view === Gerrit.Nav.View.ADMIN); this.set('_showAdminView', view === Gerrit.Nav.View.ADMIN ||
view === Gerrit.Nav.View.GROUP);
this.set('_showCLAView', view === Gerrit.Nav.View.AGREEMENTS); this.set('_showCLAView', view === Gerrit.Nav.View.AGREEMENTS);
this.set('_showEditorView', view === Gerrit.Nav.View.EDIT); this.set('_showEditorView', view === Gerrit.Nav.View.EDIT);
if (this.params.justRegistered) { if (this.params.justRegistered) {