🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(entity-link): open an acceptance in the browser from its hover card (#21966)
Rdmclin239a3cde713b8
diff --git a/src/features/EntityLink/Render/InternalEntityPreview.tsx b/src/features/EntityLink/Render/InternalEntityPreview.tsxindex a6777d2b6d6..ff4fdbecbef 100644--- a/src/features/EntityLink/Render/InternalEntityPreview.tsx+++ b/src/features/EntityLink/Render/InternalEntityPreview.tsx@@ -1,27 +1,41 @@'use client';import type { VerifyCodingScope } from '@lobechat/types';-import { Avatar, createStaticStyles, Flexbox, Freeze, Icon, Popover, Text } from '@lobehub/ui';+import {+ ActionIcon,+ Avatar,+ createStaticStyles,+ Flexbox,+ Freeze,+ Icon,+ Popover,+ Text,+} from '@lobehub/ui';import type { TFunction } from 'i18next';import {BadgeCheckIcon,BotIcon,CheckCircleIcon,CheckSquareIcon,+ ExternalLink,FileTextIcon,TargetIcon,} from 'lucide-react';import { memo, type PropsWithChildren, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';import { ArticleSkeleton } from '@/components/Skeleton';import { goalStatusKey } from '@/features/AgentGoals/goalPresentation';+import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';+import { useAppOrigin } from '@/hooks/useAppOrigin';import { useClientDataSWR } from '@/libs/swr';import { agentService } from '@/services/agent';import { documentService } from '@/services/document';import { goalService } from '@/services/goal';import { taskService } from '@/services/task';import { verifyService } from '@/services/verify';+import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';import type { InternalLinkReference } from '../internalLink';@@ -231,7 +245,17 @@ interface InternalEntityPreviewProps extends PropsWithChildren {export const InternalEntityPreview = memo<InternalEntityPreviewProps>(({ children, fallbackTitle, reference }) => {const { t } = useTranslation('chat');+ const { t: tVerify } = useTranslation('verify');const [open, setOpen] = useState(false);+ const appOrigin = useAppOrigin();+ const activeWorkspaceSlug = useActiveWorkspaceSlug();+ // A click on the link opens the acceptance in the side panel; this is the+ // explicit way out to a full browser page. Without an origin the URL would+ // be relative, which the desktop system browser cannot resolve.+ const browserUrl =+ reference.type === 'acceptance' && appOrigin+ ? `${appOrigin}${buildWorkspaceAwarePath(reference.pathname, activeWorkspaceSlug)}`+ : undefined;const { data, isLoading } = useClientDataSWR(open ? internalEntityPreviewKey(reference) : null,() => getPreviewData(reference, t),@@ -275,6 +299,14 @@ export const InternalEntityPreview = memo<InternalEntityPreviewProps>(<span className={styles.type}>{typeLabel}</span><span className={styles.title}>{data?.title || fallbackTitle}</span></Flexbox>+ {browserUrl && (+ <ActionIcon+ icon={ExternalLink}+ size={'small'}+ title={tVerify('report.actions.openInBrowser')}+ onClick={() => openTrustedExternalUrl(browserUrl)}+ />+ )}</Flexbox>{data?.description && (<Text className={styles.description} fontSize={13}>diff --git a/src/features/EntityLink/Render/index.test.tsx b/src/features/EntityLink/Render/index.test.tsxindex be584090b33..65648dca19f 100644--- a/src/features/EntityLink/Render/index.test.tsx+++ b/src/features/EntityLink/Render/index.test.tsx@@ -122,6 +122,18 @@ vi.mock('@/store/user/selectors', () => ({},}));+const mockOpenTrustedExternalUrl = vi.fn();++vi.mock('@/utils/openTrustedExternalUrl', () => ({+ openTrustedExternalUrl: (url: string) => mockOpenTrustedExternalUrl(url),+}));++let mockAppOrigin = 'https://app.lobehub.com';++vi.mock('@/hooks/useAppOrigin', () => ({+ useAppOrigin: () => mockAppOrigin,+}));+vi.mock('@/store/global', () => ({useGlobalStore: (selector: (s: unknown) => unknown) =>selector({ openInBrowserTab: mockOpenInBrowserTab }),@@ -148,6 +160,7 @@ afterEach(() => {mockShowIcon = true;mockConst.isDesktop = false;mockEntityPreview = null;+ mockAppOrigin = 'https://app.lobehub.com';vi.restoreAllMocks();});@@ -260,6 +273,49 @@ describe('Link Render — internal entities', () => {expect(getByText('Updated acceptance')).toBeInTheDocument();});+ it('opens an acceptance in the browser from its preview, not the side panel', () => {+ // A click on the link itself opens the side panel; the preview offers the+ // full page as an explicit alternative, as an absolute URL so the desktop+ // system browser can resolve it.+ mockEntityPreview = { title: 'Workspace publishing' };+ const { container, getByRole } = renderLink({+ linkHref: '/acceptance/acceptance-1',+ linkKind: 'generic',+ linkLabel: 'Acceptance',+ });+ fireEvent.mouseEnter(container.firstElementChild!);++ fireEvent.click(getByRole('button', { name: 'report.actions.openInBrowser' }));++ expect(mockOpenTrustedExternalUrl).toHaveBeenCalledWith(+ 'https://app.lobehub.com/acceptance/acceptance-1',+ );+ expect(mockOpenAcceptance).not.toHaveBeenCalled();+ });++ it('offers no browser action without an app origin to resolve against', () => {+ mockAppOrigin = '';+ const { container, queryByRole } = renderLink({+ linkHref: '/acceptance/acceptance-1',+ linkKind: 'generic',+ linkLabel: 'Acceptance',+ });+ fireEvent.mouseEnter(container.firstElementChild!);++ expect(queryByRole('button', { name: 'report.actions.openInBrowser' })).toBeNull();+ });++ it('keeps the browser action off previews of other entities', () => {+ const { container, queryByRole } = renderLink({+ linkHref: '/task/T-198',+ linkKind: 'generic',+ linkLabel: 'Task',+ });+ fireEvent.mouseEnter(container.firstElementChild!);++ expect(queryByRole('button', { name: 'report.actions.openInBrowser' })).toBeNull();+ });+it('replaces a pasted URL label with the resolved entity title', () => {// A raw acceptance URL says nothing about what it points to; once the// entity resolves, the link reads as its title.