Skip to content

Commit bb50cb4

Browse files
committed
fix(dashboard): coerce a string logoHeight and center a text logo
Review found that a quoted logoHeight (config.json may serialize it as "48") was rejected by resolveLogoHeight and silently fell back to 36px; coerce a numeric string. Center a text logo vertically within the configured height instead of pinning it to the top. Add AppShell-level coverage for the logoHeight passthrough, which the Header-only test did not exercise. Assisted-by: LLM Signed-off-by: IvanHunters <[email protected]>
1 parent 3ec2a76 commit bb50cb4

5 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎packages/system/dashboard/images/console/apps/console/src/__tests__/header-logo.test.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from "vitest"
22
import { render } from "@testing-library/react"
33
import { MemoryRouter } from "react-router"
4-
import { Header } from "@cozystack/ui"
4+
import { Header, AppShell } from "@cozystack/ui"
55

66
function renderHeader(props: Record<string, unknown> = {}) {
77
return render(
@@ -34,4 +34,18 @@ describe("Header logo sizing", () => {
3434
const { container } = renderHeader({ logoHeight: Number.NaN })
3535
expect(container.querySelector("img")?.style.height).toBe("36px")
3636
})
37+
38+
it("coerces a numeric-string logoHeight (branding config.json ships it as a string)", () => {
39+
const { container } = renderHeader({ logoHeight: "48" })
40+
expect(container.querySelector("img")?.style.height).toBe("48px")
41+
})
42+
43+
it("passes logoHeight through AppShell to the header logo", () => {
44+
const { container } = render(
45+
<MemoryRouter>
46+
<AppShell sections={[]} logoHeight={64} />
47+
</MemoryRouter>,
48+
)
49+
expect(container.querySelector("img")?.style.height).toBe("64px")
50+
})
3751
})

‎packages/system/dashboard/images/console/apps/console/src/lib/config.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export interface AppConfig {
66
logoText?: string
77
logoSvg?: string
88
// Logo height in px for the header. Lets a square logo be shown larger than
9-
// the default 36px (tuned for the wide default logo). Clamped on render.
10-
logoHeight?: number
9+
// the default 36px (tuned for the wide default logo). Clamped on render, and
10+
// a numeric string (as config.json may serialize it) is coerced there too.
11+
logoHeight?: number | string
1112
iconSvg?: string
1213
// Platform version injected at deploy time by the chart (from the console
1314
// image tag), so a promoted-by-retag image reports the stable version rather

‎packages/system/dashboard/images/console/packages/ui/src/components/Logo.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ export function Logo({ className, title = "Cozystack", svgContent, text, style }
2424
)
2525
}
2626
if (text) {
27+
// inline-flex + items-center so a configured height (style.height) centers
28+
// the label vertically instead of leaving it pinned to the top.
2729
return (
28-
<span className={className} style={style}>
30+
<span className={`${className ?? ""} inline-flex items-center`} style={style}>
2931
{text}
3032
</span>
3133
)

‎packages/system/dashboard/images/console/packages/ui/src/components/layout/AppShell.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface AppShellProps {
1616
children?: ReactNode
1717
logoSvg?: string
1818
logoText?: string
19-
logoHeight?: number
19+
logoHeight?: number | string
2020
}
2121

2222
export function AppShell({

‎packages/system/dashboard/images/console/packages/ui/src/components/layout/Header.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ interface HeaderProps {
2525
logoSvg?: string
2626
logoText?: string
2727
/** Logo height in px. Defaults to 36 and is clamped to a sane range so a
28-
* square logo can be enlarged without a bad config value deforming the bar. */
29-
logoHeight?: number
28+
* square logo can be enlarged without a bad config value deforming the bar.
29+
* Accepts a numeric string too, since branding config.json may ship "48". */
30+
logoHeight?: number | string
3031
}
3132

3233
const DEFAULT_LOGO_HEIGHT = 36
3334
const MIN_LOGO_HEIGHT = 16
3435
const MAX_LOGO_HEIGHT = 80
3536

36-
function resolveLogoHeight(height?: number): number {
37-
if (typeof height !== "number" || !Number.isFinite(height)) return DEFAULT_LOGO_HEIGHT
38-
return Math.max(MIN_LOGO_HEIGHT, Math.min(MAX_LOGO_HEIGHT, height))
37+
function resolveLogoHeight(height?: number | string): number {
38+
const n = typeof height === "string" ? Number(height) : height
39+
if (typeof n !== "number" || !Number.isFinite(n)) return DEFAULT_LOGO_HEIGHT
40+
return Math.max(MIN_LOGO_HEIGHT, Math.min(MAX_LOGO_HEIGHT, n))
3941
}
4042

4143
const DEFAULT_TABS: HeaderTab[] = [

0 commit comments

Comments
 (0)