Repository navigation
feat(chat): chat videos open from their card instead of growing the answer CU-17tkuw61kfy #2870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a3519f1
feat(chat): CU-17tkuw61kfy chat videos open from their card instead o…
michaelassraf b6cc660
feat(chat): CU-17tkuw61kfy card footers and source strips keep their …
michaelassraf facc207
fix(chat): CU-17tkuw61kfy the sources strip's skeleton is one row, on…
michaelassraf c56da62
feat(chat): CU-17tkuw61kfy a link to a screen of the app is an inline…
michaelassraf eb0d984
refactor(chat): CU-17tkuw61kfy one inline box component, InlineChip
michaelassraf 556d341
refactor(chat): CU-17tkuw61kfy one card disclosure, an explicit app-s…
michaelassraf 120f283
refactor(chat): CU-17tkuw61kfy in-app links by the runtime's rule, di…
michaelassraf 09cc3c9
Merge branch 'main' into feat/mcp-in-app-links
michaelassraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
openframe-frontend-core/src/components/chat/__tests__/inline-app-link-chip.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import type React from 'react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { InlineAppLinkChip, isInAppPath } from '../inline-app-link-chip'; | ||
|
|
||
| function HostAnchor({ href, className, children }: { href: string; className?: string; children?: React.ReactNode }) { | ||
| return ( | ||
| <a href={href} className={className} data-testid="host-anchor"> | ||
| {children} | ||
| </a> | ||
| ); | ||
| } | ||
|
|
||
| describe('a link to a screen of the app is an inline box', () => { | ||
| it('counts only root-relative paths as screens of the app', () => { | ||
| expect(isInAppPath('/devices/new')).toBe(true); | ||
| expect(isInAppPath('//evil.example/x')).toBe(false); | ||
| expect(isInAppPath('https://openframe.ai/devices')).toBe(false); | ||
| expect(isInAppPath('#section')).toBe(false); | ||
| expect(isInAppPath(undefined)).toBe(false); | ||
| }); | ||
|
|
||
| it('draws the label in the boxed chip, through the host anchor', () => { | ||
| render( | ||
| <InlineAppLinkChip href="/devices/new" anchor={HostAnchor}> | ||
| Devices → Add Device | ||
| </InlineAppLinkChip>, | ||
| ); | ||
| const link = screen.getByRole('link', { name: /Devices → Add Device/ }); | ||
| expect(link).toHaveAttribute('href', '/devices/new'); | ||
| expect(link).toHaveAttribute('data-testid', 'host-anchor'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ontend-core/src/components/chat/entity-cards/__tests__/chat-video-toggle-loading.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import type { ChatRef } from '../../chat-ref.types'; | ||
| import { SourceActionButton } from '../../source-action-button'; | ||
| import { ChatVideoToggleButton, useChatVideoToggle, WATCH_VIDEO_LABEL } from '../chat-video-toggle'; | ||
|
|
||
| const ref = { type: 'webinar', id: 'w1', title: 'A webinar' } as ChatRef; | ||
|
|
||
| function Footer({ video, reserve }: { video: ChatRef | null; reserve?: boolean }) { | ||
| const { action } = useChatVideoToggle(video, { reserve }); | ||
| return <div data-testid="row">{action}</div>; | ||
| } | ||
|
|
||
| describe('the card footer keeps its actions in place while loading', () => { | ||
| it('draws "Watch video" in its loading form: the label held as a skeleton bar, not a reachable button', () => { | ||
| render(<ChatVideoToggleButton loading />); | ||
| expect(screen.getByText(WATCH_VIDEO_LABEL)).toHaveAttribute('aria-hidden', 'true'); | ||
| expect(screen.queryByRole('button')).toBeNull(); | ||
| }); | ||
|
|
||
| it('keeps the slot, unseen, for a record of a video type that has no video', () => { | ||
| render(<Footer video={null} reserve />); | ||
| // The action is laid out (its space is kept) but cannot be reached or read. | ||
| expect(screen.getByText(WATCH_VIDEO_LABEL)).toBeTruthy(); | ||
| expect(screen.queryByRole('button')).toBeNull(); | ||
| }); | ||
|
|
||
| it('draws nothing for a type that cannot carry a video', () => { | ||
| render(<Footer video={null} />); | ||
| expect(screen.getByTestId('row')).toBeEmptyDOMElement(); | ||
| }); | ||
|
|
||
| it('draws the live action when the record has a video', () => { | ||
| render(<Footer video={ref} reserve />); | ||
| expect(screen.getByRole('button', { name: `${WATCH_VIDEO_LABEL}: A webinar` })).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('draws Ask in its loading form with the same label width', () => { | ||
| render(<SourceActionButton chatRef={ref} onDiscuss={() => undefined} density="card" loading />); | ||
| expect(screen.queryByRole('button')).toBeNull(); | ||
| expect(screen.getByText('Ask')).toHaveAttribute('aria-hidden', 'true'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
openframe-frontend-core/src/components/chat/entity-cards/chat-video-toggle.tsx
|
michaelassraf marked this conversation as resolved.
Resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| 'use client'; | ||
|
|
||
| /** | ||
| * A chat video opens from its card, never on its own. | ||
| * | ||
| * The player used to be drawn the moment its card resolved: a 16:9 box (plus | ||
| * its tab row) appeared under a card whose skeleton was one row tall, and an | ||
| * answer with three recordings grew by three players while it was being read | ||
| * (CU-17tkuw61kfy). Now the card shows a "Watch video" action in the row it | ||
| * already draws, so the answer keeps its height when it loads, and the player | ||
| * opens below the card only when the reader asks for it. A height change the | ||
| * reader asked for is not a layout shift. | ||
| * | ||
| * Two shapes, one state: | ||
| * - `useChatVideoToggle` for a card with a footer row (the action goes in the | ||
| * row, the player below the card); | ||
| * - `ChatCollapsibleVideo` for a video with no card of its own (a | ||
| * `[card://video:<id>]` marker): the same action on a row of its own. | ||
| * | ||
| * The action's space never changes. A card type whose records can carry a video | ||
| * (`video` on its registry entry) draws the action in its skeleton | ||
| * (`ChatVideoToggleButton loading`), and a record of that type with no video | ||
| * keeps the slot, unseen (`useChatVideoToggle(null, { reserve: true })`), so the | ||
| * row is the same height loading, loaded with a video and loaded without one. | ||
| */ | ||
|
|
||
| import type React from 'react'; | ||
| import { type ReactNode, useState } from 'react'; | ||
| import { PlayIcon } from '../../icons-v2-generated/media-playback/play-icon'; | ||
| import { Button } from '../../ui/button'; | ||
| import type { ChatRef } from '../chat-ref.types'; | ||
| import { CARD_FOOTER_ACTION_CLASS, FooterActionSkeleton } from '../source-action-button'; | ||
| import { ChatVideoEntityCard } from './chat-video-entity-card'; | ||
|
|
||
| export const WATCH_VIDEO_LABEL = 'Watch video'; | ||
| export const HIDE_VIDEO_LABEL = 'Hide video'; | ||
|
|
||
| export function ChatVideoToggleButton({ | ||
| open = false, | ||
| onToggle, | ||
| title, | ||
| loading, | ||
| }: { | ||
| open?: boolean; | ||
| onToggle?: () => void; | ||
| title?: string; | ||
| /** The action's loading form, drawn in the skeleton of a card that can carry a video. */ | ||
| loading?: boolean; | ||
| }): React.ReactElement { | ||
| if (loading) return <FooterActionSkeleton label={WATCH_VIDEO_LABEL} className={CARD_FOOTER_ACTION_CLASS} />; | ||
| const label = open ? HIDE_VIDEO_LABEL : WATCH_VIDEO_LABEL; | ||
| return ( | ||
| <Button | ||
| variant="transparent" | ||
| size="small" | ||
| leftIcon={<PlayIcon className="!h-3 !w-3" />} | ||
| onClick={(e: React.MouseEvent) => { | ||
| // The card around it is a link: the action must not follow it. | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| onToggle?.(); | ||
| }} | ||
| aria-expanded={open} | ||
| aria-label={title ? `${label}: ${title}` : label} | ||
| className={CARD_FOOTER_ACTION_CLASS} | ||
| > | ||
| {label} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The action for a card's footer row, and the player to draw below the card (null while closed). With no video, | ||
| * `reserve` keeps the action's slot, unseen and unreachable, for a card type whose records can carry one. | ||
| */ | ||
| export function useChatVideoToggle( | ||
| video: ChatRef | null, | ||
| { reserve = false }: { reserve?: boolean } = {}, | ||
| ): { action: ReactNode; player: ReactNode } { | ||
| const [open, setOpen] = useState(false); | ||
| if (!video) { | ||
| return { | ||
| action: reserve ? ( | ||
| <span aria-hidden inert className="invisible"> | ||
| <ChatVideoToggleButton /> | ||
| </span> | ||
| ) : null, | ||
| player: null, | ||
| }; | ||
| } | ||
| return { | ||
| action: <ChatVideoToggleButton open={open} onToggle={() => setOpen(o => !o)} title={video.title} />, | ||
| player: open ? <ChatVideoEntityCard chatRef={video} /> : null, | ||
| }; | ||
| } | ||
|
|
||
| /** A video with no card of its own: the action on its own row, the player below it once opened. */ | ||
| export function ChatCollapsibleVideo({ chatRef }: { chatRef: ChatRef }): React.ReactElement { | ||
| const { action, player } = useChatVideoToggle(chatRef); | ||
| return ( | ||
| <div className="grid min-w-0 grid-cols-1 gap-3"> | ||
| <div className="flex items-center gap-2 pl-0.5"> | ||
| {action} | ||
| <span className="min-w-0 truncate text-ods-text-secondary text-h6">{chatRef.title}</span> | ||
| </div> | ||
| {player} | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.