From 2ea5a281fcaa41ce165513e112b0a8c9fdd3d00a Mon Sep 17 00:00:00 2001
From: Scott Anderson <scott@influxdata.com>
Date: Mon, 30 Nov 2020 16:08:11 -0700
Subject: [PATCH] updated product selector to maintain context when switching
 between cloud and oss

---
 layouts/partials/topnav/product-selector.html | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/layouts/partials/topnav/product-selector.html b/layouts/partials/topnav/product-selector.html
index c5f4c5c5c..9969f26ce 100644
--- a/layouts/partials/topnav/product-selector.html
+++ b/layouts/partials/topnav/product-selector.html
@@ -1,7 +1,9 @@
+{{ $scratch := newScratch }}
 {{ $productPathData := findRE "[^/]+.*?" .RelPermalink }}
 {{ $product := index $productPathData 0 }}
 {{ $currentVersion := index $productPathData 1 }}
 {{ $isCloud := eq "influxdb/cloud" (print $product "/" $currentVersion )}}
+{{ $isOSSv2 := in (print $product "/" $currentVersion ) "influxdb/v2."}}
 
 <div class="dropdown">
   {{ if or (eq $product nil) (eq $product "platform") }}
@@ -14,8 +16,21 @@
   {{ end }}
   <ul class="item-list">
     {{ range sort .Site.Data.products "list_order" "desc" }}
+      {{ $scratch.Set "link" (print "/" .namespace "/" .latest "/") }}
+      {{ if and $isCloud (eq .altname "InfluxDB OSS")}}
+        {{ $altOSSPage := $.GetPage (replaceRE "influxdb/cloud" (print "influxdb/" $.Site.Data.products.influxdb.latest) $.Page.RelPermalink) }}
+        {{ if gt (len $altOSSPage.Title) 0 }}
+          {{ $scratch.Set "link" $altOSSPage.RelPermalink }}
+        {{ end }}
+      {{ else if and $isOSSv2 (eq .altname "InfluxDB Cloud") }}
+        {{ $altCloudPage := $.GetPage (replaceRE $currentVersion "cloud" $.Page.RelPermalink) }}
+        {{ if gt (len $altCloudPage.Title) 0 }}
+          {{ $scratch.Set "link" $altCloudPage.RelPermalink }}
+        {{ end }}
+      {{ end }}
+      {{ $link := $scratch.Get "link" }}
       <li>
-        <a href='/{{ .namespace }}/{{ cond (isset . "latest_override") .latest_override .latest }}/' {{ if and (eq .namespace $product) (in .versions $currentVersion) }}class="active"{{ end }}>{{ cond (isset . "altname") .altname .name }}</a>
+        <a href='{{ $link }}' {{ if and (eq .namespace $product) (in .versions $currentVersion) }}class="active"{{ end }}>{{ cond (isset . "altname") .altname .name }}</a>
       </li>
     {{ end }}
   </ul>