client: show build version + browser diagnostics for bug triage
Fixes #68. - Bar switcher and stats page get a low-contrast "wutzcalc <git-sha>" footer at the bottom (VersionFooter component, shared). - Admin panel gets a fuller Diagnose section: version, user agent, screen resolution + device pixel ratio, viewport size, browser language. Version is the short git commit sha, baked in at build time via vite.config.ts define (falls back to "dev" if .git is unavailable at build time, e.g. a tarball/CI-artifact deploy) - matches how deploys actually run (pnpm build from a git checkout, per deploy/wutzcalc.service), but stays defensive rather than failing the build. pnpm --filter client typecheck and build both clean.
This commit is contained in:
parent
f838db0663
commit
09e1bec9bb
7 changed files with 96 additions and 0 deletions
24
client/src/VersionFooter.tsx
Normal file
24
client/src/VersionFooter.tsx
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// #68: version/diagnostics display, shared by the two low-contrast
|
||||
// footers (BarPicker, Stats) and Admin's fuller diagnostics block —
|
||||
// same underlying info (build version + browser environment), different
|
||||
// presentation for a quick glance vs. a bug-triage read.
|
||||
|
||||
export const appVersion = __APP_VERSION__;
|
||||
|
||||
export function VersionFooter() {
|
||||
return <p class="version-footer">wutzcalc {appVersion}</p>;
|
||||
}
|
||||
|
||||
// Read fresh on every call rather than once at module load — screen/
|
||||
// viewport size can change (rotation, window resize) between when the
|
||||
// admin panel first mounts and when someone actually looks at this to
|
||||
// triage a report.
|
||||
export function diagLines(): string[] {
|
||||
return [
|
||||
`Version: ${appVersion}`,
|
||||
`User-Agent: ${navigator.userAgent}`,
|
||||
`Bildschirm: ${screen.width}×${screen.height} @ ${window.devicePixelRatio}x`,
|
||||
`Viewport: ${window.innerWidth}×${window.innerHeight}`,
|
||||
`Sprache: ${navigator.language}`,
|
||||
];
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||
import type { Bar, Drink } from '@wutzcalc/shared';
|
||||
import { errText, formatCents, j } from '../api';
|
||||
import { diagLines } from '../VersionFooter';
|
||||
|
||||
// `Drink`/`Bar` come from @wutzcalc/shared — the tablet code already did
|
||||
// this, but Admin.tsx used to re-declare its own near-identical copies,
|
||||
|
|
@ -86,10 +87,25 @@ function Dashboard({ onLogout }: { onLogout: () => void }) {
|
|||
<Exports />
|
||||
<Drinks drinks={drinks} reload={reloadDrinks} />
|
||||
<Bars drinks={drinks} />
|
||||
<Diagnose />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// #68: browser/build metadata for triaging a device-specific bug report
|
||||
// (e.g. "scrolling doesn't work on this one kiosk tablet") without having
|
||||
// to walk someone through DevTools over the phone.
|
||||
function Diagnose() {
|
||||
return (
|
||||
<>
|
||||
<h2>Diagnose</h2>
|
||||
<ul class="diag-list">
|
||||
{diagLines().map(l => <li key={l}>{l}</li>)}
|
||||
</ul>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function Exports() {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useEffect, useMemo, useState } from 'preact/hooks';
|
||||
import { errText, formatCents, j } from '../api';
|
||||
import { DayChart } from './DayChart';
|
||||
import { VersionFooter } from '../VersionFooter';
|
||||
|
||||
interface Totals { bar_id: number; bar_name: string; tx_count: number; paid_cents: number; crew_count: number; pfand_returns: number }
|
||||
interface PerDrink { drink_id: number; drink_name: string; sold_qty: number }
|
||||
|
|
@ -257,6 +258,8 @@ function Dashboard({ data, isAdmin, onReset }: { data: StatsData; isAdmin: boole
|
|||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<VersionFooter />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,21 @@ button.danger { background: #5a2a2a; border-color: #7a3a3a; color: #fff; }
|
|||
padding: 10px 18px;
|
||||
}
|
||||
|
||||
/* #68: version/build indicator for bug triage. margin-top: auto pins it
|
||||
to the bottom of a flex column (.bar-picker) without disturbing that
|
||||
column's own justify-content: center for everything above it; in a
|
||||
plain block container (Stats.tsx's .admin) margin-top: auto has no
|
||||
special effect, so it just falls in as the last item on the page —
|
||||
same class works in both contexts without a variant. */
|
||||
.version-footer {
|
||||
margin-top: auto;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
opacity: 0.35;
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
|
@ -311,6 +326,20 @@ button.danger { background: #5a2a2a; border-color: #7a3a3a; color: #fff; }
|
|||
}
|
||||
.admin .row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
|
||||
.admin .muted { opacity: 0.6; }
|
||||
/* #68: readable-but-secondary — not as dim as .muted, this is meant to
|
||||
actually be read for bug triage, just not competing with the primary
|
||||
admin content above it. break-all because navigator.userAgent runs
|
||||
long and would otherwise overflow .admin's max-width. */
|
||||
.diag-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: 13px;
|
||||
font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
|
||||
opacity: 0.8;
|
||||
word-break: break-all;
|
||||
}
|
||||
.diag-list li { padding: 3px 0; }
|
||||
.admin .login { max-width: 320px; margin: 80px auto; display: flex; flex-direction: column; gap: 12px; }
|
||||
.admin .chart {
|
||||
background: var(--surface);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useState } from 'preact/hooks';
|
||||
import type { Bar } from '@wutzcalc/shared';
|
||||
import { getTheme, setTheme } from '../api';
|
||||
import { VersionFooter } from '../VersionFooter';
|
||||
|
||||
interface Props {
|
||||
bars: Bar[] | null;
|
||||
|
|
@ -35,6 +36,7 @@ export function BarPicker({ bars, onPick }: Props) {
|
|||
<button class="theme-toggle" onClick={toggleTheme}>
|
||||
{theme === 'dark' ? '☀ Heller Modus' : '🌙 Dunkler Modus'}
|
||||
</button>
|
||||
<VersionFooter />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
5
client/src/vite-env.d.ts
vendored
Normal file
5
client/src/vite-env.d.ts
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/// <reference types="vite/client" />
|
||||
|
||||
// Injected by vite.config.ts's `define` — the short git commit sha the
|
||||
// bundle was built from, or 'dev' if `.git` wasn't available at build time.
|
||||
declare const __APP_VERSION__: string;
|
||||
|
|
@ -2,6 +2,7 @@ import { defineConfig } from 'vite';
|
|||
import preact from '@preact/preset-vite';
|
||||
import legacy from '@vitejs/plugin-legacy';
|
||||
import { resolve } from 'node:path';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
// The dev-server proxy target — same default (3000) as the server's own
|
||||
// `process.env.PORT ?? 3000` in server/src/index.ts. Override with
|
||||
|
|
@ -10,7 +11,23 @@ import { resolve } from 'node:path';
|
|||
// WUTZ_SERVER_PORT=4000 pnpm dev:client
|
||||
const serverTarget = `http://localhost:${process.env.WUTZ_SERVER_PORT ?? 3000}`;
|
||||
|
||||
// #68: baked into the bundle at build time so the client can show "which
|
||||
// build is this" for bug triage without a server round-trip. Deploys run
|
||||
// `pnpm build` from a git checkout (see deploy/wutzcalc.service), but this
|
||||
// stays defensive against a tarball/CI-artifact deploy with no `.git` —
|
||||
// falls back to 'dev' rather than failing the build.
|
||||
function appVersion(): string {
|
||||
try {
|
||||
return execSync('git rev-parse --short HEAD', { cwd: __dirname }).toString().trim();
|
||||
} catch {
|
||||
return 'dev';
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
define: {
|
||||
__APP_VERSION__: JSON.stringify(appVersion()),
|
||||
},
|
||||
plugins: [
|
||||
preact(),
|
||||
legacy({
|
||||
|
|
|
|||
Loading…
Reference in a new issue