Merge branch 'stable-2.16' into stable-3.0

* stable-2.16:
  Don't make the App reload when users go to the dashboard
  On initial load - FE decide if to show 404 otherwise it reloads

Change-Id: I831badbc554c23577ba0e0050ca7ceee892c1e39
This commit is contained in:
Paladox
2019-06-28 01:21:02 +01:00
4 changed files with 40 additions and 16 deletions

View File

@@ -310,11 +310,6 @@
// so we'll just disable it altogether for now.
delete linkObj.target;
// Because the user provided links may be arbitrary URLs, we don't know
// whether they correspond to any client routes. Mark all such links as
// external.
linkObj.external = true;
return linkObj;
},

View File

@@ -86,8 +86,8 @@ limitations under the License.
{url: 'https://awesometown.com/#hashyhash'},
{url: 'url', target: '_blank'},
].map(element._fixCustomMenuItem), [
{url: 'https://awesometown.com/#hashyhash', external: true},
{url: 'url', external: true},
{url: 'https://awesometown.com/#hashyhash'},
{url: 'url'},
]);
});
@@ -185,7 +185,6 @@ limitations under the License.
title: 'Plugins',
links: [{
name: 'Manage',
external: true,
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
}],
}]);
@@ -216,7 +215,6 @@ limitations under the License.
title: 'Projects',
links: [{
name: 'Project List',
external: true,
url: '/plugins/myplugin/index.html',
}],
}]);
@@ -249,11 +247,9 @@ limitations under the License.
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',
}],
}]);
@@ -279,7 +275,6 @@ limitations under the License.
title: 'Faves',
links: defaultLinks[0].links.concat([{
name: 'Manage',
external: true,
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
}]),
}, {
@@ -305,7 +300,6 @@ limitations under the License.
title: 'Your',
links: userLinks.concat([{
name: 'Manage',
external: true,
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
}]),
}, {
@@ -331,7 +325,6 @@ limitations under the License.
title: 'Browse',
links: adminLinks.concat([{
name: 'Manage',
external: true,
url: 'https://gerrit/plugins/plugin-manager/static/index.html',
}]),
}]);

View File

@@ -212,6 +212,12 @@
value: app,
},
_isRedirecting: Boolean,
// This variable is to differentiate between internal navigation (false)
// and for first navigation in app after loaded from server (true).
_isInitialLoad: {
type: Boolean,
value: true,
},
},
behaviors: [
@@ -692,6 +698,7 @@
this.$.reporting.beforeLocationChanged();
}
this._isRedirecting = false;
this._isInitialLoad = false;
next();
});
@@ -1461,7 +1468,13 @@
* Catchall route for when no other route is matched.
*/
_handleDefaultRoute() {
this._show404();
if (this._isInitialLoad) {
// Server recognized this route as polygerrit, so we show 404.
this._show404();
} else {
// Route can be recognized by server, so we pass it to server.
this._handlePassThroughRoute();
}
},
_show404() {

View File

@@ -631,6 +631,7 @@ limitations under the License.
suite('route handlers', () => {
let redirectStub;
let setParamsStub;
let handlePassThroughRoute;
// Simple route handlers are direct mappings from parsed route data to a
// new set of app.params. This test helper asserts that passing `data`
@@ -643,6 +644,7 @@ limitations under the License.
setup(() => {
redirectStub = sandbox.stub(element, '_redirect');
setParamsStub = sandbox.stub(element, '_setParams');
handlePassThroughRoute = sandbox.stub(element, '_handlePassThroughRoute');
});
test('_handleAgreementsRoute', () => {
@@ -674,7 +676,7 @@ limitations under the License.
});
});
test('_handleDefaultRoute', () => {
test('_handleDefaultRoute on first load', () => {
element._app = {dispatchEvent: sinon.stub()};
element._handleDefaultRoute();
assert.isTrue(element._app.dispatchEvent.calledOnce);
@@ -683,6 +685,27 @@ limitations under the License.
404);
});
test('_handleDefaultRoute after internal navigation', () => {
let onExit = null;
const onRegisteringExit = (match, _onExit) => {
onExit = _onExit;
};
sandbox.stub(window.page, 'exit', onRegisteringExit);
sandbox.stub(Gerrit.Nav, 'setup');
sandbox.stub(window.page, 'start');
sandbox.stub(window.page, 'base');
sandbox.stub(window, 'page');
element._startRouter();
element._app = {dispatchEvent: sinon.stub()};
element._handleDefaultRoute();
onExit('', () => {}); // we left page;
element._handleDefaultRoute();
assert.isTrue(handlePassThroughRoute.calledOnce);
});
test('_handleImproperlyEncodedPlusRoute', () => {
// Regression test for Issue 7100.
element._handleImproperlyEncodedPlusRoute(