All files / src/components BuildInfo.tsx

66.66% Statements 12/18
63.63% Branches 14/22
66.66% Functions 2/3
73.33% Lines 11/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61        5x 5x 5x   5x       20x                                   20x 20x 20x 20x 20x   20x                                                
"use client";
 
import { ExternalLink } from "lucide-react";
 
const VERSION = process.env.NEXT_PUBLIC_APP_VERSION ?? "0.0.0";
const CHANNEL = process.env.NEXT_PUBLIC_BUILD_CHANNEL ?? "local";
const BUILD_TIME = process.env.NEXT_PUBLIC_BUILD_TIME ?? "";
const REPO_URL =
  process.env.NEXT_PUBLIC_REPO_URL ??
  "https://github.com/ma3u/MinimumViableHealthDataspacev2";
 
function shortDate(iso: string): string {
  Eif (!iso) return "";
  const d = new Date(iso);
  if (Number.isNaN(d.getTime())) return "";
  const pad = (n: number) => String(n).padStart(2, "0");
  return `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(
    d.getUTCDate(),
  )}`;
}
 
/**
 * Compact version badge shown to the right of Sign out: `vX.Y.Z · YYYY-MM-DD`
 * linking to the GitHub release page. Just the date (no time, no commit SHA)
 * — enough to correlate a reported issue to a release without clutter.
 *
 * Local builds add a "+local" amber marker so we never mistake a dev
 * container for a released Azure / GitHub Pages demo.
 */
export function BuildInfo() {
  const isLocal = CHANNEL !== "release";
  const tag = `v${VERSION}`;
  const date = shortDate(BUILD_TIME);
  const releaseHref = `${REPO_URL}/releases/tag/${tag}`;
  const releasesHref = `${REPO_URL}/releases`;
 
  return (
    <div data-testid="user-menu-build-info">
      <a
        href={isLocal ? releasesHref : releaseHref}
        target="_blank"
        rel="noreferrer noopener"
        className="inline-flex items-center gap-1 font-mono text-[10px] leading-tight text-[var(--text-secondary)] hover:text-[var(--accent)] hover:underline"
        aria-label={
          isLocal
            ? `Open releases page (local build ${tag})`
            : `Open release ${tag}${date ? ` (${date})` : ""}`
        }
        data-testid="user-menu-version-link"
      >
        <span>{tag}</span>
        {isLocal && (
          <span className="text-amber-600 dark:text-amber-400">+local</span>
        )}
        {date && <span className="opacity-70">· {date}</span>}
        <ExternalLink size={9} aria-hidden="true" />
      </a>
    </div>
  );
}