Merge pull request #8022 from deepseek-harness/turtle/fix-ungrouped-new-session-8d376327b451
fix(ui-workspace): drop the inert New Session button from the Ungrouped header
This commit is contained in:
commit
7e00f186e2
8 files changed
+43
-51
No files matched your search
@@ -33,8 +33,8 @@
|
||||
en: 9fb88260380bf093
|
||||
zh: 3bace2b96ecd4a82
|
||||
/deepseek-ai-dsh-client-ui-workspace/use-this-package/active-schedule-markers:
|
||||
en: 668ee06286b227b6
|
||||
zh: aafdb03cde1b93c9
|
||||
en: 249d9552d8bef805
|
||||
zh: 405b1c636cba8e0b
|
||||
/deepseek-ai-dsh-client-ui-workspace/understand-the-implementation:
|
||||
en: 8f170900a4096408
|
||||
zh: 85332e80adf39403
|
||||
|
||||
@@ -85,7 +85,7 @@ Session rows share their existing action contributions between right-click and t
|
||||
|
||||
`ctx.uiWorkspace.openSession(target)` synchronously replaces the owned `mainView` reference and returns the main area to Conversation without waiting for `reference.ready`, so history loading renders inside the selected Session view. The target may be a known Session id or a durable direct-parent subagent address; an explicit address does not require a preloaded parent catalog. `openWorkspace(id, beforeOpen?, options?)` opens a Workspace blank only if no later navigation has superseded the request; New Session opens the same blank as Workspace reopening, so it returns to that blank's unsent draft. `forkSession(id, onCreated?, options?)` creates the child without navigating or superseding a pending navigation; `allowMigration` carries the caller's migration permission. The optional synchronous preparation callback runs after the target is retained and only for a current Workspace request, so superseded requests do not move composer drafts. Navigation or owner disposal suppresses the late UI commit, not the underlying Session creation.
|
||||
|
||||
Session and Workspace rows derive their affordances from the browser root's access Hooks: the global `useRemoteAccess('session/create')` gates every New Session entry, `useWorkspaceAccess` gates a Workspace's create, rename, delete, and reorder verbs, and `useSessionAccess` gates a Session row's rename, fork, drag, pin, archive, and unarchive verbs plus the search result's restore control. A refused verb is not rendered, while every Host request remains authoritative. Startup restoration retains its main reference without changing the selected panel or cancelling a later navigation. Archiving the main Session releases its reference and clears the main selection. Selection failure leaves a global panel visible. Session rows read `usePanelInfo` to suppress their selected appearance while a global panel is active; search and directory-picker focus alone do not leave that panel.
|
||||
Session and Workspace rows derive their affordances from the browser root's access Hooks: `useWorkspaceAccess` gates a Workspace's create, rename, delete, and reorder verbs, and `useSessionAccess` gates a Session row's rename, fork, drag, pin, archive, and unarchive verbs plus the search result's restore control. A refused verb is not rendered, while every Host request remains authoritative. The Ungrouped header offers no New Session, because it has no backing Workspace to start one in. Startup restoration retains its main reference without changing the selected panel or cancelling a later navigation. Archiving the main Session releases its reference and clears the main selection. Selection failure leaves a global panel visible. Session rows read `usePanelInfo` to suppress their selected appearance while a global panel is active; search and directory-picker focus alone do not leave that panel.
|
||||
|
||||
Navigation and startup restoration obtain the selected Session's projections from its `follow`; neither issues a separate projection refresh for that Session or its parent, except that restoring a saved blank first reloads that Session's projections, because listed values are cached hints that can lag its log after an unclean Host exit.
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ Session 行渲染运行时的实时 `pendingInteraction` 分类:审批显示**
|
||||
|
||||
`ctx.uiWorkspace.openSession(target)` 会同步替换其拥有的 `mainView` reference,并让主区域返回 Conversation,而不等待 `reference.ready`,因此历史加载会显示在已经选中的 Session 视图内。目标可以是已知 Session id,也可以是持久的直接父子 subagent 地址;显式地址不要求预先加载 parent catalog。`openWorkspace(id, beforeOpen?, options?)` 仅在请求未被后续导航替代时打开工作区空白 Session;新会话与重新打开工作区打开同一个空白会话,因此会回到该空白会话中未发送的草稿。`forkSession(id, onCreated?, options?)` 创建子会话,不导航,也不替代尚未完成的导航;`allowMigration` 携带调用方的迁移许可。可选的同步准备回调在目标被 retain 后执行,并且仅对仍有效的 Workspace 请求执行,因此过期请求不会搬移 composer 草稿。后续导航或 owner 释放会阻止晚到的 UI 提交,但不取消底层 Session 创建。
|
||||
|
||||
Session 行与 Workspace 行的可用操作来自浏览器根的访问 Hook:全局 `useRemoteAccess('session/create')` 门控所有新建会话入口,`useWorkspaceAccess` 门控 Workspace 的新建、重命名、删除与排序动作,`useSessionAccess` 门控 Session 行的重命名、分叉、拖拽、置顶、归档与取消归档动作,以及搜索结果的恢复控件。被拒绝的动作不渲染,但每个发往 Host 的请求仍以其授权为准。启动恢复会 retain 主 reference,不改变已选面板,也不取消后续导航。归档主 Session 会释放其 reference 并清除主选择。选择失败时保留当前全局面板。Session 行读取 `usePanelInfo`,在全局面板活跃时不显示 Session 选中样式;仅把焦点移到搜索框或目录选择器不会离开该面板。
|
||||
Session 行与 Workspace 行的可用操作来自浏览器根的访问 Hook:`useWorkspaceAccess` 门控 Workspace 的新建、重命名、删除与排序动作,`useSessionAccess` 门控 Session 行的重命名、分叉、拖拽、置顶、归档与取消归档动作,以及搜索结果的恢复控件。被拒绝的动作不渲染,但每个发往 Host 的请求仍以其授权为准。Ungrouped 标题行不提供新建会话,因为它没有可在其中新建会话的后备 Workspace。启动恢复会 retain 主 reference,不改变已选面板,也不取消后续导航。归档主 Session 会释放其 reference 并清除主选择。选择失败时保留当前全局面板。Session 行读取 `usePanelInfo`,在全局面板活跃时不显示 Session 选中样式;仅把焦点移到搜索框或目录选择器不会离开该面板。
|
||||
|
||||
导航和启动恢复通过所选 Session 的 `follow` 获取投影,不会另行刷新该 Session 或其父会话的投影;例外是恢复已保存的空白会话时先重新加载该 Session 的投影,因为列表中的值是缓存提示,Host 非正常退出后可能落后于其日志。
|
||||
|
||||
|
||||
@@ -223,31 +223,32 @@ type ProjectRowItemProps = {
|
||||
newShortcut?: ShortcutCatalogEntry | undefined
|
||||
containsCurrentDescendant?: boolean
|
||||
onToggle: () => void
|
||||
onCreate: () => void
|
||||
onCreate: (workspaceId: WorkspaceId) => void
|
||||
/** Present only for real Workspace rows in the grouped view. */
|
||||
drag?: WorkspaceRowDragProps | undefined
|
||||
/** Host account home; POSIX home-rooted hover paths display as `~`. */
|
||||
home?: string | undefined
|
||||
t: RowTranslate
|
||||
} & Pick<WorkspaceBrowserProps, 'useRemoteAccess' | 'useWorkspaceAccess' | 'renderFactorySlot' | 'useContextMenuTarget' | 'useContextMenu'>
|
||||
} & Pick<WorkspaceBrowserProps, 'useWorkspaceAccess' | 'renderFactorySlot' | 'useContextMenuTarget' | 'useContextMenu'>
|
||||
|
||||
/** Which of one header row's actions the caller's access snapshot allows. */
|
||||
interface ProjectRowAccess {
|
||||
readonly create: boolean
|
||||
/** The header actions one row offers; an absent create offers no New Session button. */
|
||||
interface ProjectRowActions {
|
||||
readonly create?: (() => void) | undefined
|
||||
readonly reorder: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Project (workspace) header row: folder + title;
|
||||
* hover reveals the chevron and create button, and dwelling on a real
|
||||
* Workspace shows its hover card (the ungrouped bucket has none).
|
||||
* hover reveals the chevron and, on a real Workspace, the create button;
|
||||
* dwelling on a real Workspace shows its hover card. The ungrouped bucket
|
||||
* has neither, because it has no backing Workspace to start a Session in.
|
||||
* `containsCurrent` arrives on the node (derivation fact, no renderer scan).
|
||||
* Create and drag follow the Workspace access snapshot. Menu providers own
|
||||
* their access checks; the ungrouped bucket has no Workspace menu.
|
||||
* @param props.group - derived group node.
|
||||
* @param props.containsCurrentDescendant - highlight an ancestor even when its subtree is collapsed.
|
||||
* @param props.onToggle - expand/collapse the group.
|
||||
* @param props.onCreate - start a frontend Session inside this Workspace.
|
||||
* @param props.onCreate - start a frontend Session inside the given Workspace.
|
||||
* @param props.drag - optional workspace-row drag wiring.
|
||||
* @param props.home - host account home for POSIX hover-path abbreviation.
|
||||
* @param props.t - the browser root's locale seat.
|
||||
@@ -260,28 +261,29 @@ export function ProjectRowItem(props: ProjectRowItemProps) {
|
||||
: <WorkspaceProjectRow {...props} workspaceId={workspaceId} />
|
||||
}
|
||||
|
||||
/** The ungrouped bucket's header: no Workspace resource, so starting a Session there asks the global resource. */
|
||||
/** The ungrouped bucket's header: no backing Workspace to start a Session in or reorder. */
|
||||
function UngroupedProjectRow(props: ProjectRowItemProps) {
|
||||
const create = props.useRemoteAccess('session/create')
|
||||
return <ProjectRow {...props} access={{ create, reorder: false }} />
|
||||
return <ProjectRow {...props} actions={{ reorder: false }} />
|
||||
}
|
||||
|
||||
/** A real Workspace's header: every action asks that Workspace's resource. */
|
||||
function WorkspaceProjectRow({ workspaceId, ...props }: ProjectRowItemProps & { workspaceId: WorkspaceId }) {
|
||||
const { useWorkspaceAccess } = props
|
||||
const access: ProjectRowAccess = {
|
||||
create: useWorkspaceAccess(workspaceId, 'session/create'),
|
||||
const create = useWorkspaceAccess(workspaceId, 'session/create')
|
||||
const actions: ProjectRowActions = {
|
||||
create: create ? () => { props.onCreate(workspaceId) } : undefined,
|
||||
reorder: useWorkspaceAccess(workspaceId, 'workspace/insertBefore'),
|
||||
}
|
||||
return <ProjectRow {...props} access={access} />
|
||||
return <ProjectRow {...props} actions={actions} />
|
||||
}
|
||||
|
||||
function ProjectRow({
|
||||
group, containsCurrentDescendant = false, onToggle, onCreate, drag: offeredDrag, home, newShortcut, t, access,
|
||||
group, containsCurrentDescendant = false, onToggle, drag: offeredDrag, home, newShortcut, t, actions,
|
||||
renderFactorySlot, useContextMenuTarget, useContextMenu,
|
||||
}: ProjectRowItemProps & { access: ProjectRowAccess }) {
|
||||
}: Omit<ProjectRowItemProps, 'onCreate'> & { actions: ProjectRowActions }) {
|
||||
const { getTriggerProps } = useContextMenu()
|
||||
const drag = access.reorder ? offeredDrag : undefined
|
||||
const drag = actions.reorder ? offeredDrag : undefined
|
||||
const create = actions.create
|
||||
const row = group
|
||||
// The ungrouped bucket has no workspace title: its label is dictionary copy.
|
||||
const label = row.workspaceId === undefined ? t('group.ungrouped') : row.label
|
||||
@@ -326,14 +328,14 @@ function ProjectRow({
|
||||
className: css.iconButton,
|
||||
})
|
||||
)}
|
||||
{access.create && (
|
||||
{create !== undefined && (
|
||||
<Tooltip label={t('actions.newSession')} shortcutKeys={newShortcut?.keys} side="bottom" align="end" delayMs={500} portal>
|
||||
<button
|
||||
type="button"
|
||||
className={css.iconButton}
|
||||
aria-keyshortcuts={newShortcut?.aria}
|
||||
aria-label={t('actions.newSession.aria', { name: label })}
|
||||
onClick={(e) => { e.stopPropagation(); onCreate() }}
|
||||
onClick={(e) => { e.stopPropagation(); create() }}
|
||||
>
|
||||
<IconNewChatOutlineRegular size={14} />
|
||||
</button>
|
||||
|
||||
@@ -254,7 +254,7 @@ type SessionTreeProps = Pick<
|
||||
WorkspaceBrowserProps,
|
||||
'useSessionStatus' | 'startSession' | 'open' | 'renderFactorySlot' | 'useContextMenuTarget' | 'useContextMenu'
|
||||
| 'insertWorkspaceBefore' | 't' | 'usePanelInfo'
|
||||
| 'useRemoteAccess' | 'useSessionAccess' | 'useWorkspaceAccess'
|
||||
| 'useSessionAccess' | 'useWorkspaceAccess'
|
||||
> & PropsRenderSlots<
|
||||
| 'sidebar.workspaces.session.row.action'
|
||||
| 'sidebar.session.row.trailing'
|
||||
@@ -314,7 +314,7 @@ function EmptySessions({ rowState, onLeaveArchivedOnly, t }: Pick<SessionTreePro
|
||||
function SessionTree({
|
||||
list, useSessionStatus, startSession, open, workspaces, ungroupedSessionIds,
|
||||
rowState, onLeaveArchivedOnly,
|
||||
workspaceReady, animationResetKey, usePanelInfo, useRemoteAccess, useSessionAccess, useWorkspaceAccess,
|
||||
workspaceReady, animationResetKey, usePanelInfo, useSessionAccess, useWorkspaceAccess,
|
||||
onSessionRenameRequest,
|
||||
renderSlot, renderFactorySlot, useContextMenuTarget, useContextMenu,
|
||||
insertWorkspaceBefore,
|
||||
@@ -555,7 +555,6 @@ function SessionTree({
|
||||
newShortcut={shortcuts.find(row => row.id === 'session.new')}
|
||||
group={group}
|
||||
renderFactorySlot={renderFactorySlot} useContextMenu={useContextMenu} useContextMenuTarget={useContextMenuTarget}
|
||||
useRemoteAccess={useRemoteAccess}
|
||||
useWorkspaceAccess={useWorkspaceAccess}
|
||||
containsCurrentDescendant={currentAncestors.has(group.key)}
|
||||
home={home}
|
||||
@@ -564,11 +563,9 @@ function SessionTree({
|
||||
if (group.expanded) dropWatermarks(key => withinGroup(key, group.key))
|
||||
setGroupExpanded(group.key, !group.expanded)
|
||||
}}
|
||||
onCreate={() => {
|
||||
if (group.workspaceId !== undefined) {
|
||||
setGroupExpanded(group.key, true)
|
||||
startSession(group.workspaceId)
|
||||
}
|
||||
onCreate={(workspaceId) => {
|
||||
setGroupExpanded(group.key, true)
|
||||
startSession(workspaceId)
|
||||
}}
|
||||
drag={workspaceDragProps}
|
||||
/>
|
||||
@@ -900,7 +897,6 @@ export function WorkspaceBrowser({
|
||||
useSectionScroller,
|
||||
useSessions,
|
||||
useSessionStatus,
|
||||
useRemoteAccess,
|
||||
useSessionAccess,
|
||||
useWorkspaceAccess,
|
||||
useWorkspaces,
|
||||
@@ -1400,7 +1396,6 @@ export function WorkspaceBrowser({
|
||||
)
|
||||
: (
|
||||
<SessionTree
|
||||
useRemoteAccess={useRemoteAccess}
|
||||
useSessionAccess={useSessionAccess}
|
||||
useWorkspaceAccess={useWorkspaceAccess}
|
||||
usePanelInfo={usePanelInfo}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
*
|
||||
* Hand-built row props spread allow-all access Hooks, so they cannot show that the browsing region
|
||||
* reads the Hooks a page actually binds. This spec replaces the runtime's allow-all access row with the
|
||||
* remote-access snapshot owner itself and renders the real slot tree, so the global and Workspace
|
||||
* access Hooks are the renderer's bindings over one non-owner snapshot.
|
||||
* remote-access snapshot owner itself and renders the real slot tree, so the Workspace access Hooks
|
||||
* are the renderer's bindings over one non-owner snapshot.
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { act, cleanup, screen } from '@testing-library/react'
|
||||
@@ -131,7 +131,7 @@ describe('Workspace header actions under the page access snapshot', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('asks the global resource before the Ungrouped header offers New Session', async () => {
|
||||
it('never offers New Session on the Ungrouped header, even under a global grant', async () => {
|
||||
const access = new ClientAccessState({ type: 'baseline', owner: false, grants: [] })
|
||||
const runtime = await bench(access, { ungroupedSession: 'loose' as SessionId })
|
||||
try {
|
||||
@@ -141,7 +141,7 @@ describe('Workspace header actions under the page access snapshot', () => {
|
||||
act(() => {
|
||||
access.update({ type: 'upsert', grant: { resource: { kind: 'global' }, actions: ['session/create'] } })
|
||||
})
|
||||
expect(screen.getByRole('button', { name: '在“未分组”中新建会话' })).toBeTruthy()
|
||||
expect(screen.queryByRole('button', { name: '在“未分组”中新建会话' })).toBeNull()
|
||||
} finally {
|
||||
await runtime.dispose()
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ function SessionNodeItem({ renderSlot = renderNoRowEntries, onRenameRequest = ()
|
||||
|
||||
// Direct header specs hold every access answer unless the case refuses one.
|
||||
function ProjectRowItem({
|
||||
useRemoteAccess = allowAllAccess.useRemoteAccess, useWorkspaceAccess = allowAllAccess.useWorkspaceAccess,
|
||||
useWorkspaceAccess = allowAllAccess.useWorkspaceAccess,
|
||||
renderFactorySlot = renderMenuButton, useContextMenuTarget = select => select(null), ...props
|
||||
}: Omit<ProjectRowItemProps, 'useRemoteAccess' | 'useWorkspaceAccess' | 'renderFactorySlot' | 'useContextMenuTarget' | 'useContextMenu'>
|
||||
& Partial<Pick<ProjectRowItemProps, 'useRemoteAccess' | 'useWorkspaceAccess' | 'renderFactorySlot' | 'useContextMenuTarget' | 'useContextMenu'>>) {
|
||||
return <ProjectRowItemComponent {...props} useRemoteAccess={useRemoteAccess} useWorkspaceAccess={useWorkspaceAccess}
|
||||
}: Omit<ProjectRowItemProps, 'useWorkspaceAccess' | 'renderFactorySlot' | 'useContextMenuTarget' | 'useContextMenu'>
|
||||
& Partial<Pick<ProjectRowItemProps, 'useWorkspaceAccess' | 'renderFactorySlot' | 'useContextMenuTarget' | 'useContextMenu'>>) {
|
||||
return <ProjectRowItemComponent {...props} useWorkspaceAccess={useWorkspaceAccess}
|
||||
useContextMenu={props.useContextMenu ?? contextMenuHook()} renderFactorySlot={renderFactorySlot}
|
||||
useContextMenuTarget={useContextMenuTarget} />
|
||||
}
|
||||
@@ -707,19 +707,17 @@ describe('workspace browser rows', () => {
|
||||
view.rerender(<ProjectRowItem {...props} useWorkspaceAccess={useWorkspaceAccess} />)
|
||||
expect(screen.getByRole('treeitem').getAttribute('draggable')).toBe('true')
|
||||
fireEvent.click(screen.getByRole('button', { name: '在“Project”中新建会话' }))
|
||||
expect(props.onCreate).toHaveBeenCalledOnce()
|
||||
expect(props.onCreate).toHaveBeenCalledExactlyOnceWith(props.group.workspaceId)
|
||||
})
|
||||
|
||||
it('ungrouped bucket asks the global resource whether it may start a Session', () => {
|
||||
it('ungrouped bucket offers no New Session and asks no access', () => {
|
||||
const group: GroupNode = {
|
||||
key: 'ungrouped', workspaceId: undefined, cwd: undefined, createdAt: undefined, label: '',
|
||||
sessionCount: 0, expanded: false, containsCurrent: false, sessions: [],
|
||||
}
|
||||
const useRemoteAccess = vi.fn((action: string) => action !== 'session/create')
|
||||
const useWorkspaceAccess = vi.fn(() => true)
|
||||
render(<ProjectRowItem group={group} onToggle={vi.fn()} onCreate={vi.fn()} t={t}
|
||||
useRemoteAccess={useRemoteAccess} useWorkspaceAccess={useWorkspaceAccess} />)
|
||||
expect(useRemoteAccess).toHaveBeenCalledWith('session/create')
|
||||
useWorkspaceAccess={useWorkspaceAccess} />)
|
||||
expect(useWorkspaceAccess).not.toHaveBeenCalled()
|
||||
expect(screen.queryByRole('button', { name: /新建会话/ })).toBeNull()
|
||||
expect(fireEvent.contextMenu(screen.getByRole('treeitem'))).toBe(true)
|
||||
|
||||
@@ -1371,18 +1371,15 @@ describe('WorkspaceBrowser', () => {
|
||||
expect(startSession).toHaveBeenCalledWith(wid('alpha'))
|
||||
})
|
||||
|
||||
it('auto-expands the Ungrouped bucket for a loose current session; its header has no menu and its + is inert', () => {
|
||||
const startSession = vi.fn()
|
||||
it('auto-expands the Ungrouped bucket for a loose current session; its header has neither menu nor +', () => {
|
||||
mount({
|
||||
useSessions: hook(sessionState([summary('loose', 1)], { main: sid('loose') })),
|
||||
useWorkspaces: hook(workspaceState([workspace('alpha', [])])),
|
||||
startSession,
|
||||
})
|
||||
// The loose session's group is UNGROUPED_KEY: expanded by the effect.
|
||||
expect(screen.getByText('loose')).toBeTruthy()
|
||||
expect(screen.queryByRole('button', { name: '工作区“未分组”的操作' })).toBeNull()
|
||||
fireEvent.click(screen.getByRole('button', { name: '在“未分组”中新建会话' }))
|
||||
expect(startSession).not.toHaveBeenCalled()
|
||||
expect(screen.queryByRole('button', { name: '在“未分组”中新建会话' })).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps an already-expanded group when the selection moves within it', () => {
|
||||
|
||||
Reference in new issue
Block a user