🤯 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(channel): keep the open settings tab in the URL (#21716)
Arvin Xu669d021c6818
diff --git a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx b/src/features/AgentChannel/PlatformDetail/index.save.test.tsxindex 9b8b77da884..2433c3d644b 100644--- a/src/features/AgentChannel/PlatformDetail/index.save.test.tsx+++ b/src/features/AgentChannel/PlatformDetail/index.save.test.tsx@@ -2,6 +2,7 @@* @vitest-environment happy-dom*/import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';+import { MemoryRouter } from 'react-router';import { beforeEach, describe, expect, it, vi } from 'vitest';import { schema as discordSchema } from '@/server/services/bot/platforms/discord/schema';@@ -90,7 +91,9 @@ describe('PlatformDetail saving', () => {});it('saves a reply setting by itself a moment after it changes, and writes nothing else', async () => {- render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />);+ render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />, {+ wrapper: MemoryRouter,+ });openTab(en['channel.tab.reply']);fireEvent.click(screen.getByRole('switch', { name: new RegExp(en['channel.showUsageStats']) }));@@ -116,6 +119,7 @@ describe('PlatformDetail saving', () => {settings: { ...config.settings, botWake: override, botWakeEnabled: true },}}/>,+ { wrapper: MemoryRouter },);openTab(en['channel.tab.reply']);@@ -128,7 +132,9 @@ describe('PlatformDetail saving', () => {});it('shows a Save in each wake block and none on the replies', () => {- render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />);+ render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />, {+ wrapper: MemoryRouter,+ });openTab(en['channel.tab.wake']);expect(screen.getAllByRole('button', { name: en['channel.module.save'] })).toHaveLength(4);@@ -138,7 +144,9 @@ describe('PlatformDetail saving', () => {});it('leaves the bottom bar to Remove and Test connection for a saved bot', () => {- render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />);+ render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />, {+ wrapper: MemoryRouter,+ });expect(screen.getByRole('button', { name: new RegExp(en['channel.removeChannel']) }),@@ -148,7 +156,9 @@ describe('PlatformDetail saving', () => {});it('saves only the block that was changed, and keeps another block’s unsaved edit', async () => {- render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />);+ render(<PlatformDetail agentId="agt" currentConfig={config} platformDef={platformDef} />, {+ wrapper: MemoryRouter,+ });openTab(en['channel.tab.wake']);// Edit the silent-wake limit (Pace) and the help-others sensitivity (Initiative).diff --git a/src/features/AgentChannel/PlatformDetail/index.tsx b/src/features/AgentChannel/PlatformDetail/index.tsxindex 16a1f2c2d4b..74e835d07f3 100644--- a/src/features/AgentChannel/PlatformDetail/index.tsx+++ b/src/features/AgentChannel/PlatformDetail/index.tsx@@ -16,6 +16,7 @@ import { useForm, useWatch } from '@lobehub/ui/form';import { ExternalLink, PanelRightClose, PanelRightOpen } from 'lucide-react';import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';+import { useSearchParams } from 'react-router';import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';@@ -247,9 +248,23 @@ const PlatformDetail = memo<PlatformDetailProps>(onValuesChange: () => valuesChangedRef.current?.(),});- // Which tab is open. `undefined` means nobody picked one, so the page picks:- // connecting for a new channel, the first settings tab once it is saved.- const [pickedTab, setPickedTab] = useState<ChannelTab>();+ // Which tab is open, kept in `?tab=` so a reload or a shared link lands on it. No value+ // means nobody picked one, so the page picks: connecting for a new channel, the first+ // settings tab once it is saved. Switching platforms changes the path and drops the query.+ const [searchParams, setSearchParams] = useSearchParams();+ const pickedTab = (searchParams.get('tab') ?? undefined) as ChannelTab | undefined;+ const setPickedTab = useCallback(+ (tab: ChannelTab) =>+ setSearchParams(+ (prev) => {+ const next = new URLSearchParams(prev);+ next.set('tab', tab);+ return next;+ },+ { replace: true },+ ),+ [setSearchParams],+ );const tabs = useMemo(() =>resolveTabs(@@ -431,7 +446,6 @@ const PlatformDetail = memo<PlatformDetailProps>(// runtimeStatus — otherwise background status refreshes would wipe// in-progress form edits and cancel the connect-status polling loop.useEffect(() => {- setPickedTab(undefined);setSaveResult(undefined);setConnectNotice(undefined);setRuntimeHidden(false);@@ -655,6 +669,7 @@ const PlatformDetail = memo<PlatformDetailProps>(updateBotProvider,connectCurrentBot,saveCoordinator,+ setPickedTab,tabs,writeDisabled,t,diff --git a/src/routes/(main)/agent/channel/permission.test.tsx b/src/routes/(main)/agent/channel/permission.test.tsxindex 0f74f8217b9..37c06e4f37a 100644--- a/src/routes/(main)/agent/channel/permission.test.tsx+++ b/src/routes/(main)/agent/channel/permission.test.tsx@@ -4,6 +4,7 @@import { useForm } from '@lobehub/ui/form';import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';import type { ReactNode } from 'react';+import { MemoryRouter, useLocation } from 'react-router';import { describe, expect, it, vi } from 'vitest';import PlatformDetail, { type ChannelFormValues } from '@/features/AgentChannel/PlatformDetail';@@ -268,6 +269,8 @@ const FooterHarness = ({ disabled }: { disabled?: boolean }) => {);};+const LocationProbe = () => <output data-testid="location">{useLocation().search}</output>;+// A saved bot folds its credentials away; open them the way a person would.const openCredentials = () => fireEvent.click(screen.getByText('channel.credentials'));@@ -321,6 +324,7 @@ describe('Agent channel permission gates', () => {it("speaks as the agent's name, not its role title", async () => {render(<PlatformDetail agentId="agent-id" currentConfig={currentConfig} platformDef={platformDef} />,+ { wrapper: MemoryRouter },);// The test window is narrow, so the preview opens from its button.@@ -333,6 +337,7 @@ describe('Agent channel permission gates', () => {it('discards form edits and restores the persisted configuration', async () => {render(<PlatformDetail agentId="agent-id" currentConfig={currentConfig} platformDef={platformDef} />,+ { wrapper: MemoryRouter },);// A saved bot opens on its first settings tab; the app ID lives on "connect".@@ -354,6 +359,32 @@ describe('Agent channel permission gates', () => {);}, 15_000);+ it('opens the tab named in the URL and writes the picked tab back to it', () => {+ render(+ <MemoryRouter initialEntries={['/agent/agent-id/channel/discord?tab=connect']}>+ <PlatformDetail+ agentId="agent-id"+ currentConfig={currentConfig}+ platformDef={platformDef}+ />+ <LocationProbe />+ </MemoryRouter>,+ );++ // A saved bot would open on access; the URL asks for connect.+ expect(screen.getByRole('tab', { name: 'channel.tab.connect' })).toHaveAttribute(+ 'aria-selected',+ 'true',+ );++ fireEvent.click(screen.getByRole('tab', { name: 'channel.tab.access' }));+ expect(screen.getByTestId('location')).toHaveTextContent('?tab=access');+ expect(screen.getByRole('tab', { name: 'channel.tab.access' })).toHaveAttribute(+ 'aria-selected',+ 'true',+ );+ });+it('disables the channel enable switch and status refresh when editing is denied', () => {render(<Header@@ -458,6 +489,7 @@ describe('Agent channel permission gates', () => {name: 'WeChat',}}/>,+ { wrapper: MemoryRouter },);const alert = screen.getByTestId('channel-paid-alert');@@ -481,6 +513,7 @@ describe('Agent channel permission gates', () => {name: 'WeChat',}}/>,+ { wrapper: MemoryRouter },);const title = screen.getByTestId('channel-paid-alert-title');@@ -510,6 +543,7 @@ describe('Agent channel permission gates', () => {name: 'WeChat',}}/>,+ { wrapper: MemoryRouter },);const title = screen.getByTestId('channel-paid-alert-title');