mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(sessions): move the session picker into the desktop right tool panel
Replace the tool rail's Activity tool with a Sessions tool that renders the full session picker (Activity, This project and Projects tabs, linked-server selector, add repository), shared with the mobile sheet via RouteSessionPicker. - A docked panel stays open and follows navigation (picker navigation mode 'panel'); the floating overlay closes on select (mode 'replace'). - The session page's sessions shortcut and /sessions open the panel; the collapsed sidebar opens it when a tool rail is mounted and falls back to the modal dialog otherwise. - useToolPanelToggle is the single panel toggle for the rail, shortcuts and sidebar. - Remove ActivityList, the fixed activity panel width and the window label.
This commit is contained in:
1 parent
82c46bbdb2
commit
d26ab578f0
25 files changed
+639
-695
No files matched your search
@@ -12,11 +12,8 @@ import { useSettingsDialog } from '@/hooks/useSettingsDialog'
|
||||
import { useSidebarCollapsed } from '@/hooks/useSidebarCollapsed'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import {
|
||||
clearToolPanelParams,
|
||||
panelToolParam,
|
||||
resolveToolPanelToggle,
|
||||
toggleToolDialogParams,
|
||||
toggleToolPanelParams,
|
||||
useToolPanelToggle,
|
||||
type PanelTool,
|
||||
} from '@/hooks/useToolPanel'
|
||||
import { isLocalOpenCodeServer, useRouteOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
@@ -37,7 +34,7 @@ import {
|
||||
export function useGlobalShortcutActions(): void {
|
||||
const { pathname } = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const { searchParams, updateParams, closePushedParams } = useUrlParams()
|
||||
const { updateParams } = useUrlParams()
|
||||
const { open: openSettings } = useSettingsDialog()
|
||||
const isMobile = useMobile()
|
||||
const serverId = useRouteOpenCodeServerId()
|
||||
@@ -67,6 +64,7 @@ export function useGlobalShortcutActions(): void {
|
||||
|
||||
const toolItems = useMemo(() => buildToolItems(pathname), [pathname])
|
||||
const [, toggleSidebarCollapsed] = useSidebarCollapsed()
|
||||
const togglePanelTool = useToolPanelToggle()
|
||||
|
||||
const toggleRouteTool = useCallback((tool: PanelTool) => {
|
||||
if (toolItems.some((item) => toolKeyOf(item) === tool)) {
|
||||
@@ -74,18 +72,13 @@ export function useGlobalShortcutActions(): void {
|
||||
updateParams((params) => toggleToolDialogParams(params, tool), 'push')
|
||||
return
|
||||
}
|
||||
const action = resolveToolPanelToggle(panelToolParam(searchParams), tool)
|
||||
if (action === 'close') {
|
||||
closePushedParams(clearToolPanelParams)
|
||||
return
|
||||
}
|
||||
updateParams((params) => toggleToolPanelParams(params, tool), action === 'switch' ? 'replace' : 'push')
|
||||
togglePanelTool(tool)
|
||||
return
|
||||
}
|
||||
if (isRemoteRoute || tool === 'files') return
|
||||
const host = repoId !== null ? getRepoPath(repoId) : getAssistantPath()
|
||||
navigate(`${host}${dialogSearch(tool)}`)
|
||||
}, [toolItems, isMobile, searchParams, updateParams, closePushedParams, navigate, repoId, isRemoteRoute])
|
||||
}, [toolItems, isMobile, togglePanelTool, updateParams, navigate, repoId, isRemoteRoute])
|
||||
|
||||
const newSession = sessionDirectory && !createSession.isPending
|
||||
? () => createSession.mutate({})
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { act, renderHook } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import { LocationCatcher } from '@/test/test-utils'
|
||||
import {
|
||||
useSessionPickerNavigation,
|
||||
type SessionPickerNavigationOptions,
|
||||
} from './useSessionPickerNavigation'
|
||||
|
||||
function createSession(id: string): Session {
|
||||
return {
|
||||
id,
|
||||
projectID: 'proj-1',
|
||||
title: `Session ${id}`,
|
||||
time: { created: 1, updated: 2 },
|
||||
location: { directory: '/repos/1' },
|
||||
cost: 0,
|
||||
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
||||
}
|
||||
}
|
||||
|
||||
function createRepo(id: number): Repo {
|
||||
return {
|
||||
id,
|
||||
name: `repo-${id}`,
|
||||
fullPath: `/repos/${id}`,
|
||||
localPath: `/repos/${id}`,
|
||||
defaultBranch: 'main',
|
||||
currentBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
}
|
||||
}
|
||||
|
||||
function renderPickerNavigation(
|
||||
initialEntries: string[],
|
||||
options: Omit<SessionPickerNavigationOptions, 'onClose'>,
|
||||
) {
|
||||
const onClose = vi.fn()
|
||||
const capturedPathname: { current: string } = { current: '' }
|
||||
const capturedSearch: { current: string } = { current: '' }
|
||||
const capturedNavigationType: { current: string } = { current: '' }
|
||||
const wrapper = function Wrapper({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<MemoryRouter initialEntries={initialEntries}>
|
||||
<LocationCatcher
|
||||
capturedPathname={capturedPathname}
|
||||
capturedSearch={capturedSearch}
|
||||
capturedNavigationType={capturedNavigationType}
|
||||
/>
|
||||
{children}
|
||||
</MemoryRouter>
|
||||
)
|
||||
}
|
||||
const rendered = renderHook(() => useSessionPickerNavigation({ ...options, onClose }), { wrapper })
|
||||
return {
|
||||
...rendered,
|
||||
onClose,
|
||||
location: () =>
|
||||
`${capturedPathname.current}${capturedSearch.current} ${capturedNavigationType.current}`,
|
||||
}
|
||||
}
|
||||
|
||||
describe('useSessionPickerNavigation', () => {
|
||||
describe('panel mode', () => {
|
||||
it('pushes the chosen session and keeps the panel open', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1/sessions/a?panel=sessions'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectSession(createSession('b'), createRepo(1))
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1/sessions/b?panel=sessions PUSH')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps the panel param when opening a session on another server', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/servers/srv_kitchen/sessions/a?panel=sessions'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectRemoteSession(createSession('b'), 'srv_hall')
|
||||
})
|
||||
|
||||
expect(location()).toBe('/servers/srv_hall/sessions/b?panel=sessions PUSH')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does nothing when the chosen local session is already open', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1/sessions/a?panel=sessions'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectSession(createSession('a'), createRepo(1))
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1/sessions/a?panel=sessions POP')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does nothing when the chosen remote session is already open', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/servers/srv_kitchen/sessions/a?panel=sessions'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectRemoteSession(createSession('a'), 'srv_kitchen')
|
||||
})
|
||||
|
||||
expect(location()).toBe('/servers/srv_kitchen/sessions/a?panel=sessions POP')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('leaves the path unchanged without a panel param', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1/sessions/a'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectSession(createSession('b'), createRepo(1))
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1/sessions/b PUSH')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not carry an empty panel param', () => {
|
||||
const { result, location } = renderPickerNavigation(['/repos/1/sessions/a?panel='], {
|
||||
mode: 'panel',
|
||||
})
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectRepo(createRepo(2))
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/2 PUSH')
|
||||
})
|
||||
|
||||
it('pushes a prepared path with the panel param and keeps the picker open', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1/sessions/a?panel=sessions'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onNavigate('/repos/1/schedules')
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1/schedules?panel=sessions PUSH')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('calls only the delete override when one is supplied', () => {
|
||||
const onDeleteActiveSession = vi.fn()
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/servers/srv_kitchen/sessions/a?panel=sessions'],
|
||||
{ mode: 'panel', onDeleteActiveSession },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onDeleteActiveSession()
|
||||
})
|
||||
|
||||
expect(onDeleteActiveSession).toHaveBeenCalledTimes(1)
|
||||
expect(location()).toBe('/servers/srv_kitchen/sessions/a?panel=sessions POP')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does nothing when deleting without an override outside a repo route', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/servers/srv_kitchen/sessions/a?panel=sessions'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onDeleteActiveSession()
|
||||
})
|
||||
|
||||
expect(location()).toBe('/servers/srv_kitchen/sessions/a?panel=sessions POP')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('opens the session list with the panel param when a repo is in view', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1/sessions/a?panel=sessions&repoTab=changes'],
|
||||
{ mode: 'panel' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onDeleteActiveSession()
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1?repoTab=changes&panel=sessions PUSH')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('push mode', () => {
|
||||
it('pushes the chosen session and closes the picker', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1?mobileTab=sessions'],
|
||||
{ mode: 'push' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectSession(createSession('b'), createRepo(1))
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1/sessions/b PUSH')
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('closes the picker without navigating when the session is already open', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1/sessions/a?mobileTab=sessions'],
|
||||
{ mode: 'push' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectSession(createSession('a'), createRepo(1))
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1/sessions/a?mobileTab=sessions POP')
|
||||
expect(onClose).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('replace mode', () => {
|
||||
it('replaces the entry without closing the picker', () => {
|
||||
const { result, onClose, location } = renderPickerNavigation(
|
||||
['/repos/1/sessions/a?mobileTab=sessions'],
|
||||
{ mode: 'replace' },
|
||||
)
|
||||
|
||||
act(() => {
|
||||
result.current.onSelectSession(createSession('b'), createRepo(1))
|
||||
})
|
||||
|
||||
expect(location()).toBe('/repos/1/sessions/b REPLACE')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -14,10 +14,11 @@ import {
|
||||
|
||||
export interface SessionPickerNavigationOptions {
|
||||
/**
|
||||
* `replace` rewrites the entry the mobile sheet was opened from so Back returns to the page behind
|
||||
* it; `push` adds an entry and closes the picker.
|
||||
* `replace` rewrites the entry the picker was opened from so Back returns to the page behind it;
|
||||
* `push` adds an entry and closes the picker; `panel` adds an entry, carries the current `panel`
|
||||
* search param onto the destination path and leaves the picker open.
|
||||
*/
|
||||
mode: 'push' | 'replace'
|
||||
mode: 'push' | 'replace' | 'panel'
|
||||
onClose: () => void
|
||||
/** Replaces the default delete behaviour of returning to the current repo's session list. */
|
||||
onDeleteActiveSession?: () => void
|
||||
@@ -32,10 +33,11 @@ export interface SessionPickerNavigation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the session picker handlers shared by the mobile sheet, the desktop dialog and the session
|
||||
* page picker. The route in view comes from the location: choosing the session already open on the
|
||||
* same server only closes the picker, and an assistant session keeps `?assistant=1` when the chosen
|
||||
* session belongs to the current repo.
|
||||
* Builds the session picker handlers shared by the mobile sheet, the desktop dialog, the desktop
|
||||
* tool panel and the session page picker. The route in view comes from the location: choosing the
|
||||
* session already open on the same server only closes the picker, and does nothing in `panel` mode
|
||||
* where the picker stays open. An assistant session keeps `?assistant=1` when the chosen session
|
||||
* belongs to the current repo.
|
||||
*
|
||||
* @param options Navigation mode, the picker's close callback, and an optional delete override.
|
||||
* @returns Handlers for selecting sessions and repos and for following a prepared path.
|
||||
@@ -52,19 +54,23 @@ export function useSessionPickerNavigation({
|
||||
const searchParams = new URLSearchParams(search)
|
||||
const isAssistantSession = searchParams.get('assistant') === '1'
|
||||
const repoTab = searchParams.get('repoTab') ?? undefined
|
||||
const panelId = searchParams.get('panel')
|
||||
const isPanelMode = mode === 'panel'
|
||||
|
||||
const open = useCallback(
|
||||
(path: string) => {
|
||||
navigate(path, { replace: mode === 'replace' })
|
||||
navigate(isPanelMode && panelId ? withQueryParam(path, 'panel', panelId) : path, {
|
||||
replace: mode === 'replace',
|
||||
})
|
||||
if (mode === 'push') onClose()
|
||||
},
|
||||
[mode, navigate, onClose],
|
||||
[isPanelMode, mode, navigate, onClose, panelId],
|
||||
)
|
||||
|
||||
const onSelectSession = useCallback(
|
||||
(session: Session, repo: Repo) => {
|
||||
if (session.id === activeSessionID && activeServerId === LOCAL_OPENCODE_SERVER_ID) {
|
||||
onClose()
|
||||
if (!isPanelMode) onClose()
|
||||
return
|
||||
}
|
||||
const sessionPath = getSessionPath(repo.id, session.id)
|
||||
@@ -74,32 +80,40 @@ export function useSessionPickerNavigation({
|
||||
: sessionPath,
|
||||
)
|
||||
},
|
||||
[activeServerId, activeSessionID, currentRepoId, isAssistantSession, onClose, open],
|
||||
[activeServerId, activeSessionID, currentRepoId, isAssistantSession, isPanelMode, onClose, open],
|
||||
)
|
||||
|
||||
const onSelectRemoteSession = useCallback(
|
||||
(session: Session, serverId: string) => {
|
||||
if (session.id === activeSessionID && serverId === activeServerId) {
|
||||
onClose()
|
||||
if (!isPanelMode) onClose()
|
||||
return
|
||||
}
|
||||
open(getServerSessionPath(serverId, session.id))
|
||||
},
|
||||
[activeServerId, activeSessionID, onClose, open],
|
||||
[activeServerId, activeSessionID, isPanelMode, onClose, open],
|
||||
)
|
||||
|
||||
const onDeleteActiveSession = useCallback(() => {
|
||||
if (deleteActiveSessionOverride) {
|
||||
onClose()
|
||||
if (!isPanelMode) onClose()
|
||||
deleteActiveSessionOverride()
|
||||
return
|
||||
}
|
||||
if (currentRepoId === null) {
|
||||
onClose()
|
||||
if (!isPanelMode) onClose()
|
||||
return
|
||||
}
|
||||
open(getSessionListPath(currentRepoId, isAssistantSession, repoTab))
|
||||
}, [currentRepoId, deleteActiveSessionOverride, isAssistantSession, onClose, open, repoTab])
|
||||
}, [
|
||||
currentRepoId,
|
||||
deleteActiveSessionOverride,
|
||||
isAssistantSession,
|
||||
isPanelMode,
|
||||
onClose,
|
||||
open,
|
||||
repoTab,
|
||||
])
|
||||
|
||||
const onSelectRepo = useCallback(
|
||||
(repo: Repo) => {
|
||||
|
||||
@@ -2,10 +2,11 @@ import { describe, expect, it } from 'vitest'
|
||||
import { createElement } from 'react'
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { MemoryRouter, useLocation, useNavigate } from 'react-router-dom'
|
||||
import { isPanelTool, toggleToolDialogParams, toggleToolPanelParams, useToolPanel } from './useToolPanel'
|
||||
import { isPanelTool, toggleToolDialogParams, toggleToolPanelParams, useToolPanel, useToolPanelToggle } from './useToolPanel'
|
||||
|
||||
describe('activity tool', () => { it('is a panel tool', () => {
|
||||
expect(isPanelTool('activity')).toBe(true)
|
||||
describe('sessions tool', () => {
|
||||
it('is a panel tool', () => {
|
||||
expect(isPanelTool('sessions')).toBe(true)
|
||||
})
|
||||
|
||||
it('clears without opening a dialog when the panel is not docked', async () => {
|
||||
@@ -18,13 +19,13 @@ describe('activity tool', () => { it('is a panel tool', () => {
|
||||
render(
|
||||
createElement(
|
||||
MemoryRouter,
|
||||
{ initialEntries: ['/repos/1/sessions/abc?panel=activity'] },
|
||||
{ initialEntries: ['/repos/1/sessions/abc?panel=sessions'] },
|
||||
createElement(Probe),
|
||||
),
|
||||
)
|
||||
|
||||
await waitFor(() => expect(screen.getByTestId('search').textContent).not.toContain('panel=activity'))
|
||||
expect(screen.getByTestId('search').textContent).not.toContain('dialog=activity')
|
||||
await waitFor(() => expect(screen.getByTestId('search').textContent).not.toContain('panel=sessions'))
|
||||
expect(screen.getByTestId('search').textContent).not.toContain('dialog=sessions')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -203,3 +204,57 @@ describe('panel history entries', () => {
|
||||
expect(screen.getByTestId('pathname').textContent).toBe('/repos/2')
|
||||
})
|
||||
})
|
||||
|
||||
describe('useToolPanelToggle', () => {
|
||||
function ToggleHarness() {
|
||||
const toggleTool = useToolPanelToggle()
|
||||
const { activeTool } = useToolPanel(true)
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
return createElement(
|
||||
'div',
|
||||
null,
|
||||
createElement('span', { 'data-testid': 'activeTool' }, activeTool ?? ''),
|
||||
createElement('span', { 'data-testid': 'search' }, location.search),
|
||||
createElement('button', { onClick: () => toggleTool('files') }, 'open files'),
|
||||
createElement('button', { onClick: () => toggleTool('terminal') }, 'open terminal'),
|
||||
createElement('button', { onClick: () => navigate(-1) }, 'back'),
|
||||
)
|
||||
}
|
||||
|
||||
function renderToggleHarness() {
|
||||
render(createElement(MemoryRouter, { initialEntries: ['/repos/1/sessions/ses_1'] }, createElement(ToggleHarness)))
|
||||
}
|
||||
|
||||
it('opens the tool with a new history entry', () => {
|
||||
renderToggleHarness()
|
||||
|
||||
fireEvent.click(screen.getByText('open files'))
|
||||
expect(screen.getByTestId('search').textContent).toBe('?panel=files')
|
||||
|
||||
fireEvent.click(screen.getByText('back'))
|
||||
expect(screen.getByTestId('search').textContent).toBe('')
|
||||
})
|
||||
|
||||
it('switches the open panel in place without a new history entry', () => {
|
||||
renderToggleHarness()
|
||||
|
||||
fireEvent.click(screen.getByText('open files'))
|
||||
fireEvent.click(screen.getByText('open terminal'))
|
||||
expect(screen.getByTestId('search').textContent).toBe('?panel=terminal')
|
||||
|
||||
fireEvent.click(screen.getByText('back'))
|
||||
expect(screen.getByTestId('search').textContent).toBe('')
|
||||
})
|
||||
|
||||
it('closes the panel when the tool is already open', () => {
|
||||
renderToggleHarness()
|
||||
|
||||
fireEvent.click(screen.getByText('open files'))
|
||||
fireEvent.click(screen.getByText('open files'))
|
||||
|
||||
expect(screen.getByTestId('activeTool').textContent).toBe('')
|
||||
expect(screen.getByTestId('search').textContent).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -4,7 +4,7 @@ import { useUrlParams } from './useUrlParams'
|
||||
|
||||
const PANEL_PARAM = 'panel'
|
||||
|
||||
const PANEL_TOOLS = ['sourceControl', 'files', 'terminal', 'walkthrough', 'preview', 'mcp', 'actions', 'skills', 'schedules', 'activity', 'secrets'] as const
|
||||
const PANEL_TOOLS = ['sourceControl', 'files', 'terminal', 'walkthrough', 'preview', 'mcp', 'actions', 'skills', 'schedules', 'sessions', 'secrets'] as const
|
||||
|
||||
export type PanelTool = (typeof PANEL_TOOLS)[number]
|
||||
|
||||
@@ -16,7 +16,7 @@ const TOOL_OWNED_PARAMS: Partial<Record<PanelTool, readonly string[]>> = {
|
||||
schedules: ['scheduleTab', 'scheduleDialog', 'jobId', 'runId'],
|
||||
}
|
||||
|
||||
const PANEL_ONLY_TOOLS: ReadonlySet<PanelTool> = new Set(['schedules', 'activity'])
|
||||
const PANEL_ONLY_TOOLS: ReadonlySet<PanelTool> = new Set(['schedules', 'sessions'])
|
||||
|
||||
export function isPanelTool(value: string | null): value is PanelTool {
|
||||
return value !== null && (PANEL_TOOLS as readonly string[]).includes(value)
|
||||
@@ -63,8 +63,22 @@ export function clearToolPanelParams(params: URLSearchParams): void {
|
||||
clearToolParams(params)
|
||||
}
|
||||
|
||||
export function panelToolParam(params: URLSearchParams): string | null {
|
||||
return params.get(PANEL_PARAM)
|
||||
/**
|
||||
* Toggles a tool in the desktop tool panel from anywhere outside the panel: closes it when it is already
|
||||
* open, switches the open panel in place, or opens it with a new history entry.
|
||||
*/
|
||||
export function useToolPanelToggle(): (tool: PanelTool) => void {
|
||||
const { searchParams, updateParams, closePushedParams } = useUrlParams()
|
||||
const panelParam = searchParams.get(PANEL_PARAM)
|
||||
|
||||
return useCallback((tool: PanelTool) => {
|
||||
const action = resolveToolPanelToggle(panelParam, tool)
|
||||
if (action === 'close') {
|
||||
closePushedParams(clearToolPanelParams)
|
||||
return
|
||||
}
|
||||
updateParams((params) => toggleToolPanelParams(params, tool), action === 'switch' ? 'replace' : 'push')
|
||||
}, [panelParam, updateParams, closePushedParams])
|
||||
}
|
||||
|
||||
export interface ToolPanelState {
|
||||
@@ -109,14 +123,7 @@ export function useToolPanel(panelAvailable: boolean): ToolPanelState {
|
||||
closePushedParams(clearToolPanelParams)
|
||||
}, [closePushedParams])
|
||||
|
||||
const toggleTool = useCallback((tool: PanelTool) => {
|
||||
const action = resolveToolPanelToggle(panelParam, tool)
|
||||
if (action === 'close') {
|
||||
closePanel()
|
||||
return
|
||||
}
|
||||
updateParams((params) => toggleToolPanelParams(params, tool), action === 'switch' ? 'replace' : 'push')
|
||||
}, [panelParam, closePanel, updateParams])
|
||||
const toggleTool = useToolPanelToggle()
|
||||
|
||||
return { activeTool, toggleTool, closePanel }
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import { useMobile } from './useMobile'
|
||||
export const TOOL_PANEL_MIN_WIDTH = 320
|
||||
export const TOOL_PANEL_MAX_WIDTH = 720
|
||||
export const TOOL_PANEL_DEFAULT_WIDTH = 600
|
||||
export const TOOL_PANEL_ACTIVITY_WIDTH = 320
|
||||
export const TOOL_PANEL_RAIL_WIDTH = 44
|
||||
export const MAIN_CONTENT_MIN_WIDTH = 420
|
||||
|
||||
|
||||
Reference in new issue
Block a user