fix(dashboard): kit Tile for profile badges, chart ink on tier chips, no duplicate Escape listeners (#18076) (#19401)

* fix(dashboard): kit Tile for profile badges, chart ink on tier chips, drop duplicate Escape listeners

- Profile badge grid: each badge is a kit Tile (stacked) instead of a raw
  <button> with a kit-exception. The hidden locked tile keeps full text ink
  over the kit's dimmed disabled state.
- Profile tier chip and the epic rarity: text-chart-N-ink on bg-chart-N-subtle
  instead of the chart colour as text on a 10% tint.
- Conversations drawer and profile badge dialog: removed the document keydown
  listeners that duplicated the Radix Dialog Escape handling.

Refs #18076

* fix(dashboard): build the profile badge glyph outside the Tile icon slot

icon-map-object-values reads every lookup object referenced from an icon slot
as icon names; passing the rarity class inside icon={…} made RARITY_COLORS look
like an icon map. The glyph is built first and handed to the Tile as a value.

Refs #18076
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-11-10 00:00:17 -03:00
committed by GitHub
parent 2e5700e97a
commit 8e72dbf546
5 changed files with 217 additions and 62 deletions

View File

@@ -594,19 +594,8 @@ function ConversationsPageContent() {
conversationNodes.length > 0 ? conversationNodes[conversationNodes.length - 1].seq : null;
}, [conversationNodes]);
useEffect(() => {
if (!activeConversationId) return;
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === "Escape") closeConversation();
};
document.addEventListener("keydown", onKeyDown);
return () => document.removeEventListener("keydown", onKeyDown);
// activeConversationId, not the whole activeConversation object: it
// gets resynced (new object reference) from the list poll while the
// modal stays open (see that effect's comment) — depending on the
// object here would rebind this listener on every poll tick for no
// reason.
}, [activeConversationId, closeConversation]);
// Escape is handled by the kit Modal (Radix Dialog); a document-level listener here would also
// close the drawer when Escape was meant for a nested menu or tooltip (#18076).
// While the conversation is open, keep polling for turns that arrive
// later (the request that opened it may not be the last one — OpenClaw

View File

