From 265d685923f3bcc20ddf6c26bc80f1a48ab86dea Mon Sep 17 00:00:00 2001 From: E-T-K Date: Fri, 19 Jan 2024 00:14:14 +0000 Subject: [PATCH] feat: URLs now default to CA_IDs instead of latest variant ID Previously: variant URLs are variant/12345 an older-version URL would redirect to variant/12345?redirectedFrom=123 CA_IDs were available but non default, eg variant/CA98765 and would redirect. Now: variant/CA98765 does not redirect. variant/12345 (latest id) redirects to variant/CA98765 variant/123 (older id) redirects to variant/CA98765?redirectedFrom=123 If a latest id doesn't have a CA_ID (eg, the variant was deleted), fallback to the original behavior instead. The noRedirect=true param can still be added to prevent any of these redirects. --- website/js/index.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/website/js/index.js b/website/js/index.js index 449693811..823664959 100644 --- a/website/js/index.js +++ b/website/js/index.js @@ -621,17 +621,27 @@ var VariantDetail = React.createClass({ }); } - // ensure that we're viewing the latest version of the variant, and redirect if we're not, + // ensure that we're viewing the latest version of the variant, with the stable CA_ID URL. + // and redirect if we're not, // unless the querystring param 'noRedirect=true' is specified, in which case we stay here. + // In the rare case there is no CA_ID, redirect to the latest version by numeric ID instead. // (if someone *really* wants to link to the old variant, they may also specify 'noRedirectMsg=true' // to silence the warning at the top of the page, too.) const { data } = nextState; - - if (data && parseInt(this.props.params.id) !== data[0].id) { - // if the variant we're requesting isn't the newest version, we need to redirect to it + if (data && this.props.params.id !== data[0].CA_ID) { const { noRedirect } = this.getQuery(); if (noRedirect !== "true") { - this.replaceWith(`/variant/:id`, { id: data[0].id }, { redirectedFrom: this.props.params.id }); + // Redirect to CA_ID if it exists, or the latest numeric id if CA_ID doesn't exist. + const redirectToID = data[0].CA_ID || data[0].id ; + + // If we were already at the latest numeric ID, redirect without a redirectedFrom message. + if (parseInt(this.props.params.id) === data[0].id) { + this.replaceWith(`/variant/:id`, { id: redirectToID }, {}); + } + // Otherwise include redirectedFrom. + else { + this.replaceWith(`/variant/:id`, { id: redirectToID }, { redirectedFrom: this.props.params.id }); + } } } }, @@ -1276,13 +1286,14 @@ var VariantDetail = React.createClass({ } { - (variantVersionIdx !== 0 && noRedirectMsg !== "true") && ( + (variant.id !== data[0].id && noRedirectMsg !== "true") && ( + // if we're not on the latest variant version, show a message with link

There is new data available on this variant.

- The data below is from {util.reformatDate(variant.Data_Release.date)} (Release {variant.Data_Release.name}). Click here for updated data on this variant. + The data below is from {util.reformatDate(variant.Data_Release.date)} (Release {variant.Data_Release.name}). Click here for updated data on this variant.