From 73809a4b567a9280f6dda269b17cf1e5d3ebc950 Mon Sep 17 00:00:00 2001
From: Arie Peterson <arie@greenhost.nl>
Date: Fri, 16 Jun 2023 11:17:28 +0200
Subject: [PATCH] Detect flux stable branch in frontend using regex

---
 .../components/VersionInfo/VersionInfo.tsx    | 57 +++++++++----------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/frontend/src/modules/dashboard/components/VersionInfo/VersionInfo.tsx b/frontend/src/modules/dashboard/components/VersionInfo/VersionInfo.tsx
index 60251d8c..8f7da1cb 100644
--- a/frontend/src/modules/dashboard/components/VersionInfo/VersionInfo.tsx
+++ b/frontend/src/modules/dashboard/components/VersionInfo/VersionInfo.tsx
@@ -15,40 +15,37 @@ export const VersionInfo = (sysInfo: SysInfoState) => {
   const branch = sysInfo.sysInfo.followingGit;
   const updateTime: Date = new Date(sysInfo.sysInfo.lastUpdated);
 
-  // eslint-disable-next-line
-  // let branch = 'DF234FD';
-  const knownMainBranch = 'v2';
+  const branchInfoAvailable = typeof branch !== 'undefined';
+  const stableBranch = branchInfoAvailable ? branch.match(/^v(\d)+$/) : false;
 
-  const versionInfo =
-    branch === knownMainBranch ? (
-      <>
-        <CheckCircleIcon className="h-4 w-4 text-primary-600" />
-        <span>Stackspin v{sysInfo.sysInfo.version}</span>
-      </>
-    ) : branch !== knownMainBranch ? (
-      <>
-        <span>Stackspin v{sysInfo.sysInfo.version}</span>
-      </>
-    ) : null;
+  const versionInfo = stableBranch ? (
+    <>
+      <CheckCircleIcon className="h-4 w-4 text-primary-600" />
+      <span>Stackspin v{sysInfo.sysInfo.version}</span>
+    </>
+  ) : branchInfoAvailable ? (
+    <>
+      <span>Stackspin v{sysInfo.sysInfo.version}</span>
+    </>
+  ) : null;
 
-  const updatesText =
-    branch === knownMainBranch ? (
-      <>
-        <div className="px-4 py-2 flex items-center gap-1">
-          <HomeIcon className="w-4 h-4 text-gray-500" />
-          <span>Latest stable branch ({branch})</span>
-        </div>
-        <div className="px-4 py-2 flex items-center gap-1">
-          <RefreshIcon className="w-4 h-4 text-gray-500" />
-          <span>Automatic updates active</span>
-        </div>
-      </>
-    ) : branch !== knownMainBranch ? (
+  const updatesText = stableBranch ? (
+    <>
       <div className="px-4 py-2 flex items-center gap-1">
-        <BeakerIcon className="w-4 h-4 text-gray-500" />
-        <span>Custom branch ({branch})</span>
+        <HomeIcon className="w-4 h-4 text-gray-500" />
+        <span>Latest stable branch ({branch})</span>
       </div>
-    ) : null;
+      <div className="px-4 py-2 flex items-center gap-1">
+        <RefreshIcon className="w-4 h-4 text-gray-500" />
+        <span>Automatic updates active</span>
+      </div>
+    </>
+  ) : branchInfoAvailable ? (
+    <div className="px-4 py-2 flex items-center gap-1">
+      <BeakerIcon className="w-4 h-4 text-gray-500" />
+      <span>Custom branch ({branch})</span>
+    </div>
+  ) : null;
 
   return (
     <Popover className="relative flex items-center">
-- 
GitLab