mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
🍴 style: Restyle the Fork Popover and Calm the Feedback Hover (#18103)
* style: Restyle the Fork Popover and Calm the Feedback Hover * fix: Follow the Stored Fork Mode and Update the Specs for the New Fork Popover * test: Find the Fork Options Link by Both of Its Names
This commit is contained in:
parent
7aa43501a1
commit
78c516b610
12 changed files with 443 additions and 407 deletions
|
|
@ -661,8 +661,8 @@ describe('HoverButtons feedback affordance', () => {
|
|||
it('offers feedback on a settled response when a handler is supplied', () => {
|
||||
renderSettledResponse(jest.fn());
|
||||
|
||||
expect(screen.getByTitle('Love this')).toBeInTheDocument();
|
||||
expect(screen.getByTitle('Needs improvement')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Love this' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Needs improvement' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
/** `useMessageActions` withholds the handler when `interface.feedback` is false, so
|
||||
|
|
@ -670,8 +670,8 @@ describe('HoverButtons feedback affordance', () => {
|
|||
it('hides feedback when no handler is supplied', () => {
|
||||
renderSettledResponse();
|
||||
|
||||
expect(screen.queryByTitle('Love this')).toBeNull();
|
||||
expect(screen.queryByTitle('Needs improvement')).toBeNull();
|
||||
expect(screen.queryByRole('button', { name: 'Love this' })).toBeNull();
|
||||
expect(screen.queryByRole('button', { name: 'Needs improvement' })).toBeNull();
|
||||
expect(screen.getByTestId('copy-response-button')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const CodeBar: React.FC<CodeBarProps> = React.memo(
|
|||
|
||||
return (
|
||||
<div className="bg-surface-code text-text-secondary flex items-center justify-between px-1.5 py-1.5 font-sans text-xs">
|
||||
<span className="flex items-center gap-1.5 text-xs font-medium">
|
||||
<span className="flex items-center gap-1.5 ps-1.5 text-xs font-medium">
|
||||
<LangIcon lang={lang} className="size-3.5" />
|
||||
{lang}
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -1972,28 +1972,28 @@
|
|||
"com_ui_fork_branches": "Include related branches",
|
||||
"com_ui_fork_change_default": "Default fork option",
|
||||
"com_ui_fork_default": "Use default fork option",
|
||||
"com_ui_fork_desc_branches": "The visible messages plus branches along the way",
|
||||
"com_ui_fork_desc_target": "Every message and branch, visible or not",
|
||||
"com_ui_fork_desc_visible": "Only the messages you see in the chat",
|
||||
"com_ui_fork_error": "There was an error forking the conversation",
|
||||
"com_ui_fork_error_rate_limit": "Too many fork requests. Please try again later",
|
||||
"com_ui_fork_exclude_files": "Leave out files",
|
||||
"com_ui_fork_from_message": "Select a fork option",
|
||||
"com_ui_fork_info_1": "Use this setting to fork messages with the desired behavior.",
|
||||
"com_ui_fork_info_2": "\"Forking\" refers to creating a new conversation that start/end from specific messages in the current conversation, creating a copy according to the options selected.",
|
||||
"com_ui_fork_info_3": "The \"target message\" refers to either the message this popup was opened from, or, if you check \"{{0}}\", the latest message in the conversation.",
|
||||
"com_ui_fork_info_branches": "This option forks the visible messages, along with related branches; in other words, the direct path to the target message, including branches along the path.",
|
||||
"com_ui_fork_info_button_label": "View information about forking conversations",
|
||||
"com_ui_fork_info_exclude_files": "If checked, the new conversation copies the messages without their attached or generated files, so later messages don't send them again.",
|
||||
"com_ui_fork_info_remember": "Check this to remember the options you select for future usage, making it quicker to fork conversations as preferred.",
|
||||
"com_ui_fork_info_start": "If checked, forking will commence from this message to the latest message in the conversation, according to the behavior selected above.",
|
||||
"com_ui_fork_info_target": "This option forks all messages leading up to the target message, including its neighbors; in other words, all message branches, whether or not they are visible or along the same path, are included.",
|
||||
"com_ui_fork_info_visible": "This option forks only the visible messages; in other words, the direct path to the target message, without any branches.",
|
||||
"com_ui_fork_more_details_about": "View additional information and details about the \"{{0}}\" fork option",
|
||||
"com_ui_fork_more_info_options": "View detailed explanation of all fork options and their behaviors",
|
||||
"com_ui_fork_fewer_options": "Fewer options",
|
||||
"com_ui_fork_from_message": "Fork conversation",
|
||||
"com_ui_fork_include": "Include",
|
||||
"com_ui_fork_mode_all": "Everything",
|
||||
"com_ui_fork_mode_branches": "Branches",
|
||||
"com_ui_fork_mode_visible": "Visible",
|
||||
"com_ui_fork_more_options": "More options",
|
||||
"com_ui_fork_open_menu": "Open Fork Menu",
|
||||
"com_ui_fork_processing": "Forking conversation...",
|
||||
"com_ui_fork_remember": "Remember",
|
||||
"com_ui_fork_remember_checked": "Your selection will be remembered after usage. Change this at any time in the settings.",
|
||||
"com_ui_fork_split_target": "Start fork here",
|
||||
"com_ui_fork_remember": "Don't ask again",
|
||||
"com_ui_fork_scope_after": "From here on",
|
||||
"com_ui_fork_scope_after_help": "Copies this message and everything after it.",
|
||||
"com_ui_fork_scope_before": "Up to here",
|
||||
"com_ui_fork_scope_before_help": "Copies the chat from the start through this message.",
|
||||
"com_ui_fork_split_target_setting": "Start fork from target message by default",
|
||||
"com_ui_fork_subtitle": "Start a new chat from a copy of this one.",
|
||||
"com_ui_fork_success": "Successfully forked conversation",
|
||||
"com_ui_fork_visible": "Visible messages only",
|
||||
"com_ui_generate_qrcode": "Generate QR Code",
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ test.describe('message hover actions', () => {
|
|||
* Escape hands focus back to the trigger, so drop it before measuring the fade
|
||||
* or `group-focus-within` keeps the row lit on its own. */
|
||||
await page.keyboard.press('Escape');
|
||||
await expect(page.locator('.popover-animate')).toHaveCount(0);
|
||||
await expect(page.getByRole('dialog', { name: 'Fork conversation' })).toHaveCount(0);
|
||||
await page.locator('body').click({ position: { x: 5, y: 5 } });
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(copyButton).toHaveCSS('opacity', '0');
|
||||
|
|
|
|||
|
|
@ -627,6 +627,9 @@ async function clickForkVisibleMessages(
|
|||
await render.scrollIntoViewIfNeeded();
|
||||
await render.hover();
|
||||
await render.getByRole('button', { name: 'Open Fork Menu' }).click();
|
||||
const popover = page.getByRole('dialog', { name: 'Fork conversation' });
|
||||
await popover.getByRole('button', { name: 'More options' }).click();
|
||||
await popover.getByRole('radio', { name: 'Visible', exact: true }).click();
|
||||
|
||||
const [response] = await Promise.all([
|
||||
page.waitForResponse(
|
||||
|
|
@ -636,7 +639,7 @@ async function clickForkVisibleMessages(
|
|||
res.status() === 200,
|
||||
{ timeout: 30000 },
|
||||
),
|
||||
page.getByRole('button', { name: 'Visible messages only', exact: true }).click(),
|
||||
popover.getByRole('button', { name: 'Fork', exact: true }).click(),
|
||||
]);
|
||||
|
||||
return (await response.json()) as ForkResponse;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import { MOCK_ENDPOINTS, NEW_CHAT_PATH, selectMockEndpoint, sendMessage } from '../helpers';
|
||||
import { probeStyle } from './style.helpers';
|
||||
|
||||
/** The fork and feedback actions `@librechat/chat` now renders on a reply, with the fork request
|
||||
* and the viewer's fork defaults supplied by the app's messages host. */
|
||||
|
|
@ -34,12 +35,15 @@ test.describe('fork and feedback actions', () => {
|
|||
const row = messageRender(page, reply);
|
||||
await row.hover();
|
||||
await row.getByRole('button', { name: 'Open Fork Menu' }).click();
|
||||
const popover = page.getByRole('dialog', { name: 'Fork conversation' });
|
||||
await popover.getByRole('button', { name: 'More options' }).click();
|
||||
await popover.getByRole('radio', { name: 'Visible', exact: true }).click();
|
||||
const [response] = await Promise.all([
|
||||
page.waitForResponse(
|
||||
(res) => res.request().method() === 'POST' && res.url().includes('/api/convos/fork'),
|
||||
{ timeout: 30000 },
|
||||
),
|
||||
page.getByRole('button', { name: 'Visible messages only', exact: true }).click(),
|
||||
popover.getByRole('button', { name: 'Fork', exact: true }).click(),
|
||||
]);
|
||||
expect(response.ok()).toBeTruthy();
|
||||
const { conversation } = (await response.json()) as {
|
||||
|
|
@ -52,6 +56,68 @@ test.describe('fork and feedback actions', () => {
|
|||
await expect(messagesView(page).getByText(reply)).toBeVisible();
|
||||
});
|
||||
|
||||
test('the fork popover leads with the scope and keeps the extra options collapsed @scenario:fork-popover-leads-with-scope-and-collapses-options', async ({
|
||||
page,
|
||||
}) => {
|
||||
const reply = await replyInNewChat(page, uniqueLabel('fork-popover'));
|
||||
|
||||
const row = messageRender(page, reply);
|
||||
await row.hover();
|
||||
await row.getByRole('button', { name: 'Open Fork Menu' }).click();
|
||||
const popover = page.getByRole('dialog', { name: 'Fork conversation' });
|
||||
await expect(popover.getByRole('radio', { name: 'Up to here' })).toBeChecked();
|
||||
|
||||
/** The less common choices wait behind one text link, and stay out of the accessibility tree. */
|
||||
/** The link names the action it will take, so it reads "Fewer options" once it is open. */
|
||||
const more = popover.getByRole('button', { name: /^(More|Fewer) options$/ });
|
||||
await expect(more).toHaveAttribute('aria-expanded', 'false');
|
||||
await expect(popover.getByRole('checkbox', { name: 'Leave out files' })).toHaveCount(0);
|
||||
await more.click();
|
||||
await expect(more).toHaveAttribute('aria-expanded', 'true');
|
||||
await expect(popover.getByRole('checkbox', { name: 'Leave out files' })).toBeVisible();
|
||||
await expect(popover.getByRole('radio', { name: 'Everything' })).toBeChecked();
|
||||
|
||||
await popover.getByRole('radio', { name: 'From here on' }).click();
|
||||
const [request] = await Promise.all([
|
||||
page.waitForRequest(
|
||||
(req) => req.method() === 'POST' && req.url().includes('/api/convos/fork'),
|
||||
{ timeout: 30000 },
|
||||
),
|
||||
popover.getByRole('button', { name: 'Fork', exact: true }).click(),
|
||||
]);
|
||||
expect(request.postDataJSON()).toMatchObject({ splitAtTarget: true });
|
||||
});
|
||||
|
||||
test('message hover buttons snap their hover tint instead of fading it @scenario:message-hover-buttons-snap-their-hover-tint', async ({
|
||||
page,
|
||||
}) => {
|
||||
const label = uniqueLabel('hover-tint');
|
||||
const first = await replyInNewChat(page, `${label}-first`);
|
||||
const secondReply = `E2E reply ${label}-second`;
|
||||
expect((await sendMessage(page, `E2E_REPLY:${label}-second`)).ok()).toBeTruthy();
|
||||
await expect(messagesView(page).getByText(secondReply)).toBeVisible({ timeout: 30000 });
|
||||
|
||||
/** The earlier reply's toolbar fades in and out; the latest one stays shown. Neither fades the
|
||||
* tint a hovered button takes. */
|
||||
const earlier = messageRender(page, first);
|
||||
const latest = messageRender(page, secondReply);
|
||||
await earlier.hover();
|
||||
const buttons = [
|
||||
earlier.getByRole('button', { name: 'Love this' }),
|
||||
latest.getByRole('button', { name: 'Love this' }),
|
||||
latest.getByRole('button', { name: 'Open Fork Menu' }),
|
||||
];
|
||||
/** A plain button fades its colors; the guard keeps the assertion from passing for nothing. */
|
||||
expect(await probeStyle(page, 'transition-colors', 'transition-property')).toMatch(/color/);
|
||||
for (const button of buttons) {
|
||||
await expect(button).toBeVisible();
|
||||
const property = await button.evaluate(
|
||||
(element) => getComputedStyle(element).transitionProperty,
|
||||
);
|
||||
expect(property).not.toMatch(/color|background/);
|
||||
}
|
||||
});
|
||||
|
||||
test('a positive rating is saved and survives a reload @scenario:feedback-rating-persists', async ({
|
||||
page,
|
||||
}) => {
|
||||
|
|
@ -65,7 +131,7 @@ test.describe('fork and feedback actions', () => {
|
|||
(res) => res.request().method() === 'PUT' && res.url().includes('/feedback'),
|
||||
{ timeout: 30000 },
|
||||
),
|
||||
page.locator('.popover-animate').getByRole('button').first().click(),
|
||||
page.getByRole('dialog').getByRole('button').first().click(),
|
||||
]);
|
||||
expect(response.ok()).toBeTruthy();
|
||||
|
||||
|
|
|
|||
|
|
@ -94,9 +94,7 @@ test("an open fork menu holds an earlier reply's actions visible after the point
|
|||
|
||||
await row.hover();
|
||||
await fork.click();
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'Visible messages only', exact: true }),
|
||||
).toBeVisible();
|
||||
await expect(page.getByRole('dialog', { name: 'Fork conversation' })).toBeVisible();
|
||||
await page.mouse.move(0, 0);
|
||||
/** The open menu lights its trigger and keeps every action in the row opaque. */
|
||||
await expect.poll(() => paintedOpacity(copy)).toBe(1);
|
||||
|
|
|
|||
|
|
@ -140,16 +140,21 @@ function FeedbackButtons({
|
|||
<Ariakit.PopoverAnchor
|
||||
store={upStore}
|
||||
render={
|
||||
<Button
|
||||
variant={isLast ? 'message-hover' : 'message-hover-reveal'}
|
||||
data-hover-active={feedback?.rating === 'thumbsUp' || undefined}
|
||||
onClick={handleThumbsUpClick}
|
||||
title={localize('com_ui_feedback_positive')}
|
||||
aria-pressed={feedback?.rating === 'thumbsUp'}
|
||||
aria-haspopup="menu"
|
||||
>
|
||||
<ThumbUpIcon size="1.1875rem" bold={feedback?.rating === 'thumbsUp'} />
|
||||
</Button>
|
||||
<TooltipAnchor
|
||||
description={localize('com_ui_feedback_positive')}
|
||||
render={
|
||||
<Button
|
||||
variant={isLast ? 'message-hover' : 'message-hover-reveal'}
|
||||
data-hover-active={feedback?.rating === 'thumbsUp' || undefined}
|
||||
onClick={handleThumbsUpClick}
|
||||
aria-label={localize('com_ui_feedback_positive')}
|
||||
aria-pressed={feedback?.rating === 'thumbsUp'}
|
||||
aria-haspopup="menu"
|
||||
>
|
||||
<ThumbUpIcon size="1.1875rem" bold={feedback?.rating === 'thumbsUp'} />
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Ariakit.Popover
|
||||
|
|
@ -157,7 +162,7 @@ function FeedbackButtons({
|
|||
gutter={8}
|
||||
portal
|
||||
unmountOnHide
|
||||
className="popover-animate border-border-medium bg-surface-secondary rounded-theme-popover flex w-auto flex-col gap-1.5 overflow-hidden border p-1.5 shadow-lg"
|
||||
className="animate-composer-popover border-border-medium bg-surface-secondary rounded-theme-popover flex w-auto flex-col gap-1.5 overflow-hidden border p-1.5 shadow-lg motion-reduce:transition-none"
|
||||
>
|
||||
<div className="flex flex-col items-stretch justify-center">
|
||||
{positiveTags.map((tag) => (
|
||||
|
|
@ -174,16 +179,21 @@ function FeedbackButtons({
|
|||
<Ariakit.PopoverAnchor
|
||||
store={downStore}
|
||||
render={
|
||||
<Button
|
||||
variant={isLast ? 'message-hover' : 'message-hover-reveal'}
|
||||
data-hover-active={feedback?.rating === 'thumbsDown' || undefined}
|
||||
onClick={handleThumbsDownClick}
|
||||
title={localize('com_ui_feedback_negative')}
|
||||
aria-pressed={feedback?.rating === 'thumbsDown'}
|
||||
aria-haspopup="menu"
|
||||
>
|
||||
<ThumbDownIcon size="1.1875rem" bold={feedback?.rating === 'thumbsDown'} />
|
||||
</Button>
|
||||
<TooltipAnchor
|
||||
description={localize('com_ui_feedback_negative')}
|
||||
render={
|
||||
<Button
|
||||
variant={isLast ? 'message-hover' : 'message-hover-reveal'}
|
||||
data-hover-active={feedback?.rating === 'thumbsDown' || undefined}
|
||||
onClick={handleThumbsDownClick}
|
||||
aria-label={localize('com_ui_feedback_negative')}
|
||||
aria-pressed={feedback?.rating === 'thumbsDown'}
|
||||
aria-haspopup="menu"
|
||||
>
|
||||
<ThumbDownIcon size="1.1875rem" bold={feedback?.rating === 'thumbsDown'} />
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Ariakit.Popover
|
||||
|
|
@ -191,7 +201,7 @@ function FeedbackButtons({
|
|||
gutter={8}
|
||||
portal
|
||||
unmountOnHide
|
||||
className="popover-animate border-border-medium bg-surface-secondary rounded-theme-popover flex w-auto flex-col gap-1.5 overflow-hidden border p-1.5 shadow-lg"
|
||||
className="animate-composer-popover border-border-medium bg-surface-secondary rounded-theme-popover flex w-auto flex-col gap-1.5 overflow-hidden border p-1.5 shadow-lg motion-reduce:transition-none"
|
||||
>
|
||||
<div className="flex flex-col items-stretch justify-center">
|
||||
{negativeTags.map((tag) => (
|
||||
|
|
|
|||
|
|
@ -1,210 +1,46 @@
|
|||
import React, { memo, useState, useRef } from 'react';
|
||||
import React, { memo, useId, useState } from 'react';
|
||||
import * as Ariakit from '@ariakit/react';
|
||||
import { VisuallyHidden } from '@ariakit/react';
|
||||
import { GitFork, InfoIcon } from 'lucide-react';
|
||||
import { GitFork, ChevronDown } from 'lucide-react';
|
||||
import { ForkOptions } from 'librechat-data-provider';
|
||||
import { GitCommit, GitBranchPlus, ListTree } from 'lucide-react';
|
||||
import { Button, Label, Checkbox, useLocalize, useToastContext } from '@librechat/client';
|
||||
import {
|
||||
Radio,
|
||||
Label,
|
||||
Button,
|
||||
Checkbox,
|
||||
useLocalize,
|
||||
TooltipAnchor,
|
||||
useToastContext,
|
||||
} from '@librechat/client';
|
||||
import type { TForkConvoRequest } from 'librechat-data-provider';
|
||||
import type { TranslationKeys } from '@librechat/client';
|
||||
import type { NamedExoticComponent } from 'react';
|
||||
import { useMessagesHost } from '../../react/messages/host';
|
||||
|
||||
interface PopoverButtonProps {
|
||||
children: React.ReactNode;
|
||||
setting: ForkOptions;
|
||||
onClick: (setting: ForkOptions) => void;
|
||||
setActiveSetting: React.Dispatch<React.SetStateAction<TranslationKeys>>;
|
||||
timeoutRef: React.MutableRefObject<NodeJS.Timeout | null>;
|
||||
hoverInfo?: React.ReactNode | string;
|
||||
hoverTitle?: React.ReactNode | string;
|
||||
hoverDescription?: React.ReactNode | string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
/** Resolved per call: a module-scope map keyed by the enum crashes hosts that mock the data provider. */
|
||||
const optionLabel = (setting: ForkOptions): TranslationKeys => {
|
||||
switch (setting) {
|
||||
case ForkOptions.DIRECT_PATH:
|
||||
return 'com_ui_fork_visible';
|
||||
case ForkOptions.INCLUDE_BRANCHES:
|
||||
return 'com_ui_fork_branches';
|
||||
case ForkOptions.TARGET_LEVEL:
|
||||
return 'com_ui_fork_all_target';
|
||||
default:
|
||||
return 'com_ui_fork_from_message';
|
||||
}
|
||||
};
|
||||
|
||||
const chevronDown = (
|
||||
<svg width="1em" height="1em" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
clipRule="evenodd"
|
||||
d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
const PopoverButton: React.FC<PopoverButtonProps> = ({
|
||||
children,
|
||||
setting,
|
||||
onClick,
|
||||
setActiveSetting,
|
||||
timeoutRef,
|
||||
hoverInfo,
|
||||
hoverTitle,
|
||||
hoverDescription,
|
||||
label,
|
||||
}) => {
|
||||
const localize = useLocalize();
|
||||
|
||||
return (
|
||||
<Ariakit.HovercardProvider placement="right-start">
|
||||
<div className="flex flex-col items-center">
|
||||
<Ariakit.HovercardAnchor
|
||||
render={
|
||||
<Ariakit.Button
|
||||
onClick={() => onClick(setting)}
|
||||
onMouseEnter={() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = null;
|
||||
}
|
||||
setActiveSetting(optionLabel(setting));
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setActiveSetting(optionLabel(ForkOptions.DEFAULT));
|
||||
}, 175);
|
||||
}}
|
||||
onFocus={() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = null;
|
||||
}
|
||||
setActiveSetting(optionLabel(setting));
|
||||
}}
|
||||
onBlur={() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
setActiveSetting(optionLabel(ForkOptions.DEFAULT));
|
||||
}, 175);
|
||||
}}
|
||||
className="border-border-medium bg-surface-secondary text-text-secondary hover:bg-surface-hover hover:text-text-primary mx-0.5 w-14 flex-1 rounded-xl border-2 transition duration-200 ease-in-out"
|
||||
aria-label={label}
|
||||
>
|
||||
{children}
|
||||
<VisuallyHidden>{label}</VisuallyHidden>
|
||||
</Ariakit.Button>
|
||||
}
|
||||
/>
|
||||
<Ariakit.HovercardDisclosure className="text-text-secondary focus:ring-text-primary rounded-full focus:ring-2 focus:outline-hidden">
|
||||
<VisuallyHidden>
|
||||
{localize('com_ui_fork_more_details_about', { 0: label })}
|
||||
</VisuallyHidden>
|
||||
{chevronDown}
|
||||
</Ariakit.HovercardDisclosure>
|
||||
{((hoverInfo != null && hoverInfo !== '') ||
|
||||
(hoverTitle != null && hoverTitle !== '') ||
|
||||
(hoverDescription != null && hoverDescription !== '')) && (
|
||||
<Ariakit.Hovercard
|
||||
gutter={16}
|
||||
shift={40}
|
||||
flip={false}
|
||||
className="border-border-medium bg-surface-secondary text-text-primary rounded-theme-popover z-[999] w-[min(20rem,90vw)] border p-4 shadow-md"
|
||||
portal={true}
|
||||
unmountOnHide={true}
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<p className="text-text-secondary flex flex-col gap-2 text-sm">
|
||||
{hoverInfo && hoverInfo}
|
||||
{hoverTitle && <span className="flex flex-wrap gap-1 font-bold">{hoverTitle}</span>}
|
||||
{hoverDescription && hoverDescription}
|
||||
</p>
|
||||
</div>
|
||||
</Ariakit.Hovercard>
|
||||
)}
|
||||
</div>
|
||||
</Ariakit.HovercardProvider>
|
||||
);
|
||||
};
|
||||
|
||||
interface CheckboxOptionProps {
|
||||
interface CompactCheckboxProps {
|
||||
id: string;
|
||||
checked: boolean;
|
||||
onToggle: (checked: boolean) => void;
|
||||
labelKey: TranslationKeys;
|
||||
infoKey: TranslationKeys;
|
||||
showToastOnCheck?: boolean;
|
||||
label: string;
|
||||
}
|
||||
const CheckboxOption: React.FC<CheckboxOptionProps> = ({
|
||||
id,
|
||||
checked,
|
||||
onToggle,
|
||||
labelKey,
|
||||
infoKey,
|
||||
showToastOnCheck = false,
|
||||
}) => {
|
||||
const localize = useLocalize();
|
||||
const { showToast } = useToastContext();
|
||||
return (
|
||||
<Ariakit.HovercardProvider placement="right-start">
|
||||
<div className="flex items-center justify-between">
|
||||
<Ariakit.HovercardAnchor
|
||||
render={
|
||||
<div className="flex items-center">
|
||||
<Checkbox
|
||||
id={id}
|
||||
checked={checked}
|
||||
onCheckedChange={(value) => {
|
||||
const isChecked = value === true;
|
||||
if (isChecked && showToastOnCheck) {
|
||||
showToast({
|
||||
message: localize('com_ui_fork_remember_checked'),
|
||||
status: 'info',
|
||||
});
|
||||
}
|
||||
onToggle(isChecked);
|
||||
}}
|
||||
variant="fade"
|
||||
aria-label={localize(labelKey)}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={id}
|
||||
variant="option"
|
||||
className="ms-2 w-auto cursor-pointer text-sm break-normal select-none"
|
||||
>
|
||||
{localize(labelKey)}
|
||||
</Label>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<Ariakit.HovercardDisclosure className="text-text-secondary focus:ring-text-primary ms-1 rounded-full focus:ring-2 focus:outline-hidden">
|
||||
<VisuallyHidden>{localize(infoKey)}</VisuallyHidden>
|
||||
{chevronDown}
|
||||
</Ariakit.HovercardDisclosure>
|
||||
</div>
|
||||
<Ariakit.Hovercard
|
||||
gutter={14}
|
||||
shift={40}
|
||||
flip={false}
|
||||
className="border-border-medium bg-surface-secondary text-text-primary rounded-theme-popover z-[999] w-[min(20rem,90vw)] border p-4 shadow-md"
|
||||
portal={true}
|
||||
unmountOnHide={true}
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<p className="text-text-secondary text-sm">{localize(infoKey)}</p>
|
||||
</div>
|
||||
</Ariakit.Hovercard>
|
||||
</Ariakit.HovercardProvider>
|
||||
);
|
||||
};
|
||||
|
||||
const CompactCheckbox: React.FC<CompactCheckboxProps> = ({ id, checked, onToggle, label }) => (
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={id}
|
||||
checked={checked}
|
||||
onCheckedChange={(value) => onToggle(value === true)}
|
||||
variant="fade"
|
||||
aria-label={label}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={id}
|
||||
variant="option"
|
||||
className="w-auto cursor-pointer text-xs break-normal select-none"
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
</div>
|
||||
);
|
||||
|
||||
type ForkProps = {
|
||||
messageId: string;
|
||||
|
|
@ -250,8 +86,18 @@ function Fork({
|
|||
rememberOption: rememberGlobal,
|
||||
setRememberOption: setRememberGlobal,
|
||||
} = host.useForkPreferences();
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const [activeSetting, setActiveSetting] = useState(optionLabel(ForkOptions.DEFAULT));
|
||||
const groupId = useId();
|
||||
const defaultMode = forkSetting || ForkOptions.TARGET_LEVEL;
|
||||
const [selected, setSelected] = useState<string>(defaultMode);
|
||||
/** The stored default can change while this toolbar stays mounted (Settings does it), so the
|
||||
* picked mode follows it. Adjusting state during render replaces the pick before the first
|
||||
* paint; an effect would paint the old mode once. */
|
||||
const [seenDefault, setSeenDefault] = useState(defaultMode);
|
||||
if (seenDefault !== defaultMode) {
|
||||
setSeenDefault(defaultMode);
|
||||
setSelected(defaultMode);
|
||||
}
|
||||
const [showMore, setShowMore] = useState(false);
|
||||
const popoverStore = Ariakit.usePopoverStore({
|
||||
placement: 'bottom',
|
||||
});
|
||||
|
|
@ -298,163 +144,164 @@ function Fork({
|
|||
});
|
||||
};
|
||||
|
||||
const forkOptionsConfig = [
|
||||
{
|
||||
setting: ForkOptions.DIRECT_PATH,
|
||||
label: localize(optionLabel(ForkOptions.DIRECT_PATH)),
|
||||
icon: <GitCommit className="h-full w-full rotate-90 p-2" aria-hidden="true" />,
|
||||
hoverTitle: (
|
||||
<>
|
||||
<GitCommit className="h-5 w-5 rotate-90" aria-hidden="true" />
|
||||
{localize(optionLabel(ForkOptions.DIRECT_PATH))}
|
||||
</>
|
||||
),
|
||||
hoverDescription: localize('com_ui_fork_info_visible'),
|
||||
},
|
||||
{
|
||||
setting: ForkOptions.INCLUDE_BRANCHES,
|
||||
label: localize(optionLabel(ForkOptions.INCLUDE_BRANCHES)),
|
||||
icon: <GitBranchPlus className="h-full w-full rotate-180 p-2" aria-hidden="true" />,
|
||||
hoverTitle: (
|
||||
<>
|
||||
<GitBranchPlus className="h-4 w-4 rotate-180" aria-hidden="true" />
|
||||
{localize(optionLabel(ForkOptions.INCLUDE_BRANCHES))}
|
||||
</>
|
||||
),
|
||||
hoverDescription: localize('com_ui_fork_info_branches'),
|
||||
},
|
||||
{
|
||||
setting: ForkOptions.TARGET_LEVEL,
|
||||
label: localize(optionLabel(ForkOptions.TARGET_LEVEL)),
|
||||
icon: <ListTree className="h-full w-full p-2" aria-hidden="true" />,
|
||||
hoverTitle: (
|
||||
<>
|
||||
<ListTree className="h-5 w-5" aria-hidden="true" />
|
||||
{`${localize(optionLabel(ForkOptions.TARGET_LEVEL))} (${localize('com_endpoint_default')})`}
|
||||
</>
|
||||
),
|
||||
hoverDescription: localize('com_ui_fork_info_target'),
|
||||
},
|
||||
const scopeOptions = [
|
||||
{ value: 'before', label: localize('com_ui_fork_scope_before') },
|
||||
{ value: 'after', label: localize('com_ui_fork_scope_after') },
|
||||
];
|
||||
const modeOptions = [
|
||||
{ value: ForkOptions.DIRECT_PATH, label: localize('com_ui_fork_mode_visible') },
|
||||
{ value: ForkOptions.INCLUDE_BRANCHES, label: localize('com_ui_fork_mode_branches') },
|
||||
{ value: ForkOptions.TARGET_LEVEL, label: localize('com_ui_fork_mode_all') },
|
||||
];
|
||||
const modeHelp: Record<string, TranslationKeys> = {
|
||||
[ForkOptions.DIRECT_PATH]: 'com_ui_fork_desc_visible',
|
||||
[ForkOptions.INCLUDE_BRANCHES]: 'com_ui_fork_desc_branches',
|
||||
[ForkOptions.TARGET_LEVEL]: 'com_ui_fork_desc_target',
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Ariakit.PopoverAnchor
|
||||
store={popoverStore}
|
||||
render={
|
||||
<Button
|
||||
variant={isLast ? 'message-hover' : 'message-hover-reveal'}
|
||||
data-hover-active={isActive || undefined}
|
||||
onClick={(e) => {
|
||||
if (rememberGlobal) {
|
||||
e.preventDefault();
|
||||
startFork({
|
||||
messageId,
|
||||
splitAtTarget,
|
||||
conversationId,
|
||||
option: forkSetting,
|
||||
latestMessageId: getLatestMessageId?.(),
|
||||
});
|
||||
} else {
|
||||
popoverStore.toggle();
|
||||
}
|
||||
}}
|
||||
type="button"
|
||||
aria-label={localize('com_ui_fork_open_menu')}
|
||||
>
|
||||
<GitFork className="size-[1.1875rem]" aria-hidden="true" />
|
||||
</Button>
|
||||
<TooltipAnchor
|
||||
description={localize('com_ui_fork_open_menu')}
|
||||
render={
|
||||
<Button
|
||||
variant={isLast ? 'message-hover' : 'message-hover-reveal'}
|
||||
data-hover-active={isActive || undefined}
|
||||
onClick={(e) => {
|
||||
if (rememberGlobal) {
|
||||
e.preventDefault();
|
||||
startFork({
|
||||
messageId,
|
||||
splitAtTarget,
|
||||
conversationId,
|
||||
option: forkSetting,
|
||||
latestMessageId: getLatestMessageId?.(),
|
||||
});
|
||||
} else {
|
||||
popoverStore.toggle();
|
||||
}
|
||||
}}
|
||||
type="button"
|
||||
aria-label={localize('com_ui_fork_open_menu')}
|
||||
>
|
||||
<GitFork className="size-[1.1875rem]" aria-hidden="true" />
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Ariakit.Popover
|
||||
store={popoverStore}
|
||||
gutter={10}
|
||||
className={`popover-animate ${isActive ? 'open' : ''} border-border-medium bg-surface-secondary rounded-theme-popover pointer-events-auto flex w-[min(15rem,90vw)] flex-col gap-3 overflow-hidden border p-2 px-4 shadow-lg outline-none`}
|
||||
aria-labelledby={`${groupId}-title`}
|
||||
className="animate-composer-popover border-border-medium bg-surface-secondary rounded-theme-popover pointer-events-auto flex w-[min(21rem,92vw)] flex-col overflow-hidden border p-4 shadow-lg outline-none motion-reduce:transition-none"
|
||||
style={{ zIndex: 50 }}
|
||||
portal={true}
|
||||
unmountOnHide={true}
|
||||
>
|
||||
<div className="text-text-primary flex h-8 w-full items-center justify-center text-sm">
|
||||
{localize(activeSetting)}
|
||||
<Ariakit.HovercardProvider placement="right-start">
|
||||
<div className="ms-auto flex h-6 w-6 items-center justify-center gap-1">
|
||||
<Ariakit.HovercardAnchor
|
||||
render={
|
||||
<button
|
||||
className="text-text-secondary flex h-5 w-5 cursor-help items-center rounded-full"
|
||||
aria-label={localize('com_ui_fork_info_button_label')}
|
||||
>
|
||||
<InfoIcon aria-hidden="true" />
|
||||
</button>
|
||||
}
|
||||
/>
|
||||
<Ariakit.HovercardDisclosure className="text-text-secondary focus:ring-text-primary rounded-full focus:ring-2 focus:outline-hidden">
|
||||
<VisuallyHidden>{localize('com_ui_fork_more_info_options')}</VisuallyHidden>
|
||||
{chevronDown}
|
||||
</Ariakit.HovercardDisclosure>
|
||||
</div>
|
||||
<Ariakit.Hovercard
|
||||
gutter={19}
|
||||
shift={40}
|
||||
flip={false}
|
||||
className="border-border-medium bg-surface-secondary text-text-primary rounded-theme-popover z-[999] w-[min(20rem,90vw)] border p-4 shadow-md"
|
||||
portal={true}
|
||||
unmountOnHide={true}
|
||||
>
|
||||
<div className="text-text-secondary flex flex-col gap-2 space-y-2 text-sm">
|
||||
<span>{localize('com_ui_fork_info_1')}</span>
|
||||
<span>{localize('com_ui_fork_info_2')}</span>
|
||||
<span>
|
||||
{localize('com_ui_fork_info_3', {
|
||||
0: localize('com_ui_fork_split_target'),
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
</Ariakit.Hovercard>
|
||||
</Ariakit.HovercardProvider>
|
||||
</div>
|
||||
<div className="flex h-full w-full items-center justify-center gap-1">
|
||||
{forkOptionsConfig.map((opt) => (
|
||||
<PopoverButton
|
||||
key={opt.setting}
|
||||
setActiveSetting={setActiveSetting}
|
||||
timeoutRef={timeoutRef}
|
||||
onClick={onClick}
|
||||
setting={opt.setting}
|
||||
label={opt.label}
|
||||
hoverTitle={opt.hoverTitle}
|
||||
hoverDescription={opt.hoverDescription}
|
||||
>
|
||||
{opt.icon}
|
||||
</PopoverButton>
|
||||
))}
|
||||
</div>
|
||||
<CheckboxOption
|
||||
id="split-target-checkbox"
|
||||
checked={splitAtTarget}
|
||||
onToggle={setSplitAtTarget}
|
||||
labelKey="com_ui_fork_split_target"
|
||||
infoKey="com_ui_fork_info_start"
|
||||
/>
|
||||
<CheckboxOption
|
||||
id="exclude-files-checkbox"
|
||||
checked={excludeFiles}
|
||||
onToggle={setExcludeFiles}
|
||||
labelKey="com_ui_fork_exclude_files"
|
||||
infoKey="com_ui_fork_info_exclude_files"
|
||||
/>
|
||||
<CheckboxOption
|
||||
id="remember-checkbox"
|
||||
checked={remember}
|
||||
onToggle={(checked) => {
|
||||
if (checked)
|
||||
showToast({ message: localize('com_ui_fork_remember_checked'), status: 'info' });
|
||||
setRemember(checked);
|
||||
<form
|
||||
className="flex flex-col gap-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
popoverStore.hide();
|
||||
onClick(selected);
|
||||
}}
|
||||
labelKey="com_ui_fork_remember"
|
||||
infoKey="com_ui_fork_info_remember"
|
||||
showToastOnCheck
|
||||
/>
|
||||
>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<h2 id={`${groupId}-title`} className="text-text-primary text-sm font-semibold">
|
||||
{localize('com_ui_fork_from_message')}
|
||||
</h2>
|
||||
<p className="text-text-secondary text-xs">{localize('com_ui_fork_subtitle')}</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2.5">
|
||||
<Radio
|
||||
tone="raised"
|
||||
fullWidth
|
||||
options={scopeOptions}
|
||||
value={splitAtTarget ? 'after' : 'before'}
|
||||
onChange={(value) => setSplitAtTarget(value === 'after')}
|
||||
aria-labelledby={`${groupId}-title`}
|
||||
/>
|
||||
<p className="text-text-secondary text-xs" aria-live="polite">
|
||||
{localize(
|
||||
splitAtTarget ? 'com_ui_fork_scope_after_help' : 'com_ui_fork_scope_before_help',
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<Button
|
||||
type="button"
|
||||
variant="inline-link"
|
||||
className="self-start"
|
||||
aria-expanded={showMore}
|
||||
aria-controls={`${groupId}-more`}
|
||||
onClick={() => setShowMore((open) => !open)}
|
||||
>
|
||||
{localize(showMore ? 'com_ui_fork_fewer_options' : 'com_ui_fork_more_options')}
|
||||
<ChevronDown
|
||||
className={`size-4 transition-transform duration-300 ease-out motion-reduce:transition-none ${showMore ? 'rotate-180' : ''}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</Button>
|
||||
<div
|
||||
id={`${groupId}-more`}
|
||||
aria-hidden={!showMore || undefined}
|
||||
{...(showMore ? {} : { inert: '' })}
|
||||
className={`grid transition-all duration-300 ease-out motion-reduce:transition-none ${showMore ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]'}`}
|
||||
>
|
||||
<div className="-m-1 min-h-0 overflow-hidden">
|
||||
<div
|
||||
className={`transition-opacity duration-300 ease-out motion-reduce:transition-none ${showMore ? 'opacity-100' : 'opacity-0'}`}
|
||||
>
|
||||
{/* The space under the link lives inside the reveal, so a collapsed region leaves no gap. */}
|
||||
<div className="flex flex-col gap-3 p-1 pt-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span
|
||||
id={`${groupId}-mode`}
|
||||
className="text-text-primary text-xs font-medium"
|
||||
>
|
||||
{localize('com_ui_fork_include')}
|
||||
</span>
|
||||
<Radio
|
||||
tone="raised"
|
||||
fullWidth
|
||||
size="sm"
|
||||
options={modeOptions}
|
||||
value={selected}
|
||||
onChange={setSelected}
|
||||
aria-labelledby={`${groupId}-mode`}
|
||||
/>
|
||||
<p className="text-text-secondary text-xs" aria-live="polite">
|
||||
{localize(modeHelp[selected] ?? 'com_ui_fork_desc_target')}
|
||||
</p>
|
||||
</div>
|
||||
<CompactCheckbox
|
||||
id="exclude-files-checkbox"
|
||||
checked={excludeFiles}
|
||||
onToggle={setExcludeFiles}
|
||||
label={localize('com_ui_fork_exclude_files')}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-border-light flex items-center justify-between gap-3 border-t pt-3">
|
||||
<CompactCheckbox
|
||||
id="remember-checkbox"
|
||||
checked={remember}
|
||||
onToggle={setRemember}
|
||||
label={localize('com_ui_fork_remember')}
|
||||
/>
|
||||
<Button type="submit" variant="submit">
|
||||
<GitFork className="size-4" aria-hidden="true" />
|
||||
{localize('com_ui_fork')}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Ariakit.Popover>
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* @jest-environment jsdom
|
||||
*/
|
||||
import { useState } from 'react';
|
||||
import { useState, useSyncExternalStore } from 'react';
|
||||
import { ForkOptions } from 'librechat-data-provider';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { ForkConversation, ForkPreferences } from '../../../react/messages/host';
|
||||
import { createMessagesHost } from '../../../__fixtures__/messagesHost';
|
||||
|
|
@ -98,8 +98,10 @@ describe('Fork', () => {
|
|||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_open_menu' }));
|
||||
fireEvent.click(await screen.findByRole('checkbox', { name: 'com_ui_fork_exclude_files' }));
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_visible' }));
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'com_ui_fork_more_options' }));
|
||||
fireEvent.click(screen.getByRole('checkbox', { name: 'com_ui_fork_exclude_files' }));
|
||||
fireEvent.click(screen.getByRole('radio', { name: 'com_ui_fork_mode_visible' }));
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork' }));
|
||||
|
||||
expect(forkConversation).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
|
|
@ -111,6 +113,118 @@ describe('Fork', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('shows and sends the "From here on" scope when it is the stored preference', async () => {
|
||||
render(
|
||||
<ForkHost forkConversation={forkConversation} defaults={{ splitAtTarget: true }}>
|
||||
<Fork
|
||||
messageId="assistant-1"
|
||||
conversationId="convo-1"
|
||||
forkingSupported={true}
|
||||
getLatestMessageId={() => 'assistant-9'}
|
||||
/>
|
||||
</ForkHost>,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_open_menu' }));
|
||||
const after = await screen.findByRole('radio', { name: 'com_ui_fork_scope_after' });
|
||||
expect(after).toHaveAttribute('aria-checked', 'true');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork' }));
|
||||
|
||||
expect(forkConversation).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ splitAtTarget: true, latestMessageId: 'assistant-9' }),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the advanced options collapsed until asked for', async () => {
|
||||
render(
|
||||
<ForkHost forkConversation={forkConversation}>
|
||||
<Fork messageId="assistant-1" conversationId="convo-1" forkingSupported={true} />
|
||||
</ForkHost>,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_open_menu' }));
|
||||
const toggle = await screen.findByRole('button', { name: 'com_ui_fork_more_options' });
|
||||
expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
||||
expect(screen.queryByRole('checkbox', { name: 'com_ui_fork_exclude_files' })).toBeNull();
|
||||
fireEvent.click(toggle);
|
||||
expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
||||
});
|
||||
|
||||
it('opens the extra options on a collapsing region, turning the chevron with it', async () => {
|
||||
render(
|
||||
<ForkHost forkConversation={forkConversation}>
|
||||
<Fork messageId="assistant-1" conversationId="convo-1" forkingSupported={true} />
|
||||
</ForkHost>,
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_open_menu' }));
|
||||
const toggle = await screen.findByRole('button', { name: 'com_ui_fork_more_options' });
|
||||
const chevron = toggle.querySelector('svg');
|
||||
const region = document.getElementById(toggle.getAttribute('aria-controls') ?? '');
|
||||
|
||||
expect(region).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(region).toHaveAttribute('inert');
|
||||
expect(region).toHaveClass('grid-rows-[0fr]');
|
||||
expect(chevron).not.toHaveClass('rotate-180');
|
||||
|
||||
fireEvent.click(toggle);
|
||||
expect(region).not.toHaveAttribute('aria-hidden');
|
||||
expect(region).not.toHaveAttribute('inert');
|
||||
expect(region).toHaveClass('grid-rows-[1fr]');
|
||||
expect(chevron).toHaveClass('rotate-180');
|
||||
});
|
||||
|
||||
/** The default mode lives in a store the Settings dialog also writes, so it can change while the
|
||||
* message toolbar stays mounted. */
|
||||
it('follows the stored default mode when it changes while the toolbar stays mounted', async () => {
|
||||
let stored: string = ForkOptions.INCLUDE_BRANCHES;
|
||||
const listeners = new Set<() => void>();
|
||||
const setStored = (next: string) => {
|
||||
stored = next;
|
||||
listeners.forEach((listener) => listener());
|
||||
};
|
||||
const preferences = {
|
||||
setOption: setStored,
|
||||
splitAtTarget: false,
|
||||
setSplitAtTarget: () => {},
|
||||
rememberOption: false,
|
||||
setRememberOption: () => {},
|
||||
};
|
||||
const host = createMessagesHost({
|
||||
useForkPreferences: () => ({
|
||||
...preferences,
|
||||
option: useSyncExternalStore(
|
||||
(listener) => {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
},
|
||||
() => stored,
|
||||
),
|
||||
}),
|
||||
useForkConversation: () => forkConversation,
|
||||
});
|
||||
render(
|
||||
<MessagesHostProvider host={host}>
|
||||
<Fork messageId="assistant-1" conversationId="convo-1" forkingSupported={true} />
|
||||
</MessagesHostProvider>,
|
||||
);
|
||||
|
||||
act(() => setStored(ForkOptions.DIRECT_PATH));
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_open_menu' }));
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'com_ui_fork_more_options' }));
|
||||
expect(screen.getByRole('radio', { name: 'com_ui_fork_mode_visible' })).toHaveAttribute(
|
||||
'aria-checked',
|
||||
'true',
|
||||
);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork' }));
|
||||
|
||||
expect(forkConversation).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ option: ForkOptions.DIRECT_PATH }),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps files by default', async () => {
|
||||
render(
|
||||
<ForkHost forkConversation={forkConversation}>
|
||||
|
|
@ -119,7 +233,7 @@ describe('Fork', () => {
|
|||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_open_menu' }));
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'com_ui_fork_visible' }));
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'com_ui_fork' }));
|
||||
|
||||
const calls = forkConversation.mock.calls;
|
||||
expect(calls[calls.length - 1]?.[0]).not.toHaveProperty('excludeFiles');
|
||||
|
|
@ -133,7 +247,7 @@ describe('Fork', () => {
|
|||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'com_ui_fork_open_menu' }));
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'com_ui_fork_visible' }));
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'com_ui_fork' }));
|
||||
expect(mockShowToast).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ message: 'com_ui_fork_processing' }),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -46,18 +46,18 @@ describe('revealOnRowHoverClasses', () => {
|
|||
expect(revealOnRowHoverClasses).toContain('motion-reduce:transition-none');
|
||||
});
|
||||
|
||||
/* `cn` merges the whole `transition-*` group, so a bare `transition-opacity`
|
||||
would replace the `transition-colors` a `Button` contributes and the hover
|
||||
tint would snap. The colour properties have to ride along explicitly. */
|
||||
it('names the colour properties alongside opacity', () => {
|
||||
expect(revealOnRowHoverClasses).toContain('transition-reveal');
|
||||
expect(revealOnRowHoverClasses).not.toContain('transition-opacity');
|
||||
/* The hover tint snaps: only opacity transitions, and the reveal replaces the
|
||||
`transition-none` the toolbar buttons carry. */
|
||||
it('transitions opacity only', () => {
|
||||
expect(revealOnRowHoverClasses).toContain('transition-opacity');
|
||||
expect(revealOnRowHoverClasses).not.toContain('transition-reveal');
|
||||
});
|
||||
|
||||
it('keeps the colour fade when merged onto a Button', () => {
|
||||
it('does not fade colours when merged onto a Button', () => {
|
||||
const merged = cn(buttonVariants({ variant: 'message-hover-reveal' }));
|
||||
expect(merged).toContain('transition-reveal');
|
||||
expect(merged).toContain('transition-opacity');
|
||||
expect(merged).not.toContain('transition-colors');
|
||||
expect(cn(buttonVariants({ variant: 'message-hover' }))).toContain('transition-none');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -51,13 +51,11 @@ export const disabledInkClasses =
|
|||
* lightningcss rejects and which fails the production CSS build while leaving `jest`
|
||||
* and `tsc` perfectly green.
|
||||
*
|
||||
* The transition is `transition-reveal` (opacity, color and background-color) rather
|
||||
* than `transition-opacity`: `cn` merges the whole `transition-*` group, so a bare
|
||||
* `transition-opacity` would replace the `transition-colors` a `Button` brings and
|
||||
* the hover tint would snap instead of fading.
|
||||
* The transition is opacity only: the hover tint snaps, it does not fade, and `cn` merges the
|
||||
* whole `transition-*` group so this replaces the `transition-none` the toolbar buttons carry.
|
||||
*/
|
||||
export const revealOnRowHoverClasses =
|
||||
'transition-reveal duration-theme-normal ease-out group-hover:opacity-100 group-focus-visible:opacity-100 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-100 motion-reduce:transition-none no-touch:opacity-0';
|
||||
'transition-opacity duration-theme-normal ease-out group-hover:opacity-100 group-focus-visible:opacity-100 group-has-[:focus-visible:not(:is(input,textarea,[contenteditable]))]:opacity-100 motion-reduce:transition-none no-touch:opacity-0';
|
||||
|
||||
export const peerDisabledInkClasses =
|
||||
'peer-theme-disabled:text-text-disabled peer-theme-disabled:opacity-100 peer-theme-disabled:[&_svg]:text-text-disabled';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue