mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 09:28:34 +00:00
fix(webui): align timestamp tooltip styles
This commit is contained in:
parent
fa65a01977
commit
29fdb7d628
@ -4,6 +4,7 @@ import {
|
|||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
|
type ComponentPropsWithoutRef,
|
||||||
type ReactNode,
|
type ReactNode,
|
||||||
} from "react";
|
} from "react";
|
||||||
import {
|
import {
|
||||||
@ -80,6 +81,42 @@ function ForkArrowIcon({ className }: { className?: string }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MessageTimestampProps = Omit<
|
||||||
|
ComponentPropsWithoutRef<"time">,
|
||||||
|
"dateTime" | "title"
|
||||||
|
> & {
|
||||||
|
timestamp: number;
|
||||||
|
tooltipLabel: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function MessageTimestamp({
|
||||||
|
timestamp,
|
||||||
|
tooltipLabel,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: MessageTimestampProps) {
|
||||||
|
return (
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<time
|
||||||
|
{...props}
|
||||||
|
dateTime={new Date(timestamp).toISOString()}
|
||||||
|
tabIndex={0}
|
||||||
|
className={cn(
|
||||||
|
"cursor-help text-[11px] leading-none text-muted-foreground/70 tabular-nums",
|
||||||
|
"focus-visible:rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</time>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="top" align="center">{tooltipLabel}</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function MessageCopyButton({ content }: { content: string }) {
|
function MessageCopyButton({ content }: { content: string }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
@ -307,14 +344,13 @@ export function MessageBubble({
|
|||||||
<TooltipProvider delayDuration={220} skipDelayDuration={80}>
|
<TooltipProvider delayDuration={220} skipDelayDuration={80}>
|
||||||
<div className="flex min-h-8 items-center justify-end gap-1.5 text-muted-foreground">
|
<div className="flex min-h-8 items-center justify-end gap-1.5 text-muted-foreground">
|
||||||
{showCreatedAt ? (
|
{showCreatedAt ? (
|
||||||
<time
|
<MessageTimestamp
|
||||||
data-message-created-at
|
data-message-created-at
|
||||||
dateTime={new Date(message.createdAt).toISOString()}
|
timestamp={message.createdAt}
|
||||||
className="text-[11px] leading-none text-muted-foreground/70 tabular-nums"
|
tooltipLabel={createdAtTitle}
|
||||||
title={createdAtTitle}
|
|
||||||
>
|
>
|
||||||
{createdAtLabel}
|
{createdAtLabel}
|
||||||
</time>
|
</MessageTimestamp>
|
||||||
) : null}
|
) : null}
|
||||||
<UserDeliveryStatus
|
<UserDeliveryStatus
|
||||||
status={message.deliveryStatus}
|
status={message.deliveryStatus}
|
||||||
@ -436,15 +472,14 @@ export function MessageBubble({
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
) : null}
|
) : null}
|
||||||
{showAssistantTimestamp ? (
|
{showAssistantTimestamp ? (
|
||||||
<time
|
<MessageTimestamp
|
||||||
{...(showCompletedAt ? { "data-assistant-completed-at": true } : {})}
|
{...(showCompletedAt ? { "data-assistant-completed-at": true } : {})}
|
||||||
data-message-timestamp
|
data-message-timestamp
|
||||||
dateTime={new Date(assistantTimestamp).toISOString()}
|
timestamp={assistantTimestamp}
|
||||||
className="text-[11px] leading-none text-muted-foreground/70 tabular-nums"
|
tooltipLabel={assistantTimestampTitle}
|
||||||
title={assistantTimestampTitle}
|
|
||||||
>
|
>
|
||||||
{assistantTimestampLabel}
|
{assistantTimestampLabel}
|
||||||
</time>
|
</MessageTimestamp>
|
||||||
) : null}
|
) : null}
|
||||||
{showAutomationTrigger ? (
|
{showAutomationTrigger ? (
|
||||||
<AutomationTriggerMeta
|
<AutomationTriggerMeta
|
||||||
|
|||||||
@ -347,7 +347,7 @@ describe("MessageBubble", () => {
|
|||||||
expect(onForkFromHere).toHaveBeenCalledTimes(1);
|
expect(onForkFromHere).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows the assistant completion time in the former latency slot", () => {
|
it("shows the assistant completion time in the former latency slot", async () => {
|
||||||
const completedAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
const completedAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<MessageBubble
|
<MessageBubble
|
||||||
@ -366,13 +366,18 @@ describe("MessageBubble", () => {
|
|||||||
const time = container.querySelector("[data-assistant-completed-at]");
|
const time = container.querySelector("[data-assistant-completed-at]");
|
||||||
expect(time).toHaveTextContent(formatMessageEndTime(completedAt));
|
expect(time).toHaveTextContent(formatMessageEndTime(completedAt));
|
||||||
expect(time).toHaveAttribute("dateTime", new Date(completedAt).toISOString());
|
expect(time).toHaveAttribute("dateTime", new Date(completedAt).toISOString());
|
||||||
expect(time).toHaveAttribute("title", fmtDateTime(completedAt));
|
expect(time).not.toHaveAttribute("title");
|
||||||
|
expect(time).toHaveAttribute("tabIndex", "0");
|
||||||
expect(time).toHaveClass(
|
expect(time).toHaveClass(
|
||||||
|
"cursor-help",
|
||||||
"text-[11px]",
|
"text-[11px]",
|
||||||
"leading-none",
|
"leading-none",
|
||||||
"text-muted-foreground/70",
|
"text-muted-foreground/70",
|
||||||
"tabular-nums",
|
"tabular-nums",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fireEvent.pointerMove(time!);
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(fmtDateTime(completedAt));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to the assistant creation time when replay has no completion time", () => {
|
it("falls back to the assistant creation time when replay has no completion time", () => {
|
||||||
@ -391,11 +396,11 @@ describe("MessageBubble", () => {
|
|||||||
const time = container.querySelector("[data-message-timestamp]");
|
const time = container.querySelector("[data-message-timestamp]");
|
||||||
expect(time).toHaveTextContent(formatMessageEndTime(createdAt));
|
expect(time).toHaveTextContent(formatMessageEndTime(createdAt));
|
||||||
expect(time).toHaveAttribute("dateTime", new Date(createdAt).toISOString());
|
expect(time).toHaveAttribute("dateTime", new Date(createdAt).toISOString());
|
||||||
expect(time).toHaveAttribute("title", fmtDateTime(createdAt));
|
expect(time).not.toHaveAttribute("title");
|
||||||
expect(time).not.toHaveAttribute("data-assistant-completed-at");
|
expect(time).not.toHaveAttribute("data-assistant-completed-at");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders the creation time for user messages", () => {
|
it("renders the creation time for user messages", async () => {
|
||||||
const createdAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
const createdAt = Date.UTC(2026, 6, 25, 12, 34, 56);
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<MessageBubble
|
<MessageBubble
|
||||||
@ -411,7 +416,11 @@ describe("MessageBubble", () => {
|
|||||||
const time = container.querySelector("[data-message-created-at]");
|
const time = container.querySelector("[data-message-created-at]");
|
||||||
expect(time).toHaveTextContent(formatMessageEndTime(createdAt));
|
expect(time).toHaveTextContent(formatMessageEndTime(createdAt));
|
||||||
expect(time).toHaveAttribute("dateTime", new Date(createdAt).toISOString());
|
expect(time).toHaveAttribute("dateTime", new Date(createdAt).toISOString());
|
||||||
expect(time).toHaveAttribute("title", fmtDateTime(createdAt));
|
expect(time).not.toHaveAttribute("title");
|
||||||
|
expect(time).toHaveAttribute("tabIndex", "0");
|
||||||
|
|
||||||
|
fireEvent.pointerMove(time!);
|
||||||
|
expect(await screen.findByRole("tooltip")).toHaveTextContent(fmtDateTime(createdAt));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not infer completion time from the assistant creation timestamp", () => {
|
it("does not infer completion time from the assistant creation timestamp", () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user