Skip to content

Commit dd884cc

Browse files
committed
fix(web): centre-truncate image digests in the UI
- Enhanced `shortImage()` to centre-truncate bare `sha256:…` digests, keeping the algorithm prefix and first/last 6 hex characters so digests remain distinguishable on narrow layouts - Added `shortenDigest()` and `shortenSha256()` helpers to handle both tagged refs (e.g. `textile-stitch:latest`) unchanged and digest-only refs (e.g. `sha256:ce1d74…2fef60`) - Added `title` attributes to image references in BotDetail and Fleet to show the full digest on hover - Updated BotDetail and Fleet row image displays with monospace font to match digest formatting
1 parent bb8e797 commit dd884cc

7 files changed

Lines changed: 41 additions & 10 deletions

File tree

.textile-monorepo-source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4ed54f528104b8c429126bb591e440890cf073ca
1+
e1a1f43c78c7c42fa16002408fedc3f69096b442

.textile-stitch-release-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.111
1+
0.1.112

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stitch-bot"
3-
version = "0.1.111"
3+
version = "0.1.112"
44
edition = "2021"
55
description = "Stitch — Textile filler-network operator bot; market-makes the filler order book with signed UniswapX limit orders."
66
license = "AGPL-3.0-or-later"

web/src/format.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,33 @@ export function shortAddress(address: string): string {
6666
: address
6767
}
6868

69-
/** An image reference with its registry path dropped, keeping the tag. */
69+
/**
70+
* An image reference short enough for a fleet row or detail cell.
71+
*
72+
* Drops the registry path, then centre-truncates a content digest so a bare
73+
* `sha256:…` (or `name@sha256:…`) does not shove the rest of the layout off
74+
* screen. Tagged refs like `textile-stitch:latest` stay as-is.
75+
*/
7076
export function shortImage(image: string | null): string {
7177
if (!image) return '—'
7278
const lastSlash = image.lastIndexOf('/')
73-
return lastSlash === -1 ? image : image.slice(lastSlash + 1)
79+
const name = lastSlash === -1 ? image : image.slice(lastSlash + 1)
80+
return shortenDigest(name)
81+
}
82+
83+
/** `sha256:ce1d74…2fef60` — keeps the prefix and enough hex to tell digests apart. */
84+
function shortenDigest(ref: string): string {
85+
const at = ref.lastIndexOf('@')
86+
if (at !== -1) {
87+
const name = ref.slice(0, at)
88+
const digest = ref.slice(at + 1)
89+
return `${name}@${shortenSha256(digest)}`
90+
}
91+
return shortenSha256(ref)
92+
}
93+
94+
function shortenSha256(value: string): string {
95+
const hex = value.startsWith('sha256:') ? value.slice('sha256:'.length) : null
96+
if (hex === null || hex.length <= 12) return value
97+
return `sha256:${hex.slice(0, 6)}${hex.slice(-6)}`
7498
}

web/src/pages/BotDetail.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ export default function BotDetail() {
245245
<dl className="mt-4 grid gap-3 text-sm sm:grid-cols-2 lg:grid-cols-4">
246246
<Detail label="Origin">{bot.origin}</Detail>
247247
<Detail label="Layout">{bot.layout}</Detail>
248-
<Detail label="Image">{shortImage(bot.image)}</Detail>
248+
<Detail label="Image">
249+
<span className="font-mono" title={bot.image ?? undefined}>
250+
{shortImage(bot.image)}
251+
</span>
252+
</Detail>
249253
<Detail label="Created">{formatTimestamp(bot.createdUnix)}</Detail>
250254
<Detail label="Chain">{bot.config ? bot.config.chainId : '—'}</Detail>
251255
<Detail label="Pools">{bot.config ? bot.config.pools : '—'}</Detail>

web/src/pages/Fleet.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export default function Fleet() {
137137
)}
138138

139139
<p className="text-xs text-faint">
140-
New bots run <code>{shortImage(data.botImage)}</code>. Configs live in{' '}
141-
<code>{data.botsDir}</code>.
140+
New bots run{' '}
141+
<code title={data.botImage}>{shortImage(data.botImage)}</code>. Configs
142+
live in <code>{data.botsDir}</code>.
142143
</p>
143144
</div>
144145
)
@@ -236,7 +237,9 @@ function BotRow({
236237
</Tag>
237238
)}
238239
{bot.config && <Tag>{bot.config.signer}</Tag>}
239-
<span className="ml-auto">{shortImage(bot.image)}</span>
240+
<span className="ml-auto font-mono" title={bot.image ?? undefined}>
241+
{shortImage(bot.image)}
242+
</span>
240243
</div>
241244

242245
{(blocking.length > 0 || advisory.length > 0) && (

0 commit comments

Comments
 (0)