From c4bfb532bad9d6ae515abda7b3bdb8efe1474d92 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Sat, 28 Sep 2019 20:50:15 -0400 Subject: [PATCH 1/3] Fixed version suggestion logic. Previously, if it had search everything and found nothing, that means it also cannot find `maxVersion`. Thus, this commit's solution is to simply find anything that is not yet yanked even if it is unstable. If even this fails, then we truly have nothing to offer thereby offering an empty page. --- app/routes/crate/version.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index b4e03785c09..1a6aeb53c5f 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -11,7 +11,7 @@ export default Route.extend({ flashMessages: service(), - refreshAfterLogin: observer('session.isLoggedIn', function() { + refreshAfterLogin: observer('session.isLoggedIn', function () { this.refresh(); }), @@ -43,14 +43,28 @@ export default Route.extend({ .get('versions') .then(versions => { const latestStableVersion = versions.find(version => { + // Find the latest version that is stable AND not-yanked. if (!isUnstableVersion(version.get('num')) && !version.get('yanked')) { return version; } }); if (latestStableVersion == null) { - // If no stable version exists, fallback to `maxVersion` - params.version_num = maxVersion; + // Cannot find any version that is stable AND not-yanked. + // The fact that "maxVersion" itself cannot be found means that + // we have to fall back to the latest one that is unstable.... + const latestUnyankedVersion = versions.find(version => { + // Find the latest version that is stable AND not-yanked. + if (!version.get('yanked')) { + return version; + } + }); + if (latestStableVersion == null) { + // There's not even any unyanked version... + params.version_num = maxVersion; + } else { + params.version_num = latestUnyankedVersion; + } } else { params.version_num = latestStableVersion.get('num'); } From 90f7533a3d9649a899b41f8ab7227c2367653742 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Sun, 29 Sep 2019 17:15:30 -0400 Subject: [PATCH 2/3] Minute change --- app/routes/crate/version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 1a6aeb53c5f..51b7b0764cb 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -11,7 +11,7 @@ export default Route.extend({ flashMessages: service(), - refreshAfterLogin: observer('session.isLoggedIn', function () { + refreshAfterLogin: observer('session.isLoggedIn', function() { this.refresh(); }), From e7abdfc27e43e82589134dc185525460eaff19b3 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Thu, 3 Oct 2019 16:37:20 +0100 Subject: [PATCH 3/3] Update version.js --- app/routes/crate/version.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 51b7b0764cb..5150da20f10 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -59,6 +59,7 @@ export default Route.extend({ return version; } }); + if (latestStableVersion == null) { // There's not even any unyanked version... params.version_num = maxVersion;