Map legacy create routes to new routes

Previous routes:

/admin/create-project/ --> /admin/projects#create
/admin/create-group/ --> /admin/groups#create

Now do not have dedicated pages, but instead modals on the group list
and project list pages, respectively.

This change redirects the routes, and opens the corresponding modal
when the user lands on the page.

Change-Id: Ic50ff8e00dc1bf6361b6bd36c38fe8bac1106f6c
This commit is contained in:
Becky Siegel
2017-09-01 12:07:09 -07:00
parent f9cb7beda2
commit 28d1bf6f1e
6 changed files with 96 additions and 2 deletions

View File

@@ -70,6 +70,7 @@
attached() {
this._getCreateGroupCapability();
this.fire('title-change', {title: 'Groups'});
this._maybeOpenCreateOverlay(this.params);
},
_paramsChanged(params) {
@@ -81,6 +82,16 @@
this._offset);
},
/**
* Opens the create overlay if the route has a hash 'create'
* @param {!Object} params
*/
_maybeOpenCreateOverlay(params) {
if (params && params.openCreateModal) {
this.$.createOverlay.open();
}
},
_computeGroupUrl(id) {
return this.getUrl(this._path + '/', id);
},

View File

@@ -90,6 +90,18 @@ limitations under the License.
test('_shownGroups', () => {
assert.equal(element._shownGroups.length, 25);
});
test('_maybeOpenCreateOverlay', () => {
const overlayOpen = sandbox.stub(element.$.createOverlay, 'open');
element._maybeOpenCreateOverlay();
assert.isFalse(overlayOpen.called);
const params = {};
element._maybeOpenCreateOverlay(params);
assert.isFalse(overlayOpen.called);
params.openCreateModal = true;
element._maybeOpenCreateOverlay(params);
assert.isTrue(overlayOpen.called);
});
});
suite('test with less then 25 groups', () => {

View File

@@ -70,6 +70,7 @@
attached() {
this._getCreateProjectCapability();
this.fire('title-change', {title: 'Projects'});
this._maybeOpenCreateOverlay(this.params);
},
_paramsChanged(params) {
@@ -81,6 +82,16 @@
this._offset);
},
/**
* Opens the create overlay if the route has a hash 'create'
* @param {!Object} params
*/
_maybeOpenCreateOverlay(params) {
if (params && params.openCreateModal) {
this.$.createOverlay.open();
}
},
_computeProjectUrl(name) {
return this.getUrl(this._path + '/', name);
},

View File

@@ -66,13 +66,11 @@ limitations under the License.
suite('list with projects', () => {
setup(done => {
projects = _.times(26, projectGenerator);
stub('gr-rest-api-interface', {
getProjects(num, offset) {
return Promise.resolve(projects);
},
});
element._paramsChanged(value).then(() => { flush(done); });
});
@@ -86,6 +84,18 @@ limitations under the License.
test('_shownProjects', () => {
assert.equal(element._shownProjects.length, 25);
});
test('_maybeOpenCreateOverlay', () => {
const overlayOpen = sandbox.stub(element.$.createOverlay, 'open');
element._maybeOpenCreateOverlay();
assert.isFalse(overlayOpen.called);
const params = {};
element._maybeOpenCreateOverlay(params);
assert.isFalse(overlayOpen.called);
params.openCreateModal = true;
element._maybeOpenCreateOverlay(params);
assert.isTrue(overlayOpen.called);
});
});
suite('list with less then 25 projects', () => {

View File

@@ -46,6 +46,12 @@
GROUP_LIST_FILTER: '/admin/groups/q/filter::filter',
GROUP_LIST_FILTER_OFFSET: '/admin/groups/q/filter::filter,:offset',
// Matches /admin/create-project
LEGACY_CREATE_PROJECT: /^\/admin\/create-project\/?$/,
// Matches /admin/create-project
LEGACY_CREATE_GROUP: /^\/admin\/create-group\/?$/,
// Matches /admin/projects/<project>
PROJECT: /^\/admin\/projects\/([^,]+)$/,
@@ -463,6 +469,12 @@
this._mapRoute(RoutePattern.TAG_LIST_FILTER,
'_handleTagListFilterRoute');
this._mapRoute(RoutePattern.LEGACY_CREATE_GROUP,
'_handleCreateGroupRoute', true);
this._mapRoute(RoutePattern.LEGACY_CREATE_PROJECT,
'_handleCreateProjectRoute', true);
this._mapRoute(RoutePattern.PROJECT_LIST_OFFSET,
'_handleProjectListOffsetRoute');
@@ -612,6 +624,7 @@
adminView: 'gr-admin-group-list',
offset: data.params[1] || 0,
filter: null,
openCreateModal: data.hash === 'create',
});
},
@@ -728,6 +741,7 @@
adminView: 'gr-project-list',
offset: data.params[1] || 0,
filter: null,
openCreateModal: data.hash === 'create',
});
},
@@ -748,6 +762,18 @@
});
},
_handleCreateProjectRoute(data) {
// Redirects the legacy route to the new route, which displays the project
// list with a hash 'create'.
this._redirect('/admin/projects#create');
},
_handleCreateGroupRoute(data) {
// Redirects the legacy route to the new route, which displays the group
// list with a hash 'create'.
this._redirect('/admin/groups#create');
},
_handleProjectRoute(data) {
this._setParams({
view: Gerrit.Nav.View.ADMIN,

View File

@@ -125,6 +125,8 @@ limitations under the License.
const shouldRequireAutoAuth = [
'_handleAdminPlaceholderRoute',
'_handleAgreementsRoute',
'_handleCreateGroupRoute',
'_handleCreateProjectRoute',
'_handleDiffEditRoute',
'_handleGroupAuditLogRoute',
'_handleGroupInfoRoute',
@@ -641,6 +643,7 @@ limitations under the License.
adminView: 'gr-admin-group-list',
offset: 0,
filter: null,
openCreateModal: false,
});
data.params[1] = 42;
@@ -649,6 +652,16 @@ limitations under the License.
adminView: 'gr-admin-group-list',
offset: 42,
filter: null,
openCreateModal: false,
});
data.hash = 'create';
assertDataToParams(data, '_handleGroupListOffsetRoute', {
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-admin-group-list',
offset: 42,
filter: null,
openCreateModal: true,
});
});
@@ -812,6 +825,7 @@ limitations under the License.
adminView: 'gr-project-list',
offset: 0,
filter: null,
openCreateModal: false,
});
data.params[1] = 42;
@@ -820,6 +834,16 @@ limitations under the License.
adminView: 'gr-project-list',
offset: 42,
filter: null,
openCreateModal: false,
});
data.hash = 'create';
assertDataToParams(data, '_handleProjectListOffsetRoute', {
view: Gerrit.Nav.View.ADMIN,
adminView: 'gr-project-list',
offset: 42,
filter: null,
openCreateModal: true,
});
});