@@ -4,11 +4,13 @@ import { useState, useEffect, useCallback } from "react";
import { useLocale, useTranslations } from "next-intl";
import { PageHeader } from "@omniroute/ui-kit/page-header";
import { Progress } from "@omniroute/ui-kit/progress";
import { Tile } from "@omniroute/ui-kit/tile";
import Badge from "@/shared/components/Badge";
import Button from "@/shared/components/Button";
import Card from "@/shared/components/Card";
import Icon from "@/shared/components/Icon";
import Modal from "@/shared/components/Modal";
import { cn } from "@/shared/utils/cn";
import { cumulativeXpForLevel, getLevelTier, getLevelTitle } from "@/lib/gamification/xp";
interface UserLevel {
@@ -42,11 +44,11 @@ interface UserBadge {
}
const TIER_CONFIG: Record<string, { labelKey: string; color: string; bg: string }> = {
bronze: { labelKey: "tiers.bronze", color: "text-chart-5", bg: "bg-chart-5/10" },
bronze: { labelKey: "tiers.bronze", color: "text-chart-5-ink", bg: "bg-chart-5-subtle" },
silver: { labelKey: "tiers.silver", color: "text-text-muted", bg: "bg-text-muted/10" },
gold: { labelKey: "tiers.gold", color: "text-warning", bg: "bg-warning/10" },
platinum: { labelKey: "tiers.platinum", color: "text-chart-2", bg: "bg-chart-2/10" },
diamond: { labelKey: "tiers.diamond", color: "text-chart-3", bg: "bg-chart-3/10" },
platinum: { labelKey: "tiers.platinum", color: "text-chart-2-ink", bg: "bg-chart-2-subtle" },
diamond: { labelKey: "tiers.diamond", color: "text-chart-3-ink", bg: "bg-chart-3-subtle" },
};
const BADGE_ICONS: Record<string, string> = {
@@ -95,7 +97,7 @@ const RARITY_COLORS: Record<string, string> = {
common: "text-text-muted border-border",
uncommon: "text-success border-success/30",
rare: "text-info border-info/30",
epic: "text-chart-3 border-chart-3/30",
epic: "text-chart-3-ink border-chart-3/30",
legendary: "text-warning border-warning/30",
};
@@ -110,14 +112,7 @@ export default function ProfilePage() {
const [error, setError] = useState("");
const [selectedBadge, setSelectedBadge] = useState<BadgeDef | null>(null);
useEffect(() => {
if (!selectedBadge) return;
const closeOnEscape = (event: KeyboardEvent) => {
if (event.key === "Escape") setSelectedBadge(null);
};
document.addEventListener("keydown", closeOnEscape);
return () => document.removeEventListener("keydown", closeOnEscape);
}, [selectedBadge]);
// Escape closes the badge dialog through the kit Modal (Radix Dialog) itself (#18076).
const [streak, setStreak] = useState(0);
const fetchData = useCallback(async () => {
@@ -285,57 +280,64 @@ export default function ProfilePage() {
const isHiddenAndLocked = Boolean(badge.hidden) && !isEarned;
const earnedInfo = earnedBadges.find((b) => b.badgeId === badge.id);
const rarityColor = RARITY_COLORS[badge.rarity] || RARITY_COLORS.common;
// Rarity tints the earned glyph; a locked glyph is dimmed (its text keeps full ink).
const glyphTone = isEarned ? rarityColor : "opacity-50 grayscale";
const glyph = (
<span className={glyphTone}>
<BadgeIcon icon={isHiddenAndLocked ? null : badge.icon} earned={isEarned} />
</span>
);
return (
// kit-exception: Multi-line badge tile (icon, name, description, date, progress): the kit Button
// is a single-line pill, so the tile stays a native <button> on kit tokens.
<button
<Tile
key={badge.id}
type="button"
layout="stacked"
onClick={() => !isHiddenAndLocked && setSelectedBadge(badge)}
disabled={isHiddenAndLocked}
// Locked: dashed border, muted surface, dimmed glyph and a lock mark. The text
// keeps full token ink — the old tile-wide opacity-50 + grayscale put names and
// descriptions under AA (36 axe color-contrast nodes, F4).
className={`relative p-4 rounded-xl border transition-all text-start ${
isEarned
? `${rarityColor} bg-surface hover:shadow-md`
: "border-dashed border-border bg-bg-subtle enabled:hover:border-text-muted disabled:cursor-default"
}`}
data-locked={isEarned ? undefined : "true"}
>
{!isEarned && (
<span className="absolute top-2 end-2 text-text-muted">
<Icon name="lock" size={14} />
<span className="ci-sr-only">{tg("badgeLocked")}</span>
</span>
// descriptions under AA (36 axe color-contrast nodes, F4) — so the kit's dimmed
// disabled tile is brought back to full opacity for the hidden badge.
className={cn(
isEarned ? `${rarityColor} hover:shadow-md` : "border-dashed bg-bg-subtle",
isHiddenAndLocked && "cursor-default opacity-100"
)}
<div className={`text-3xl mb-2 ${isEarned ? "" : "opacity-50 grayscale"}`}>
<BadgeIcon icon={isHiddenAndLocked ? null : badge.icon} earned={isEarned} />
</div>
<p className="font-semibold text-sm truncate">
{badge.hidden && !isEarned ? "???" : translateBadge(badge, "name")}
</p>
<p className="text-xs text-text-muted mt-1 line-clamp-2">
{badge.hidden && !isEarned
? tg("hiddenBadge")
: translateBadge(badge, "description")}
</p>
data-locked={isEarned ? undefined : "true"}
icon={glyph}
title={
<span className="block truncate font-semibold">
{badge.hidden && !isEarned ? "???" : translateBadge(badge, "name")}
</span>
}
meta={
isEarned ? undefined : (
<span className="text-text-muted">
<Icon name="lock" size={14} />
<span className="ci-sr-only">{tg("badgeLocked")}</span>
</span>
)
}
description={
<span className="line-clamp-2">
{badge.hidden && !isEarned
? tg("hiddenBadge")
: translateBadge(badge, "description")}
</span>
}
>
{isEarned && earnedInfo?.unlockedAt && (
<p className="text-[10px] text-text-muted mt-2">
<span className="block text-[10px] text-text-muted">
{tg("earnedDate", {
date: new Date(earnedInfo.unlockedAt).toLocaleDateString(locale),
})}
</p>
</span>
)}
{!isEarned && badge.criteria && (
<div className="mt-2">
<div className="w-full h-1.5 rounded-full bg-border overflow-hidden">
<div className="h-full w-0 rounded-full bg-chart-3/50" />
</div>
</div>
<span className="block w-full h-1.5 rounded-full bg-border overflow-hidden">
<span className="block h-full w-0 rounded-full bg-chart-3/50" />
</span>
)}
</button>
</Tile>
);
})}
</div>

View File

@@ -0,0 +1,27 @@
/**
* #18076 — the conversations drawer and the profile badge dialog are kit `Modal`s (Radix
* Dialog), which already close on Escape through their own dismissable layer. Both pages also
* kept a document-level `keydown` listener that closed the dialog on Escape. That duplicate
* fires even when Escape was meant for a nested layer (a menu or tooltip inside the dialog),
* closing the whole dialog. The listeners are gone; Escape is covered by Radix (see
* tests/unit/ui/profile-badge-dialog.test.tsx "closes on Escape").
*/
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
const DASHBOARD = "src/app/(dashboard)/dashboard";
const read = (p: string) => fs.readFileSync(path.join(ROOT, DASHBOARD, p), "utf8");
for (const page of ["conversations/page.tsx", "profile/page.tsx"]) {
test(`${page}: no document-level Escape listener next to the Radix modal`, () => {
const src = read(page);
// The page still renders the kit Modal, which owns Escape.
assert.match(src, /import Modal from "@\/shared\/components\/Modal"/);
assert.doesNotMatch(src, /document\.addEventListener\(\s*["']keydown["']/);
assert.doesNotMatch(src, /key === "Escape"/);
});
}

View File

@@ -0,0 +1,134 @@
// @vitest-environment jsdom
/**
* #18076 (lote 8 follow-up):
* - The profile badge grid used raw <button>s with a `kit-exception:` because the kit had no
* multi-line tile. Kit 0.0.104 ships `Tile`, so every badge is a kit tile now.
* - The tier chip painted the chart colour itself as text (`text-chart-5` on `bg-chart-5/10`,
* one light-mode contrast node). The kit pairs each chart token with a text-safe `-ink` and an
* opaque `-subtle` tint; the bronze, platinum and diamond tiers use those.
*/
import fs from "node:fs";
import path from "node:path";
import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
(
globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
const translate = (key: string) => key;
vi.mock("next-intl", () => ({
useLocale: () => "en",
useTranslations: () => Object.assign(translate, { has: () => false }),
}));
const { default: ProfilePage } = await import("@/app/(dashboard)/dashboard/profile/page");
const PAGE = path.resolve(__dirname, "../../../src/app/(dashboard)/dashboard/profile/page.tsx");
const roots: Array<{ root: ReturnType<typeof createRoot>; container: HTMLDivElement }> = [];
async function renderProfile(currentLevel = 1) {
const badge = (id: string, name: string, hidden = 0) => ({
id,
name,
description: `${name} description`,
icon: "rocket",
category: "usage",
rarity: "rare",
criteria: '{"type":"requests","count":10}',
hidden,
createdAt: "2026-08-26T00:00:00.000Z",
});
vi.stubGlobal(
"fetch",
vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url.endsWith("/level")) {
return { ok: true, json: async () => ({ level: { totalXp: 0, currentLevel } }) };
}
if (url.endsWith("/earned")) {
return {
ok: true,
json: async () => ({
badges: [{ badgeId: "earned-one", unlockedAt: "2026-08-26T00:00:00.000Z" }],
}),
};
}
return {
ok: true,
json: async () => ({
badges: [
badge("earned-one", "Earned"),
badge("locked-one", "Locked"),
badge("hidden-one", "Hidden", 1),
],
}),
};
})
);
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
roots.push({ root, container });
act(() => root.render(<ProfilePage />));
for (let i = 0; i < 40 && container.querySelectorAll("button").length < 3; i++) {
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 10));
});
}
return container;
}
afterEach(() => {
for (const { root, container } of roots.splice(0)) {
act(() => root.unmount());
container.remove();
}
vi.unstubAllGlobals();
});
describe("profile badge grid", () => {
it("renders every badge as a kit Tile named by the badge title", async () => {
const container = await renderProfile();
const tiles = [...container.querySelectorAll<HTMLButtonElement>("[data-slot='tile']")];
expect(tiles).toHaveLength(3);
const earned = tiles.find((t) => t.textContent?.includes("Earned description"));
expect(earned?.tagName).toBe("BUTTON");
const labelId = earned?.getAttribute("aria-labelledby");
expect(labelId && document.getElementById(labelId)?.textContent).toBe("Earned");
});
it("keeps the hidden locked badge unclickable but at full text ink", async () => {
const container = await renderProfile();
const hidden = [...container.querySelectorAll<HTMLButtonElement>("[data-slot='tile']")].find(
(t) => t.textContent?.includes("???")
);
expect(hidden?.disabled).toBe(true);
// The kit dims disabled tiles to 0.48 opacity; the page restores full ink for the copy.
expect(hidden?.className).toMatch(/\bopacity-100\b/);
expect(hidden?.textContent).not.toContain("Hidden description");
});
it("leaves no raw <button> tile with a kit-exception in the page source", () => {
const src = fs.readFileSync(PAGE, "utf8");
expect(src).not.toMatch(/kit-exception: Multi-line badge tile/);
expect(src).toMatch(/from "@omniroute\/ui-kit\/tile"/);
});
});
describe("profile tier chip", () => {
it.each([
[1, "text-chart-5-ink", "bg-chart-5-subtle"],
[60, "text-chart-2-ink", "bg-chart-2-subtle"],
[90, "text-chart-3-ink", "bg-chart-3-subtle"],
])("level %i paints the tier with the -ink text and -subtle tint", async (level, ink, tint) => {
const container = await renderProfile(level);
const chip = [...container.querySelectorAll<HTMLElement>("[class*='-subtle']")].find((el) =>
el.textContent?.includes("tierLabel")
);
expect(chip?.className).toContain(ink);
expect(chip?.className).toContain(tint);
// No chart colour is used as text without its -ink pair anywhere on the page.
expect(container.innerHTML).not.toMatch(/\btext-chart-\d(?![\d-])/);
});
});

View File

@@ -89,7 +89,10 @@ describe("Profile locked badge tiles", () => {
const locked = tile(container, "Locked");
expect(locked).toBeDefined();
expect(locked.className).not.toMatch(/\bopacity-|\bgrayscale\b/);
for (const text of [...locked.querySelectorAll("p")]) {
// The badge name and description (kit Tile title/description slots since #18076).
const copy = [...locked.querySelectorAll(".ci-tile__title, .ci-tile__description")];
expect(copy).toHaveLength(2);
for (const text of copy) {
expect(text.closest("[class*='opacity-']")).toBeNull();
}
expect(locked.getAttribute("data-locked")).toBe("true");