From 78c516b610a43c1d04116a6bfb7918f9386ab5d1 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:45:42 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=B4=20style:=20Restyle=20the=20Fork=20?= =?UTF-8?q?Popover=20and=20Calm=20the=20Feedback=20Hover=20(#18103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../Messages/__tests__/HoverButtons.spec.tsx | 8 +- .../components/Messages/Content/CodeBar.tsx | 2 +- client/src/locales/en/translation.json | 32 +- e2e/specs/mock/hover-actions.spec.ts | 2 +- e2e/specs/mock/message-tree.spec.ts | 5 +- .../mock/scenarios/fork-feedback.spec.ts | 70 ++- e2e/specs/mock/scenarios/mouse-reveal.spec.ts | 4 +- .../chat/src/components/messages/Feedback.tsx | 54 +- .../chat/src/components/messages/Fork.tsx | 523 +++++++----------- .../messages/__tests__/Fork.spec.tsx | 126 ++++- .../messages/__tests__/styles.spec.ts | 16 +- packages/client/src/utils/theme.ts | 8 +- 12 files changed, 443 insertions(+), 407 deletions(-) diff --git a/client/src/components/Chat/Messages/__tests__/HoverButtons.spec.tsx b/client/src/components/Chat/Messages/__tests__/HoverButtons.spec.tsx index 40a5207bf6..1f7d0e00bc 100644 --- a/client/src/components/Chat/Messages/__tests__/HoverButtons.spec.tsx +++ b/client/src/components/Chat/Messages/__tests__/HoverButtons.spec.tsx @@ -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(); }); }); diff --git a/client/src/components/Messages/Content/CodeBar.tsx b/client/src/components/Messages/Content/CodeBar.tsx index 037a91748c..b1003b8da7 100644 --- a/client/src/components/Messages/Content/CodeBar.tsx +++ b/client/src/components/Messages/Content/CodeBar.tsx @@ -16,7 +16,7 @@ const CodeBar: React.FC = React.memo( return (
- + {lang} diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json index 38770c942f..571ea54f47 100644 --- a/client/src/locales/en/translation.json +++ b/client/src/locales/en/translation.json @@ -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", diff --git a/e2e/specs/mock/hover-actions.spec.ts b/e2e/specs/mock/hover-actions.spec.ts index 98ef71e0a8..044ca2d20f 100644 --- a/e2e/specs/mock/hover-actions.spec.ts +++ b/e2e/specs/mock/hover-actions.spec.ts @@ -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'); diff --git a/e2e/specs/mock/message-tree.spec.ts b/e2e/specs/mock/message-tree.spec.ts index 519a468870..5db6ee93e0 100644 --- a/e2e/specs/mock/message-tree.spec.ts +++ b/e2e/specs/mock/message-tree.spec.ts @@ -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; diff --git a/e2e/specs/mock/scenarios/fork-feedback.spec.ts b/e2e/specs/mock/scenarios/fork-feedback.spec.ts index 0833455bf4..ef4fb793e9 100644 --- a/e2e/specs/mock/scenarios/fork-feedback.spec.ts +++ b/e2e/specs/mock/scenarios/fork-feedback.spec.ts @@ -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(); diff --git a/e2e/specs/mock/scenarios/mouse-reveal.spec.ts b/e2e/specs/mock/scenarios/mouse-reveal.spec.ts index d405e67444..c75c970dcd 100644 --- a/e2e/specs/mock/scenarios/mouse-reveal.spec.ts +++ b/e2e/specs/mock/scenarios/mouse-reveal.spec.ts @@ -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); diff --git a/packages/chat/src/components/messages/Feedback.tsx b/packages/chat/src/components/messages/Feedback.tsx index 2ac01195c5..bbb4350607 100644 --- a/packages/chat/src/components/messages/Feedback.tsx +++ b/packages/chat/src/components/messages/Feedback.tsx @@ -140,16 +140,21 @@ function FeedbackButtons({ - - + + + + } + /> } />
{positiveTags.map((tag) => ( @@ -174,16 +179,21 @@ function FeedbackButtons({ - - + + + + } + /> } />
{negativeTags.map((tag) => ( diff --git a/packages/chat/src/components/messages/Fork.tsx b/packages/chat/src/components/messages/Fork.tsx index 26b5df4b23..52b91fdea7 100644 --- a/packages/chat/src/components/messages/Fork.tsx +++ b/packages/chat/src/components/messages/Fork.tsx @@ -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>; - timeoutRef: React.MutableRefObject; - 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 = ( - - - -); - -const PopoverButton: React.FC = ({ - children, - setting, - onClick, - setActiveSetting, - timeoutRef, - hoverInfo, - hoverTitle, - hoverDescription, - label, -}) => { - const localize = useLocalize(); - - return ( - -
- 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} - {label} - - } - /> - - - {localize('com_ui_fork_more_details_about', { 0: label })} - - {chevronDown} - - {((hoverInfo != null && hoverInfo !== '') || - (hoverTitle != null && hoverTitle !== '') || - (hoverDescription != null && hoverDescription !== '')) && ( - -
-

- {hoverInfo && hoverInfo} - {hoverTitle && {hoverTitle}} - {hoverDescription && hoverDescription} -

-
-
- )} -
-
- ); -}; - -interface CheckboxOptionProps { +interface CompactCheckboxProps { id: string; checked: boolean; onToggle: (checked: boolean) => void; - labelKey: TranslationKeys; - infoKey: TranslationKeys; - showToastOnCheck?: boolean; + label: string; } -const CheckboxOption: React.FC = ({ - id, - checked, - onToggle, - labelKey, - infoKey, - showToastOnCheck = false, -}) => { - const localize = useLocalize(); - const { showToast } = useToastContext(); - return ( - -
- - { - 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)} - /> - -
- } - /> - - {localize(infoKey)} - {chevronDown} - -
- -
-

{localize(infoKey)}

-
-
- - ); -}; + +const CompactCheckbox: React.FC = ({ id, checked, onToggle, label }) => ( +
+ onToggle(value === true)} + variant="fade" + aria-label={label} + /> + +
+); type ForkProps = { messageId: string; @@ -250,8 +86,18 @@ function Fork({ rememberOption: rememberGlobal, setRememberOption: setRememberGlobal, } = host.useForkPreferences(); - const timeoutRef = useRef(null); - const [activeSetting, setActiveSetting] = useState(optionLabel(ForkOptions.DEFAULT)); + const groupId = useId(); + const defaultMode = forkSetting || ForkOptions.TARGET_LEVEL; + const [selected, setSelected] = useState(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: