Skip to content

Commit 99d2b1b

Browse files
committed
feat(ui): show the deployed version in the top bar on a live server
The top bar read the version from the bootstrap, which only the mock data fills. It now reads the location's newest snapshot, and again when a new version is published.
1 parent 4e2311f commit 99d2b1b

6 files changed

Lines changed: 42 additions & 7 deletions

File tree

‎ui/src/lib/api/client.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {
2828
RunRowPage,
2929
RunRowQuery,
3030
RunStatement,
31+
Snapshot,
3132
RunTabCounts,
3233
Scope,
3334
SnapshotChange,
@@ -134,6 +135,8 @@ export interface ApiClient extends PlatformApi {
134135

135136
listPlatformEvents(query: { activeOnly: boolean }): Promise<PlatformEvent[]>;
136137

138+
/** The newest version deployed to the location; null before its first deploy. */
139+
getLatestSnapshot(scope: Scope): Promise<Snapshot | null>;
137140
/** Null when the location has reported no recent sync. */
138141
getWarehouseSync(scope: Scope): Promise<WarehouseSync | null>;
139142
/** Asks the location to read SQLBuild's state back from the warehouse now. `connection.test` */

‎ui/src/lib/api/http-client.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { checkDetailOf, toCheck, toCheckEvidence, toCheckSql } from './http-chec
77
import { findNode, nodeDetailOf, toCatalogNodes, nodeJobsOf, toMicrobatchCoverage, toNodeRuns, toColumnLineage } from './http-catalog';
88
import { auditMatches, toAuditEntry } from './http-audit';
99
import { toSnapshotChanges } from './http-changes';
10-
import { manualConnectionTest, toLocationDetail, toLocationSummary, toWarehouseConnection, warehouseSyncOf } from './http-locations';
10+
import { manualConnectionTest, snapshotOf, toLocationDetail, toLocationSummary, toWarehouseConnection, warehouseSyncOf } from './http-locations';
1111
import { toAccount, toRoleAssignments, toServerSettings } from './http-people';
1212
import { toMaintenanceHistory } from './http-maintenance';
1313
import { overviewOf } from './http-overview';
@@ -17,7 +17,7 @@ import { jobDetailOf, runWindowOf, toJob, toTick, toTrigger, toTriggerStateEvent
1717
import { timelineOf } from './http-timeline';
1818
import { RUN_WINDOW, groupRunNodes, parseRunCursor, planResultOf, queueEntriesOf, toAdhocCheck, runDetailOf, runRowPageOver, runsMatching, runTabCountsOf, toRunNode, toRuns, toRunEvent, toRunOutput, toRunStatements } from './http-runs';
1919
import type { ChangeSubscription, ChangedChannel, ChangedSignal, ConnectionState } from './signals';
20-
import type { AuthMode, Bootstrap, Capability, Location, NavCounts, PlatformEvent, Scope, WarehouseSync } from './types';
20+
import type { AuthMode, Bootstrap, Capability, Location, NavCounts, PlatformEvent, Scope, Snapshot, WarehouseSync } from './types';
2121
import type { Account, AuditEntry, AuditQuery, ConnectionTest, LocationDetail, ServerSettings, WarehouseConnection, LocationSummary, PlatformEventQuery, PlatformEventRecord, PlatformHealth, MaintenanceHistory, RoleAssignment, RoleAssignmentRequest, RoleDefinition, RoleDetail } from './types/platform';
2222
import type { Acknowledgement, CatalogNode, CatalogNodeDetail, Check, CheckDetail, CheckEvidence, CheckSql, Overview, SnapshotChange, ColumnLineage } from './types/build';
2323
import type { AdhocRunCheck, AdhocRunRequest, BulkRunResult, PlanResult, QueueEntry, Timeline, Job, JobDetail, JobLaunchOptions, RerunMode, SnapshotNode, Run, RunDetail, RunListQuery, RunRowPage, RunRowQuery, RunTabCounts, Trigger, TriggerDetail, TriggerState, RunEventPage, RunNodeError, RunOutputLine, RunStatement, StatementSql } from './types/operate';
@@ -79,6 +79,7 @@ const SUPPORTED: ReadonlySet<string> = new Set<keyof ApiClient>([
7979
'platformHealth',
8080
'listRoles',
8181
'getRole',
82+
'getLatestSnapshot',
8283
'getWarehouseSync',
8384
'requestWarehouseSync',
8485
'maintenanceHistory',
@@ -547,6 +548,13 @@ export function createHttpClient({ baseUrl = '', onUnauthorized, fetch: answer,
547548
}
548549
return found.slice(0, limit);
549550
},
551+
async getLatestSnapshot(scope: Scope): Promise<Snapshot | null> {
552+
const { locationId, target } = parseLocationKey(scope.locationId);
553+
const { data, error, response } = await http.GET('/api/control/locations/{location_id}/targets/{target}/snapshots', { params: { path: { location_id: locationId, target }, query: { limit: 1 } } });
554+
if (response.status === 401) onUnauthorized();
555+
if (!data) throw new ApiError(errorText(error, response), response.status);
556+
return snapshotOf(data[0] ?? null);
557+
},
550558
async getWarehouseSync(scope: Scope): Promise<WarehouseSync | null> {
551559
const { locationId, target } = parseLocationKey(scope.locationId);
552560
const { data, error, response } = await http.GET('/api/control/locations/{location_id}/targets/{target}/health', { params: { path: { location_id: locationId, target } } });

‎ui/src/lib/api/http-locations.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function manualConnectionTest(record: Wire['LocationWorkRecord'] | null):
5353
};
5454
}
5555

56-
function snapshotOf(published: Wire['PublishedSnapshot'] | null): Snapshot | null {
56+
export function snapshotOf(published: Wire['PublishedSnapshot'] | null): Snapshot | null {
5757
return published
5858
? {
5959
id: published.snapshot_id,

‎ui/src/lib/api/mock/mock-client.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
RunOutputLine,
2525
RunStatement,
2626
Scope,
27+
Snapshot,
2728
SnapshotNode,
2829
Timeline,
2930
Trigger,
@@ -329,6 +330,10 @@ export class MockApiClient implements ApiClient {
329330
return this.#reply(query.activeOnly ? events.filter((e) => e.active) : events);
330331
}
331332

333+
async getLatestSnapshot(scope: Scope): Promise<Snapshot | null> {
334+
return this.#reply(this.#location(scope).snapshot ?? null);
335+
}
336+
332337
async getWarehouseSync(scope: Scope): Promise<WarehouseSync> {
333338
this.#location(scope);
334339
return this.#reply({ ...this.#sync(scope) });

‎ui/src/lib/components/app-topbar.svelte‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,27 @@
3232
offline: 'Offline'
3333
};
3434
35-
const snapshot = $derived(app.location?.snapshot);
35+
const snapshot = $derived(app.snapshot);
36+
const where = $derived(app.location ? `${app.location.name} · ${targetWords(app.location.target)}` : '—');
3637
</script>
3738

3839
<div class="app-topbar flex h-[52px] shrink-0 items-center gap-3 border-b border-border px-5">
3940
<h1 class="text-[15px] font-semibold">{title}</h1>
40-
<span class="text-muted-foreground text-[12.5px]">{app.location ? `${app.location.name} · ${targetWords(app.location.target)}` : '—'}</span>
41+
<span class="text-muted-foreground min-w-0 truncate text-[12.5px]" title={where}>{where}</span>
4142
<div class="ml-auto flex items-center gap-2.5">
4243
<span
4344
class="text-muted-foreground flex items-center gap-[7px] text-[12px]"
4445
title={snapshot === undefined
4546
? connectionTitle[app.connection]
4647
: `${connectionTitle[app.connection]}\n${snapshot
47-
? `Version ${snapshot.generation}: commit ${snapshot.gitRevision}${snapshot.gitDirty ? ' (with uncommitted changes)' : ''} by ${snapshot.gitAuthor} (snapshot ${snapshot.id}, generation ${snapshot.generation})`
48+
? `Version ${snapshot.generation}${snapshot.gitRevision ? `: commit ${snapshot.gitRevision}${snapshot.gitDirty ? ' (with uncommitted changes)' : ''}${snapshot.gitAuthor ? ` by ${snapshot.gitAuthor}` : ''}` : ', not from a git commit'} (snapshot ${snapshot.id}, generation ${snapshot.generation})`
4849
: 'Nothing deployed to this location yet'}`}
4950
>
5051
<!-- A fixed slot, so going from Connecting to Live doesn't shift the bar. -->
5152
<span class="connection"><span class="h-[7px] w-[7px] rounded-full" style:background={connectionTone[app.connection]}></span>{connectionLabel[app.connection]}</span>
5253
{#if snapshot !== undefined}
5354
<span class="text-[var(--sb-text-faint)]">·</span>
54-
{snapshot ? `Version ${snapshot.generation}, deployed ${formatAgo(snapshot.publishedAt, app.now)}` : 'nothing deployed yet'}
55+
<span class="whitespace-nowrap">{snapshot ? `Version ${snapshot.generation}, deployed ${formatAgo(snapshot.publishedAt, app.now)}` : 'nothing deployed yet'}</span>
5556
{/if}
5657
</span>
5758
{#if app.client.supports('getWarehouseSync')}

‎ui/src/lib/state/app.svelte.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
type NavCounts,
1717
type PlatformEvent,
1818
type Scope,
19+
type Snapshot,
1920
type WarehouseSync
2021
} from '$lib/api';
2122

@@ -38,6 +39,8 @@ class AppState {
3839
navCounts = $state<NavCounts | null>(null);
3940
platformEvents = $state<PlatformEvent[]>([]);
4041
warehouseSync = $state<WarehouseSync | null>(null);
42+
/** The selected location's newest deployed version: undefined until read, null before its first deploy. */
43+
snapshot = $state<Snapshot | null | undefined>(undefined);
4144

4245
readonly scope = $derived<Scope | null>(this.locationId ? { locationId: this.locationId } : null);
4346
readonly location = $derived(this.bootstrap?.locations.find((l) => l.id === this.locationId) ?? null);
@@ -81,6 +84,7 @@ class AppState {
8184
this.client.changes.subscribe((signal) => {
8285
if (channelMatches(signal.channel, ['platform_events'])) void this.#loadPlatformEvents();
8386
if (channelMatches(signal.channel, ['warehouse_sync'])) void this.#loadWarehouseSync();
87+
if (channelMatches(signal.channel, ['snapshot'])) void this.#loadSnapshot();
8488
if (channelMatches(signal.channel, ['runs', 'triggers', 'checks'])) void this.#loadNavCounts();
8589
});
8690
try {
@@ -118,6 +122,7 @@ class AppState {
118122
this.client.changes.follow(this.scope);
119123
this.navCounts = null;
120124
this.warehouseSync = null;
125+
this.snapshot = undefined;
121126
this.#loadScoped();
122127
}
123128

@@ -140,6 +145,19 @@ class AppState {
140145
#loadScoped() {
141146
void this.#loadNavCounts();
142147
void this.#loadWarehouseSync();
148+
void this.#loadSnapshot();
149+
}
150+
151+
async #loadSnapshot() {
152+
if (!this.client.supports('getLatestSnapshot')) return;
153+
const scope = this.scope;
154+
if (!scope) return;
155+
try {
156+
const snapshot = await this.client.getLatestSnapshot(scope);
157+
if (this.scope === scope) this.snapshot = snapshot;
158+
} catch {
159+
// The version is decoration; a person who may not read it sees the bar without it.
160+
}
143161
}
144162

145163
async #loadNavCounts() {

0 commit comments

Comments
 (0)