Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: show conversation tag keys in sidebar chips (#16853)

Matt Van Horn61cfd23c1fe1
diff --git a/__tests__/components/features/conversation-panel/conversation-card.test.tsx b/__tests__/components/features/conversation-panel/conversation-card.test.tsx
index e79f53cfbb..c6dee95368 100644
--- a/__tests__/components/features/conversation-panel/conversation-card.test.tsx
+++ b/__tests__/components/features/conversation-panel/conversation-card.test.tsx
@@ -754,9 +754,9 @@ describe("ConversationCard", () => {
describe("Tag chips", () => {
// Tag chips surface the agent-server's server-side conversation tags
// (e.g. ``origin=slack`` stamped by an automation) and are gated by the
- // conversation panel's "Tags" toggle (``showTags``). Chip labels are
- // value-only; the full ``key: value`` lives in the chip tooltip.
- it("renders non-reserved tags as value-only chips when showTags is on", () => {
+ // conversation panel's "Tags" toggle (``showTags``). Chips show a friendly
+ // ``key: value`` pair, with the full pair retained in the tooltip.
+ it("renders friendly key/value chips in priority and alphabetical order", () => {
renderWithProviders(
<ConversationCard
title="Conversation 1"
@@ -770,10 +770,9 @@ describe("ConversationCard", () => {
const chips = screen.getAllByTestId("conversation-card-tag-chip");
// ``origin`` is a priority key, so it leads; remaining keys sort A–Z.
expect(chips).toHaveLength(2);
- expect(chips[0]).toHaveTextContent("slack");
- expect(chips[0].getAttribute("title")).toMatch(/: slack$/);
- expect(chips[0].getAttribute("title")).not.toContain("origin");
- expect(chips[1]).toHaveTextContent("alice");
+ expect(chips[0]).toHaveTextContent("Origin: slack");
+ expect(chips[0]).toHaveAttribute("title", "Origin: slack");
+ expect(chips[1]).toHaveTextContent("Owner: alice");
expect(chips[1]).toHaveAttribute("title", "Owner: alice");
expect(
within(chips[0]).getByTestId("conversation-card-tag-chip-icon"),
@@ -809,9 +808,8 @@ describe("ConversationCard", () => {
const chips = screen.getAllByTestId("conversation-card-tag-chip");
expect(chips).toHaveLength(1);
- expect(chips[0]).toHaveTextContent("review");
- expect(chips[0].getAttribute("title")).toMatch(/: review$/);
- expect(chips[0].getAttribute("title")).not.toContain("origin");
+ expect(chips[0]).toHaveTextContent("Origin: review");
+ expect(chips[0]).toHaveAttribute("title", "Origin: review");
});
it("hides every automation provenance chip", () => {
@@ -922,7 +920,7 @@ describe("ConversationCard", () => {
);
const chip = screen.getByTestId("conversation-card-tag-chip");
- expect(chip).toHaveTextContent("abcdefghijklm…");
+ expect(chip).toHaveTextContent("Token: abcdefghijklm…");
expect(chip).toHaveAttribute("title", `Token: ${longValue}`);
});
diff --git a/__tests__/components/features/conversation-panel/conversation-tag-chips.test.tsx b/__tests__/components/features/conversation-panel/conversation-tag-chips.test.tsx
index 103c99c07b..f528d77b8e 100644
--- a/__tests__/components/features/conversation-panel/conversation-tag-chips.test.tsx
+++ b/__tests__/components/features/conversation-panel/conversation-tag-chips.test.tsx
@@ -78,7 +78,15 @@ describe("ConversationTagChips", () => {
);
});
const visibleChip = screen.getByTestId("conversation-card-tag-chip");
- expect(visibleChip).toHaveTextContent("slack");
+ expect(visibleChip).toHaveTextContent("Origin: slack");
+ // The visible and off-screen copies must use the same wider key/value
+ // content so the overflow calculation measures what users actually see.
+ const measureRow = visibleChip
+ .closest('[data-testid="conversation-card-tag-chips"]')
+ ?.querySelector('[aria-hidden="true"]') as HTMLElement;
+ expect(
+ Array.from(measureRow.children).map((chip) => chip.textContent),
+ ).toEqual(["Origin: slack", "Env: prod", "Owner: alice"]);
// Tooltip uses the humanized label β€” "Origin", not the wire key and not
// "Git" (origin names the source of the conversation, not a git fact).
expect(visibleChip).toHaveAttribute("title", "Origin: slack");
@@ -180,11 +188,31 @@ describe("ConversationTagChips", () => {
2,
);
});
+ const chips = screen.getAllByTestId("conversation-card-tag-chip");
+ expect(chips[0]).toHaveTextContent("Origin: slack");
+ expect(chips[1]).toHaveTextContent("Owner: alice");
expect(
screen.getAllByTestId("conversation-card-tag-chip-icon"),
).toHaveLength(2);
});
+ it("shows the humanized key once for bare tags with an empty value", () => {
+ renderWithProviders(<ConversationTagChips tags={[["work", ""]]} />);
+
+ const chip = screen.getByTestId("conversation-card-tag-chip");
+ expect(chip.textContent).toBe("Work");
+ expect(chip).toHaveAttribute("title", "Work");
+ });
+
+ it("safely truncates emoji values while preserving the full tooltip", () => {
+ const longValue = "πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€";
+ renderWithProviders(<ConversationTagChips tags={[["mood", longValue]]} />);
+
+ const chip = screen.getByTestId("conversation-card-tag-chip");
+ expect(chip).toHaveTextContent(`Mood: ${"πŸ˜€".repeat(13)}…`);
+ expect(chip).toHaveAttribute("title", `Mood: ${longValue}`);
+ });
+
it("keeps the overflow popover open across re-renders with unchanged tags", async () => {
// Callers rebuild the tag array on every render, and the conversation
// panel re-renders at least every 10s (`refetchInterval`). Resetting on
diff --git a/src/components/features/conversation-panel/conversation-card/conversation-tag-chips.tsx b/src/components/features/conversation-panel/conversation-card/conversation-tag-chips.tsx
index 9621e98db0..c4a5213921 100644
--- a/src/components/features/conversation-panel/conversation-card/conversation-tag-chips.tsx
+++ b/src/components/features/conversation-panel/conversation-card/conversation-tag-chips.tsx
@@ -52,15 +52,25 @@ function TagIconSlot({
);
}
+function formatTagChipLabel(
+ key: string,
+ value: string,
+ t: (key: I18nKey) => string,
+): string {
+ // Same string as the tooltip, with the value hard-truncated so long chips
+ // still fit. Bare tags (empty value) show the humanized key once.
+ return formatConversationTagTooltip(key, truncateTagChipValue(value), t);
+}
+
function TagChipContent({
icon,
keyName,
- value,
+ chipLabel,
iconTestId,
}: {
icon: ConversationTagIcon;
keyName: string;
- value: string;
+ chipLabel: string;
/**
* Only the visible row passes this. The off-screen measure row renders the
* same chips, so tagging both would emit every chip test id twice and break
@@ -71,26 +81,22 @@ function TagChipContent({
return (
<>
<TagIconSlot icon={icon} keyName={keyName} testId={iconTestId} />
- {/* Bare tags (empty value) fall back to the key so the chip is never
- an empty pill. */}
- <span className="truncate leading-4">
- {truncateTagChipValue(value || keyName)}
- </span>
+ <span className="truncate leading-4">{chipLabel}</span>
</>
);
}
/**
- * Single-row tag chips for a conversation card. Chip labels are value-only
- * (bare tags with an empty value show the key; the full ``key: value`` pair
- * lives in the tooltip); chips that do not fit fold behind a ``+N``
+ * Single-row tag chips for a conversation card. Chip labels show the same
+ * humanized ``key: value`` pair as the tooltip (bare tags with an empty
+ * value show the key once); chips that do not fit fold behind a ``+N``
* button that opens a key/value popover.
*
* The overflow popover is portaled with ``position: fixed`` so it is not
* clipped by the chip row's ``overflow-hidden`` or the sidebar scroller.
*/
export function ConversationTagChips({ tags }: ConversationTagChipsProps) {
- const { t } = useTranslation("openhands");
+ const { t, i18n } = useTranslation("openhands");
const containerRef = React.useRef<HTMLDivElement>(null);
const measureRef = React.useRef<HTMLDivElement>(null);
const triggerRef = React.useRef<HTMLButtonElement>(null);
@@ -146,6 +152,13 @@ export function ConversationTagChips({ tags }: ConversationTagChipsProps) {
recomputeVisibleCount();
}, [tagsKey, recomputeVisibleCount]);
+ // Localized key labels change chip width (e.g. "Git" vs a longer
+ // translation), so overflow must be remeasured when the language changes.
+ const language = i18n.resolvedLanguage ?? i18n.language;
+ React.useLayoutEffect(() => {
+ recomputeVisibleCount();
+ }, [language, recomputeVisibleCount]);
+
React.useEffect(() => {
const container = containerRef.current;
if (!container || typeof ResizeObserver === "undefined") {
@@ -235,7 +248,7 @@ export function ConversationTagChips({ tags }: ConversationTagChipsProps) {
<TagChipContent
icon={getConversationTagIcon(key, value)}
keyName={key}
- value={value}
+ chipLabel={formatTagChipLabel(key, value, t)}
/>
</span>
))}
@@ -256,7 +269,7 @@ export function ConversationTagChips({ tags }: ConversationTagChipsProps) {
<TagChipContent
icon={getConversationTagIcon(key, value)}
keyName={key}
- value={value}
+ chipLabel={formatTagChipLabel(key, value, t)}
iconTestId="conversation-card-tag-chip-icon"
/>
</span>