mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 15:33:45 +00:00
🧭 refactor: Move the Message Navigation Rail Into @librechat/chat (#17758)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
* refactor: Move the Message Navigation Rail Into @librechat/chat * refactor: Render the Message Navigation Rail From @librechat/chat * test: Cover the Navigation Rail Jumping Between a Thread's Ends
This commit is contained in:
parent
a3989d7b1b
commit
c4d5e44719
14 changed files with 165 additions and 62 deletions
|
|
@ -19,6 +19,7 @@ import {
|
|||
getMessageClipboardSource,
|
||||
useCopyMessageToClipboard,
|
||||
} from '~/hooks';
|
||||
import { useForkConvoMutation, useGetMessagesByConvoId } from '~/data-provider';
|
||||
import useConversationSeenSource from '~/hooks/Conversations/seenSource';
|
||||
import { useOptionalMessagesOperations } from './MessagesViewContext';
|
||||
import ThreadMessage from '~/components/Chat/Messages/Thread/Message';
|
||||
|
|
@ -27,7 +28,6 @@ import MessageIcon from '~/components/Chat/Messages/MessageIcon';
|
|||
import { useFileMapContext } from '~/Providers/FileMapContext';
|
||||
import Files from '~/components/Chat/Messages/Content/Files';
|
||||
import { useScreenshot } from '~/hooks/ScreenshotContext';
|
||||
import { useForkConvoMutation } from '~/data-provider';
|
||||
import useClockFormat from '~/hooks/useClockFormat';
|
||||
import { autoScrollAtom } from '~/store/autoScroll';
|
||||
import store from '~/store';
|
||||
|
|
@ -88,6 +88,17 @@ function useAppGetMessages(): () => TMessage[] | undefined {
|
|||
return useOptionalMessagesOperations().getMessages;
|
||||
}
|
||||
|
||||
function useAppConversationMessages(
|
||||
conversationId: string | null | undefined,
|
||||
isStreaming: boolean,
|
||||
): TMessage[] | undefined {
|
||||
return useGetMessagesByConvoId(
|
||||
conversationId ?? '',
|
||||
{ enabled: !!conversationId },
|
||||
{ isStreaming },
|
||||
).data;
|
||||
}
|
||||
|
||||
function useAppHasPendingTurn(conversationId: string): boolean {
|
||||
return useAtomValue(revealedQueuedTurnFamily(conversationId)) != null;
|
||||
}
|
||||
|
|
@ -114,6 +125,7 @@ export const appMessagesHost: MessagesHost = {
|
|||
useMessageCopy: useAppMessageCopy,
|
||||
useGetMessages: useAppGetMessages,
|
||||
useHasPendingTurn: useAppHasPendingTurn,
|
||||
useConversationMessages: useAppConversationMessages,
|
||||
renderMessageAudio: (props) => <AppMessageAudio {...props} />,
|
||||
useScreenshotTarget: () => useScreenshot().screenshotTargetRef,
|
||||
useAutoScroll: () => useAtomValue(autoScrollAtom),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { useChatSurface } from '@librechat/chat/react';
|
||||
import { MessagesView as MessagesList } from '@librechat/chat/components';
|
||||
import { MessageNav, MessagesView as MessagesList } from '@librechat/chat/components';
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
import { MessagePartsHostProvider, appMessagePartsHost } from '~/Providers/MessagePartsHostContext';
|
||||
import PendingSteers from './Content/Parts/PendingSteers';
|
||||
|
|
@ -7,7 +7,6 @@ import { MessagesViewProvider } from '~/Providers';
|
|||
import ScrollButton from './ScrollButton';
|
||||
import PendingTurn from './PendingTurn';
|
||||
import { FLAT_THREAD } from './Thread';
|
||||
import MessageNav from './MessageNav';
|
||||
|
||||
function MessagesViewContent({
|
||||
messagesTree,
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ jest.mock('../ScrollButton', () => ({
|
|||
__esModule: true,
|
||||
default: () => null,
|
||||
}));
|
||||
jest.mock('../MessageNav', () => {
|
||||
jest.mock('@librechat/chat/components', () => {
|
||||
const { useEffect } = jest.requireActual('react');
|
||||
return {
|
||||
__esModule: true,
|
||||
default: function MessageNav({ conversationId }: { conversationId?: string | null }) {
|
||||
...jest.requireActual('@librechat/chat/components'),
|
||||
MessageNav: function MessageNav({ conversationId }: { conversationId?: string | null }) {
|
||||
useEffect(() => {
|
||||
mockNavMount();
|
||||
return () => mockNavUnmount();
|
||||
|
|
@ -96,6 +96,7 @@ const host: MessagesHost = {
|
|||
renderMessageAudio: () => null,
|
||||
useScreenshotTarget: () => undefined,
|
||||
useAutoScroll: () => false,
|
||||
useConversationMessages: () => undefined,
|
||||
useSeenSource: () => ({
|
||||
readReply: () => undefined,
|
||||
hasReplyProof: () => false,
|
||||
|
|
|
|||
|
|
@ -130,4 +130,31 @@ test.describe('long conversations', () => {
|
|||
await expect(reply).toBeInViewport();
|
||||
await expect(first).not.toBeInViewport();
|
||||
});
|
||||
|
||||
test.describe('on a desktop viewport, where the navigation rail shows', () => {
|
||||
test.use({ viewport: { width: 1280, height: 800 }, isMobile: false, hasTouch: false });
|
||||
|
||||
test('the navigation rail jumps to the first turn and back to the latest @scenario:message-nav-jumps-between-ends', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`/c/${conversationId}`);
|
||||
|
||||
const thread = page.locator(`[data-conversation-id="${conversationId}"]`);
|
||||
await expect(thread.locator('.message-render')).toHaveCount(TURNS);
|
||||
const first = thread.getByText('Turn 1 of the long conversation', { exact: true });
|
||||
const latest = thread.getByText(`Turn ${TURNS} of the long conversation`, { exact: true });
|
||||
await expect(latest).toBeInViewport();
|
||||
|
||||
const rail = page.getByRole('navigation', { name: 'Message navigation' });
|
||||
await expect(rail.getByRole('button', { name: 'Navigate to next message' })).toBeDisabled();
|
||||
await rail.getByRole('button', { name: 'Scroll to top' }).click();
|
||||
await expect(first).toBeInViewport();
|
||||
await expect(
|
||||
rail.getByRole('button', { name: 'Navigate to previous message' }),
|
||||
).toBeDisabled();
|
||||
|
||||
await rail.getByRole('button', { name: 'Scroll to bottom' }).click();
|
||||
await expect(latest).toBeInViewport();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -381,14 +381,6 @@
|
|||
"count": 1
|
||||
}
|
||||
},
|
||||
"client/src/components/Chat/Messages/MessageNav.tsx": {
|
||||
"design/disabled-recipe": {
|
||||
"count": 1
|
||||
},
|
||||
"shadcn/no-arbitrary-values": {
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"client/src/components/Chat/ProjectLandingChip.tsx": {
|
||||
"shadcn/no-restyle": {
|
||||
"count": 14
|
||||
|
|
@ -1356,6 +1348,11 @@
|
|||
"count": 1
|
||||
}
|
||||
},
|
||||
"packages/chat/src/components/messages/MessageNav.tsx": {
|
||||
"design/disabled-recipe": {
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"packages/chat/src/components/messages/MessageRow.tsx": {
|
||||
"shadcn/no-arbitrary-values": {
|
||||
"count": 1
|
||||
|
|
|
|||
44
packages/chat/src/__fixtures__/chat.ts
Normal file
44
packages/chat/src/__fixtures__/chat.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import type { ChatContract } from '../react/chat/contract';
|
||||
|
||||
const noop = (): void => undefined;
|
||||
|
||||
/** A pane's chat contract with inert members: no conversation, nothing in flight, no files.
|
||||
* Specs override the members the component under test reads. */
|
||||
export function createChatContract(overrides: Partial<ChatContract> = {}): ChatContract {
|
||||
return {
|
||||
index: 0,
|
||||
conversation: null,
|
||||
setConversation: noop,
|
||||
newConversation: noop,
|
||||
preset: null,
|
||||
setPreset: noop,
|
||||
optionSettings: {},
|
||||
setOptionSettings: noop,
|
||||
getMessages: () => undefined,
|
||||
messagesKey: '',
|
||||
setMessages: noop,
|
||||
subscribeMessages: () => noop,
|
||||
getMessagesRevision: () => 0,
|
||||
setSiblingIdx: noop,
|
||||
latestMessageId: undefined,
|
||||
latestMessageDepth: undefined,
|
||||
useLiveAttachments: () => ({}),
|
||||
ask: noop,
|
||||
regenerate: noop,
|
||||
isSubmitting: false,
|
||||
setIsSubmitting: noop,
|
||||
handleRegenerate: noop,
|
||||
handleContinue: noop,
|
||||
stopGenerating: () => Promise.resolve(),
|
||||
handleStopGenerating: noop,
|
||||
abortScroll: false,
|
||||
setAbortScroll: noop,
|
||||
files: new Map(),
|
||||
setFiles: noop,
|
||||
filesLoading: false,
|
||||
setFilesLoading: noop,
|
||||
feedbackEnabled: false,
|
||||
getMappingOptions: () => ({}),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ export function createMessagesHost(overrides: Partial<MessagesHost> = {}): Messa
|
|||
renderMessageAudio: () => null,
|
||||
useScreenshotTarget: () => undefined,
|
||||
useAutoScroll: () => false,
|
||||
useConversationMessages: () => undefined,
|
||||
useSeenSource: () => ({
|
||||
readReply: () => undefined,
|
||||
hasReplyProof: () => false,
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ export { default as HoverButtons } from './components/messages/HoverButtons';
|
|||
export { default as ContentRow } from './components/messages/ContentRow';
|
||||
export type { ContentRowProps } from './components/messages/ContentRow';
|
||||
export { default as MessageFooter } from './components/messages/MessageFooter';
|
||||
export { default as MessageNav } from './components/messages/MessageNav';
|
||||
export type { MessageFooterProps } from './components/messages/MessageFooter';
|
||||
export { getMessageAriaLabel, getHeaderPrefixForScreenReader } from './components/messages/labels';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
import { memo, useState, useEffect, useCallback, useRef, useMemo } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { parseWakeupMessage } from '@librechat/chat';
|
||||
import { ChevronUp, ChevronDown } from 'lucide-react';
|
||||
import { ContentTypes } from 'librechat-data-provider';
|
||||
import { pxToRem, useRemScale } from '@librechat/client';
|
||||
import { cn, pxToRem, useLocalize, useRemScale } from '@librechat/client';
|
||||
import type { TMessage, TMessageContentParts } from 'librechat-data-provider';
|
||||
import type { TranslationKeys } from '~/hooks';
|
||||
import { useMessagesConversation, useMessagesSubmission } from '~/Providers';
|
||||
import { useGetMessagesByConvoId } from '~/data-provider';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
import type { TranslationKeys } from '@librechat/client';
|
||||
import { parseWakeupMessage } from '../../core/parts/wakeup';
|
||||
import { useMessagesHost } from '../../react/messages/host';
|
||||
import { useChatContext } from '../../react/chat/context';
|
||||
|
||||
type MessageEntry = {
|
||||
id: string;
|
||||
|
|
@ -245,7 +243,7 @@ function entryTop(el: HTMLElement, container: HTMLElement): number {
|
|||
let node: Element | null = el;
|
||||
while (node instanceof HTMLElement) {
|
||||
top += node.offsetTop;
|
||||
const parent = node.offsetParent;
|
||||
const parent: Element | null = node.offsetParent;
|
||||
if (!(parent instanceof HTMLElement) || parent === container || !container.contains(parent)) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -293,10 +291,10 @@ export function magnifyFalloff(distance: number, influence: number): number {
|
|||
* without it every row compresses to its content the moment the rail overflows —
|
||||
* halving the hit target of every rib in exactly the long conversations the rail
|
||||
* exists to navigate. */
|
||||
const indicatorButtonClasses = cn(
|
||||
const indicatorButtonClasses = [
|
||||
'flex w-full shrink-0 items-center justify-end rounded-sm transition-opacity duration-300',
|
||||
'focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-border-xheavy',
|
||||
);
|
||||
].join(' ');
|
||||
|
||||
const dimIndicatorClasses =
|
||||
'opacity-40 high-contrast:opacity-50 group-hover/nav:opacity-100 group-focus-within/nav:opacity-100';
|
||||
|
|
@ -358,14 +356,14 @@ const MessageIndicator = memo(function MessageIndicator({
|
|||
);
|
||||
});
|
||||
|
||||
const chevronButtonClasses = cn(
|
||||
const chevronButtonClasses = [
|
||||
'-me-1 rounded-md p-0.5 text-text-tertiary opacity-40 transition-[color,opacity] duration-300 high-contrast:opacity-50',
|
||||
'group-hover/nav:text-text-secondary group-hover/nav:opacity-100',
|
||||
'group-focus-within/nav:text-text-secondary group-focus-within/nav:opacity-100',
|
||||
'group-hover/nav:hover:text-text-primary',
|
||||
'group-hover/nav:disabled:opacity-30 group-focus-within/nav:disabled:opacity-30',
|
||||
'focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-border-xheavy',
|
||||
);
|
||||
].join(' ');
|
||||
|
||||
function MessageNav({
|
||||
scrollableRef,
|
||||
|
|
@ -373,18 +371,11 @@ function MessageNav({
|
|||
}: {
|
||||
scrollableRef: React.RefObject<HTMLDivElement>;
|
||||
conversationId?: string | null;
|
||||
}) {
|
||||
}): React.JSX.Element | null {
|
||||
const localize = useLocalize();
|
||||
const { conversationId: contextConversationId } = useMessagesConversation();
|
||||
const conversationId = renderedConversationId ?? contextConversationId;
|
||||
const { isSubmitting } = useMessagesSubmission();
|
||||
const { data: messages } = useGetMessagesByConvoId(
|
||||
conversationId ?? '',
|
||||
{
|
||||
enabled: !!conversationId,
|
||||
},
|
||||
{ isStreaming: isSubmitting },
|
||||
);
|
||||
const { conversation, isSubmitting } = useChatContext();
|
||||
const conversationId = renderedConversationId ?? conversation?.conversationId;
|
||||
const messages = useMessagesHost().useConversationMessages(conversationId, isSubmitting);
|
||||
const messagesById = useMemo(() => {
|
||||
const map = new Map<string, TMessage>();
|
||||
if (messages) {
|
||||
|
|
@ -1753,4 +1744,6 @@ function MessageNav({
|
|||
);
|
||||
}
|
||||
|
||||
export default memo(MessageNav);
|
||||
const MemoizedMessageNav: ReturnType<typeof memo<typeof MessageNav>> = memo(MessageNav);
|
||||
|
||||
export default MemoizedMessageNav;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/** @jest-environment jsdom */
|
||||
import React from 'react';
|
||||
import { render, act, fireEvent, screen } from '@testing-library/react';
|
||||
|
||||
type ReactNode = React.ReactNode;
|
||||
type RefObject<T> = React.RefObject<T>;
|
||||
|
||||
type TestMessage = {
|
||||
|
|
@ -23,35 +23,23 @@ const mockUseMessagesConversation = jest.fn();
|
|||
const mockUseMessagesSubmission = jest.fn();
|
||||
let mockRemScale = 1;
|
||||
|
||||
jest.mock('~/data-provider', () => ({
|
||||
useGetMessagesByConvoId: (...args: unknown[]) => mockUseGetMessagesByConvoId(...args),
|
||||
}));
|
||||
|
||||
jest.mock('~/Providers', () => ({
|
||||
useMessagesConversation: (...args: unknown[]) => mockUseMessagesConversation(...args),
|
||||
useMessagesSubmission: (...args: unknown[]) => mockUseMessagesSubmission(...args),
|
||||
}));
|
||||
|
||||
jest.mock('~/hooks', () => ({
|
||||
jest.mock('@librechat/client', () => ({
|
||||
...jest.requireActual('@librechat/client'),
|
||||
useLocalize:
|
||||
() =>
|
||||
(key: string, opts?: Record<string, string | number>): string =>
|
||||
opts ? `${key}|${JSON.stringify(opts)}` : key,
|
||||
}));
|
||||
|
||||
// The nav no longer renders HoverCard, but `~/utils` transitively imports the
|
||||
// dual CJS/ESM @librechat/client whose dist pulls ESM-only @ariakit subpaths
|
||||
// that jest cannot resolve. Stub the module so the unit under test stays isolated.
|
||||
jest.mock('@librechat/client', () => ({
|
||||
HoverCard: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
HoverCardTrigger: ({ children, asChild }: { children: ReactNode; asChild?: boolean }) =>
|
||||
asChild ? children : <div>{children}</div>,
|
||||
HoverCardPortal: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
HoverCardContent: ({ children }: { children: ReactNode }) => <div>{children}</div>,
|
||||
pxToRem: jest.requireActual('../../../../../../packages/client/src/utils/theme').pxToRem,
|
||||
useRemScale: () => mockRemScale,
|
||||
}));
|
||||
|
||||
if (typeof window.ResizeObserver !== 'function') {
|
||||
window.ResizeObserver = class {
|
||||
observe(): void {}
|
||||
unobserve(): void {}
|
||||
disconnect(): void {}
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof window.matchMedia !== 'function') {
|
||||
window.matchMedia = (query: string) =>
|
||||
({
|
||||
|
|
@ -127,7 +115,8 @@ if (typeof (global as { PointerEvent?: unknown }).PointerEvent === 'undefined')
|
|||
}
|
||||
|
||||
import type { TMessage } from 'librechat-data-provider';
|
||||
import MessageNav, {
|
||||
import { createChatContract } from '../../../__fixtures__/chat';
|
||||
import RealMessageNav, {
|
||||
buildEntry,
|
||||
previewTextFor,
|
||||
buildSteerEntry,
|
||||
|
|
@ -135,6 +124,36 @@ import MessageNav, {
|
|||
magnifyFalloff,
|
||||
ribDimsFor,
|
||||
} from '../MessageNav';
|
||||
import { createMessagesHost } from '../../../__fixtures__/messagesHost';
|
||||
import { MessagesHostProvider } from '../../../react/messages/host';
|
||||
import { ChatContext } from '../../../react/chat/context';
|
||||
|
||||
const host = createMessagesHost({
|
||||
useConversationMessages: (conversationId, isStreaming) =>
|
||||
mockUseGetMessagesByConvoId(
|
||||
conversationId ?? '',
|
||||
{ enabled: !!conversationId },
|
||||
{ isStreaming },
|
||||
).data,
|
||||
});
|
||||
|
||||
/** Renders the rail inside the chat and messages hosts, reading the mocked conversation and
|
||||
* submission state on every render so a spec can change them between renders. */
|
||||
function MessageNav(props: React.ComponentProps<typeof RealMessageNav>): React.JSX.Element {
|
||||
const { conversationId } = mockUseMessagesConversation();
|
||||
const { isSubmitting } = mockUseMessagesSubmission();
|
||||
const chat = createChatContract({
|
||||
isSubmitting,
|
||||
conversation: { conversationId, endpoint: null, title: null, createdAt: '', updatedAt: '' },
|
||||
});
|
||||
return (
|
||||
<ChatContext.Provider value={chat}>
|
||||
<MessagesHostProvider host={host}>
|
||||
<RealMessageNav {...props} />
|
||||
</MessagesHostProvider>
|
||||
</ChatContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function buildMessage(overrides: Partial<TestMessage> = {}): TestMessage {
|
||||
return {
|
||||
|
|
@ -40,6 +40,7 @@ function createHost(overrides: Partial<MessagesHost> = {}) {
|
|||
const host = createMessagesHost({
|
||||
useScreenshotTarget: () => useRef<HTMLDivElement>(null),
|
||||
useAutoScroll: () => false,
|
||||
useConversationMessages: () => undefined,
|
||||
useSeenSource: () => source,
|
||||
...overrides,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ const host: MessagesHost = {
|
|||
renderMessageAudio: () => null,
|
||||
useScreenshotTarget: () => undefined,
|
||||
useAutoScroll: () => false,
|
||||
useConversationMessages: () => undefined,
|
||||
useSeenSource: () => ({
|
||||
readReply: () => undefined,
|
||||
hasReplyProof: () => false,
|
||||
|
|
|
|||
|
|
@ -175,6 +175,11 @@ export interface MessagesHost {
|
|||
useAutoScroll: () => boolean;
|
||||
/** The read-state storage the list marks a conversation seen through. */
|
||||
useSeenSource: () => ConversationSeenSource;
|
||||
/** The conversation's cached messages, refreshed as they stream when isStreaming is set; undefined until loaded or without a conversation. */
|
||||
useConversationMessages: (
|
||||
conversationId: string | null | undefined,
|
||||
isStreaming: boolean,
|
||||
) => TMessage[] | undefined;
|
||||
|
||||
/** Renders a message author's icon with the app's endpoint and avatar icons. */
|
||||
renderMessageIcon: (props: MessageIconProps) => ReactNode;
|
||||
|
|
@ -223,6 +228,7 @@ const fallbackHost: MessagesHost = {
|
|||
useScreenshotTarget: () => useRef<HTMLDivElement>(null),
|
||||
useAutoScroll: () => false,
|
||||
useSeenSource: () => inertSeenSource,
|
||||
useConversationMessages: () => undefined,
|
||||
renderMessageIcon: () => null,
|
||||
renderMessageRow: () => null,
|
||||
renderActivity: () => null,
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@ const messagesHost: MessagesHost = {
|
|||
renderMessageAudio: () => null,
|
||||
useScreenshotTarget: () => undefined,
|
||||
useAutoScroll: () => false,
|
||||
useConversationMessages: () => undefined,
|
||||
useSeenSource: () => ({
|
||||
readReply: () => undefined,
|
||||
hasReplyProof: () => false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue