fix: 项目可从分组拖出(未分类桶为空时拖拽中也显示 + 菜单移出对规则分类项目开放)
- 根因:未分类桶空时不渲染(无拖拽目标)+ 菜单「移到未分类」仅对有 assignment 的项目显示 → 规则分类项目两条移出路径全断 - tree.ts 新增 withDraggingUncategorized:拖拽中未分类桶缺失时临时渲染 折叠空桶作移出落点,dragend/drop 即隐藏;单测 3 例 - 菜单移出条件改为 resolveCategory !== undefined(任何分组内项目可用, 未分类桶内不显示),hasOverride 改名 canMoveOut - 验证脚本:cat2 改用手动分组、规则分类按 hidden 过滤(用户环境已隐藏 「个人项目」),新增拖出断言 4 项;确认 manualSaving 防重入正常 - 单测 68/68,真机 CDP 34/34,零侵入 + 现场恢复
This commit is contained in:
parent
226e21f7a1
commit
61717b2be9
|
|
@ -43,6 +43,9 @@
|
|||
- **Drag projects into groups**: drop on any group row or on a project row inside a group
|
||||
(cross-group move = overrides the rule classification); drop on "未分类" or use the menu
|
||||
"移到未分类" = **forced uncategorized** (rule matches are ignored)
|
||||
- **Drag projects OUT of a group**: even when every project is grouped (the uncategorized
|
||||
bucket is empty and hidden at rest), the bucket **appears while dragging** so you can
|
||||
always drag a project out; rule-classified projects also have the "移到未分类" menu item
|
||||
- **Reorder projects inside a group**: top half of a project row = insert before it,
|
||||
bottom half = insert after it
|
||||
- **Reorder groups**: group rows are draggable — top half of another group row = move before it,
|
||||
|
|
@ -281,7 +284,10 @@ scripts/
|
|||
- v0.4 real-browser verification 30/30 (added: insertion indicator, project/group
|
||||
**downward drag** (bottom half → insert after the target), group upward drag (top half →
|
||||
move before the target); scene restored).
|
||||
- 65 unit tests green (vitest: `core` / `manual` / `tree` / `store`).
|
||||
- v0.4.1 real-browser verification 34/34 (added: dragging projects OUT of a group —
|
||||
the empty uncategorized bucket appears while dragging; drop on it = forced
|
||||
uncategorized; rule-classified projects get the "移到未分类" menu item).
|
||||
- 68 unit tests green (vitest: `core` / `manual` / `tree` / `store`).
|
||||
- Reproducible automated verification: `node scripts/verify-groups.mjs` (host restarted).
|
||||
|
||||
## License
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ DeepSeek峰谷小组件 等)归入一个「DSH 插件」分类文件夹,点
|
|||
### 拖拽归类 + 排序
|
||||
- **拖项目进分组**:拖到任意分组行 / 分组内项目行即移入(跨组移动 = 覆盖规则归类);
|
||||
拖到「未分类」或菜单「移到未分类」= **强制归入未分类**(规则匹配也无效)
|
||||
- **从分组拖出**:即使所有项目都在分组里(未分类桶为空),**拖拽中未分类桶也会
|
||||
临时显示**,随时可把项目拖出分组;规则分类里的项目行菜单同样有「移到未分类」
|
||||
- **项目组内排序**:拖到项目行上半 = 插到它前面、下半 = 插到它后面
|
||||
- **分组排序**:分组行可拖动,拖到另一分组行上半 = 移到它前面、下半 = 移到它后面
|
||||
- **插入位置指示线**:拖动中实时显示 2px 指示线(行上/下方),松手落点所见即所得
|
||||
|
|
@ -263,7 +265,9 @@ scripts/
|
|||
菜单/重命名/删除回未分类/置底/现场恢复,零侵入断言)。
|
||||
- v0.4 真机验证 30/30(新增:插入指示线、项目/分组**向下拖**(行下半 → 插到目标
|
||||
之后)、分组向上拖(行上半 → 移到目标之前);现场恢复通过)。
|
||||
- 单测 65 用例全绿(vitest:`core` / `manual` / `tree` / `store`)。
|
||||
- v0.4.1 真机验证 34/34(新增:**从分组拖出**——未分类桶为空时拖拽中也显示,
|
||||
拖到其上 = 强制未分类;规则分类项目行也有「移到未分类」菜单)。
|
||||
- 单测 68 用例全绿(vitest:`core` / `manual` / `tree` / `store`)。
|
||||
- 可复跑的自动化真机验证:`node scripts/verify-groups.mjs`(需 host 已重启)。
|
||||
|
||||
## License
|
||||
|
|
|
|||
|
|
@ -320,6 +320,24 @@ window.__ModuleLoader__.load({
|
|||
return a.id < b.id ? -1 : 1;
|
||||
}
|
||||
/**
|
||||
* While a drag is in progress, the empty uncategorized bucket must still
|
||||
* render as a drop target — otherwise a project can never be dragged OUT of a
|
||||
* group when every project is grouped (the bucket hides when empty). Appends
|
||||
* a collapsed empty uncategorized node when the bucket is absent; never
|
||||
* duplicates an existing one. Pure; the caller decides when a drag is active.
|
||||
*/
|
||||
function withDraggingUncategorized(groups, dragging) {
|
||||
if (!dragging) return groups;
|
||||
if (groups.some((g) => g.key === UNCATEGORIZED_KEY)) return groups;
|
||||
return [...groups, {
|
||||
key: UNCATEGORIZED_KEY,
|
||||
label: UNCATEGORIZED_LABEL,
|
||||
expanded: false,
|
||||
containsCurrent: false,
|
||||
workspaces: []
|
||||
}];
|
||||
}
|
||||
/**
|
||||
* Compute the matched-session set: immediate title/Workspace substring matches
|
||||
* from the local list, merged with ranked Host content matches. The consumer
|
||||
* (SearchBody) derives the pruned three-level tree from these ids.
|
||||
|
|
@ -559,10 +577,10 @@ window.__ModuleLoader__.load({
|
|||
});
|
||||
}
|
||||
/** One workspace folder row inside a category: draggable source + drop target. */
|
||||
function WorkspaceRow({ node, t, onToggle, onNewSession, onRename, onDelete, hasOverride = false, onMoveOut, dropActive = false, insertLine, onRowDragOver, onRowDragLeave, onRowDrop, onDragStartExtra }) {
|
||||
function WorkspaceRow({ node, t, onToggle, onNewSession, onRename, onDelete, canMoveOut = false, onMoveOut, dropActive = false, insertLine, onRowDragOver, onRowDragLeave, onRowDrop, onDragStartExtra }) {
|
||||
const [menuOpen, setMenuOpen] = (0, react.useState)(false);
|
||||
const menuItems = [
|
||||
...hasOverride && onMoveOut !== void 0 ? [{
|
||||
...canMoveOut && onMoveOut !== void 0 ? [{
|
||||
id: "moveOut",
|
||||
label: t("workspace.moveToUncategorized"),
|
||||
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconFolderOpenOutline16, { size: 16 })
|
||||
|
|
@ -943,6 +961,7 @@ window.__ModuleLoader__.load({
|
|||
]);
|
||||
const expandedCategories = (0, react.useMemo)(() => Object.entries(categoryExpansion).filter(([, v]) => v).map(([k]) => k), [categoryExpansion]);
|
||||
const expandedWorkspaces = (0, react.useMemo)(() => Object.entries(workspaceExpansion).filter(([, v]) => v).map(([k]) => k), [workspaceExpansion]);
|
||||
const [dragging, setDragging] = (0, react.useState)(false);
|
||||
const groups = (0, react.useMemo)(() => deriveGroups(list, workspaces, archivedSessionIds, config, {
|
||||
expandedCategories,
|
||||
expandedWorkspaces
|
||||
|
|
@ -955,6 +974,7 @@ window.__ModuleLoader__.load({
|
|||
expandedCategories,
|
||||
expandedWorkspaces
|
||||
]);
|
||||
const displayGroups = (0, react.useMemo)(() => withDraggingUncategorized(groups, dragging), [groups, dragging]);
|
||||
const [adding, setAdding] = (0, react.useState)(false);
|
||||
const [addError, setAddError] = (0, react.useState)(null);
|
||||
const [addErrorOpen, setAddErrorOpen] = (0, react.useState)(false);
|
||||
|
|
@ -1119,7 +1139,10 @@ window.__ModuleLoader__.load({
|
|||
};
|
||||
const [dragIndicator, setDragIndicator] = (0, react.useState)(null);
|
||||
(0, react.useEffect)(() => {
|
||||
const clear = () => setDragIndicator(null);
|
||||
const clear = () => {
|
||||
setDragIndicator(null);
|
||||
setDragging(false);
|
||||
};
|
||||
document.addEventListener("dragend", clear);
|
||||
return () => {
|
||||
document.removeEventListener("dragend", clear);
|
||||
|
|
@ -1202,6 +1225,7 @@ window.__ModuleLoader__.load({
|
|||
const onDropRow = (categoryKey, row) => (event) => {
|
||||
event.preventDefault();
|
||||
setDragIndicator(null);
|
||||
setDragging(false);
|
||||
const draggedCategory = event.dataTransfer.getData(DND_CATEGORY_TYPE);
|
||||
if (draggedCategory !== "") {
|
||||
const rect = event.currentTarget.getBoundingClientRect();
|
||||
|
|
@ -1242,6 +1266,7 @@ window.__ModuleLoader__.load({
|
|||
setDragIndicator(null);
|
||||
};
|
||||
const onDragStartWorkspace = (workspaceId) => () => {
|
||||
setDragging(true);
|
||||
const workspace = workspaces.find((w) => w.workspaceId === workspaceId);
|
||||
const sourceKey = workspace === void 0 ? void 0 : resolveCategory(config, manual, workspace.workspaceId, workspace.path, workspace.title);
|
||||
for (const key of Object.keys(categoryExpansion)) {
|
||||
|
|
@ -1254,6 +1279,7 @@ window.__ModuleLoader__.load({
|
|||
const onDragStartCategory = (categoryKey) => (event) => {
|
||||
event.dataTransfer.setData(DND_CATEGORY_TYPE, categoryKey);
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
setDragging(true);
|
||||
for (const key of Object.keys(categoryExpansion)) if (categoryExpansion[key]) actions.setCategoryExpanded(key, false);
|
||||
};
|
||||
const now = Date.now();
|
||||
|
|
@ -1394,7 +1420,7 @@ window.__ModuleLoader__.load({
|
|||
children: [groups.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
||||
className: "wgEmpty",
|
||||
children: workspacePhase === "ready" ? t("empty.noWorkspaces") : t("empty.none")
|
||||
}), groups.map((category) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CategorySection, {
|
||||
}), displayGroups.map((category) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CategorySection, {
|
||||
category,
|
||||
current,
|
||||
now,
|
||||
|
|
@ -1447,7 +1473,10 @@ window.__ModuleLoader__.load({
|
|||
onMoveOut: (workspaceId) => {
|
||||
moveWorkspaceTo(workspaceId, UNCATEGORIZED_KEY);
|
||||
},
|
||||
hasOverride: (workspaceId) => Object.hasOwn(manual.assignments, workspaceId)
|
||||
canMoveOut: (workspaceId) => {
|
||||
const workspace = workspaces.find((w) => w.workspaceId === workspaceId);
|
||||
return workspace !== void 0 && resolveCategory(config, manual, workspace.workspaceId, workspace.path, workspace.title) !== void 0;
|
||||
}
|
||||
}, category.key))]
|
||||
})
|
||||
]
|
||||
|
|
@ -1660,7 +1689,7 @@ window.__ModuleLoader__.load({
|
|||
return resolveCategory(config, manual, workspace.workspaceId, workspace.path, workspace.title);
|
||||
}
|
||||
/** One category section: header row + expanded workspace folders. */
|
||||
function CategorySection({ category, current, now, t, manageable, dragIndicator, onDragOverRow, onDragLeaveRow, onDropRow, onDragStartCategory, onDragStartWorkspace, onToggleCategory, onToggleWorkspace, onNewSession, onOpen, onRenameRequest, onDeleteRequest, onSessionRename, onSessionArchive, onFork, onGroupRename, onGroupDelete, onMoveOut, hasOverride }) {
|
||||
function CategorySection({ category, current, now, t, manageable, dragIndicator, onDragOverRow, onDragLeaveRow, onDropRow, onDragStartCategory, onDragStartWorkspace, onToggleCategory, onToggleWorkspace, onNewSession, onOpen, onRenameRequest, onDeleteRequest, onSessionRename, onSessionArchive, onFork, onGroupRename, onGroupDelete, onMoveOut, canMoveOut }) {
|
||||
const categoryLine = dragIndicator?.mode === "line" && dragIndicator.row.kind === "category" && dragIndicator.row.key === category.key ? dragIndicator.before ? "before" : "after" : void 0;
|
||||
const categoryInto = dragIndicator?.mode === "into" && dragIndicator.categoryKey === category.key;
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||
|
|
@ -1704,7 +1733,7 @@ window.__ModuleLoader__.load({
|
|||
onDelete: () => {
|
||||
onDeleteRequest(workspace.workspaceId, workspace.label);
|
||||
},
|
||||
hasOverride: hasOverride(workspace.workspaceId),
|
||||
canMoveOut: canMoveOut(workspace.workspaceId),
|
||||
onMoveOut: () => {
|
||||
onMoveOut(workspace.workspaceId);
|
||||
},
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -52,15 +52,15 @@ export declare function CategoryRow({ node, t, onToggle, onRename, onDelete, dro
|
|||
onDragStartCategory?: (event: DragEvent) => void;
|
||||
} & RowDropProps): import("react").JSX.Element;
|
||||
/** One workspace folder row inside a category: draggable source + drop target. */
|
||||
export declare function WorkspaceRow({ node, t, onToggle, onNewSession, onRename, onDelete, hasOverride, onMoveOut, dropActive, insertLine, onRowDragOver, onRowDragLeave, onRowDrop, onDragStartExtra }: {
|
||||
export declare function WorkspaceRow({ node, t, onToggle, onNewSession, onRename, onDelete, canMoveOut, onMoveOut, dropActive, insertLine, onRowDragOver, onRowDragLeave, onRowDrop, onDragStartExtra }: {
|
||||
node: WorkspaceGroupNode;
|
||||
t: T;
|
||||
onToggle: () => void;
|
||||
onNewSession: () => void;
|
||||
onRename: () => void;
|
||||
onDelete: () => void;
|
||||
/** Workspace has a manual group override — offer "move to uncategorized". */
|
||||
hasOverride?: boolean;
|
||||
/** Project currently sits inside a group — offer "move to uncategorized". */
|
||||
canMoveOut?: boolean;
|
||||
onMoveOut?: () => void;
|
||||
/** Extra dragstart hook (e.g. collapse all expanded projects while dragging). */
|
||||
onDragStartExtra?: () => void;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,14 @@ export declare function workspaceLabel(cwd: string | undefined): string;
|
|||
* empty; empty rule buckets stay hidden.
|
||||
*/
|
||||
export declare function deriveGroups(list: SessionListState, workspaces: readonly WorkspaceView[], archivedSessionIds: readonly SessionId[], config: GroupsConfig, view: GroupsTreeView, manual: ManualGroups): CategoryNode[];
|
||||
/**
|
||||
* While a drag is in progress, the empty uncategorized bucket must still
|
||||
* render as a drop target — otherwise a project can never be dragged OUT of a
|
||||
* group when every project is grouped (the bucket hides when empty). Appends
|
||||
* a collapsed empty uncategorized node when the bucket is absent; never
|
||||
* duplicates an existing one. Pure; the caller decides when a drag is active.
|
||||
*/
|
||||
export declare function withDraggingUncategorized(groups: readonly CategoryNode[], dragging: boolean): readonly CategoryNode[];
|
||||
/** Bounded set of matched sessions plus content snippets (feeds the search tree). */
|
||||
export interface SearchMatchSet {
|
||||
/** Session ids that matched (local metadata hits + Host content hits). */
|
||||
|
|
|
|||
|
|
@ -196,11 +196,14 @@ async function main() {
|
|||
report('非法 PUT(未知分类)返回 400', bad.status === 400, `status=${bad.status}`)
|
||||
|
||||
// ---- 5.5 v0.3:组内排序 + 拖动时其他分组项目收起 ------------------------
|
||||
const ruleKeys = snapshot.categories?.map(c => c.name) ?? []
|
||||
// cat1 = first VISIBLE rule category (hidden ones don't render); cat2 =
|
||||
// the manual 验证分组 created in the v0.2 flow (already holds one project).
|
||||
const hiddenSet = new Set(snapshot.manual?.hidden ?? [])
|
||||
const ruleKeys = (snapshot.categories ?? []).map(c => c.name).filter(n => !hiddenSet.has(n))
|
||||
const cat1 = ruleKeys[0]
|
||||
const cat2 = ruleKeys[1]
|
||||
if (cat1 === undefined || cat2 === undefined) {
|
||||
report('v0.3 需两个规则分类(跳过排序/收起断言)', false, `categories=${JSON.stringify(ruleKeys)}`)
|
||||
const cat2 = groupName
|
||||
if (cat1 === undefined) {
|
||||
report('v0.3 需至少一个可见规则分类(跳过排序/收起断言)', false, `categories=${JSON.stringify(ruleKeys)}`)
|
||||
} else {
|
||||
// Expand both rule categories so their project rows are visible.
|
||||
const expandCat = (key) => evaluate(`(() => {
|
||||
|
|
@ -287,6 +290,57 @@ async function main() {
|
|||
return !!first && first.getAttribute('data-wsid') === ${JSON.stringify(reorderAfter.targetWsid)}
|
||||
})()`))
|
||||
|
||||
// ---- v0.4.1:从分组拖出 —— 未分类桶为空时拖拽中也显示为落点 ----
|
||||
const uncatBefore = await evaluate(`!!document.querySelector('.wgCategoryRow[data-wg-category="未分类"]')`)
|
||||
const dragOut = await evaluate(`(() => {
|
||||
const s1 = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(cat1)}]')?.parentElement
|
||||
if (!s1) return { error: 'no section' }
|
||||
const source = s1.querySelector('.wgProjectRow')
|
||||
if (!source) return { error: 'no project row' }
|
||||
const dt = new DataTransfer()
|
||||
source.dispatchEvent(new DragEvent('dragstart', { bubbles: true, cancelable: true, dataTransfer: dt }))
|
||||
window.__wgDt = dt // stash for the drop step
|
||||
return { wsid: source.getAttribute('data-wsid') }
|
||||
})()`)
|
||||
report('拖拽中未分类桶可见(原为空也显示)', !!dragOut.wsid && await waitFor(`!!document.querySelector('.wgCategoryRow[data-wg-category="未分类"]')`, 5000),
|
||||
`拖拽前未分类桶存在=${uncatBefore}`)
|
||||
const droppedOut = await evaluate(`(() => {
|
||||
const target = document.querySelector('.wgCategoryRow[data-wg-category="未分类"]')
|
||||
if (!target || !window.__wgDt) return false
|
||||
target.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, dataTransfer: window.__wgDt }))
|
||||
target.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer: window.__wgDt }))
|
||||
return true
|
||||
})()`)
|
||||
report('拖到未分类 = 从分组拖出(assignments=null 落盘)', droppedOut && !!dragOut.wsid && await waitFor(`fetch(${JSON.stringify(BASE)} + '/workspace-groups/config', { cache: 'no-store' }).then(r => r.json()).then(d => d.manual?.assignments?.[${JSON.stringify(dragOut.wsid)}] === null)`))
|
||||
await evaluate(`(() => {
|
||||
const row = document.querySelector('.wgCategoryRow[data-wg-category="未分类"]')
|
||||
if (row && row.getAttribute('aria-expanded') === 'false') row.click()
|
||||
return true
|
||||
})()`)
|
||||
report('拖出的项目出现在未分类桶', !!dragOut.wsid && await waitFor(`(() => {
|
||||
const s = document.querySelector('.wgCategoryRow[data-wg-category="未分类"]')?.parentElement
|
||||
return !!s && !!s.querySelector('.wgProjectRow[data-wsid=${JSON.stringify(dragOut.wsid ?? '')}]')
|
||||
})()`))
|
||||
|
||||
// ---- v0.4.1b:规则分类项目行菜单也提供「移到未分类」 ----
|
||||
const menuMoveOut = await evaluate(`(() => {
|
||||
const s1 = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(cat1)}]')?.parentElement
|
||||
const row = s1?.querySelector('.wgProjectRow')
|
||||
if (!row) return false
|
||||
row.querySelector('button[aria-label^="重命名 "]')?.click()
|
||||
return true
|
||||
})()`)
|
||||
report('规则分类项目行菜单出现', menuMoveOut && await waitFor(`[...document.querySelectorAll('button')].some(b => b.textContent.trim() === '移到未分类')`, 4000))
|
||||
// Close the menu (performs the move-out PUT) and let the async write
|
||||
// settle — the following group-reorder drops are rejected by the
|
||||
// manualSaving re-entrancy guard while a save is in flight.
|
||||
await evaluate(`(() => {
|
||||
const item = [...document.querySelectorAll('button')].find(b => b.textContent.trim() === '移到未分类')
|
||||
if (item) { item.click(); return true }
|
||||
return false
|
||||
})()`)
|
||||
await sleep(1000)
|
||||
|
||||
// ---- v0.4:分组拖动 — 下半 = 移到目标分组之后 ----
|
||||
const groupDown = await evaluate(`(() => {
|
||||
const source = document.querySelector('.wgCategoryRow[data-wg-category=${JSON.stringify(cat2)}]')
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import {
|
|||
} from '../core/matcher.ts'
|
||||
import { UNCATEGORIZED_LABEL, type GroupsConfig, type ManualGroups } from '../core/types.ts'
|
||||
import type { GroupsBrowserProps } from './contract.ts'
|
||||
import { deriveGroups, deriveSearchGroups, deriveSearchMatches, UNCATEGORIZED_KEY, type CategoryNode } from './tree.ts'
|
||||
import { deriveGroups, deriveSearchGroups, deriveSearchMatches, UNCATEGORIZED_KEY, withDraggingUncategorized, type CategoryNode } from './tree.ts'
|
||||
import { CategoryRow, DND_CATEGORY_TYPE, DND_WORKSPACE_TYPE, hasPluginDragType, SessionRow, WorkspaceRow } from './rows.tsx'
|
||||
import css from './styles.css?inline'
|
||||
|
||||
|
|
@ -275,6 +275,9 @@ export function GroupsBrowser({
|
|||
() => Object.entries(workspaceExpansion).filter(([, v]) => v).map(([k]) => k),
|
||||
[workspaceExpansion],
|
||||
)
|
||||
// Whether a drag is in progress (drives the always-visible uncategorized
|
||||
// drop target while dragging).
|
||||
const [dragging, setDragging] = useState(false)
|
||||
const groups = useMemo(
|
||||
() => deriveGroups(list, workspaces, archivedSessionIds, config, {
|
||||
expandedCategories,
|
||||
|
|
@ -282,6 +285,13 @@ export function GroupsBrowser({
|
|||
}, manual),
|
||||
[list, workspaces, archivedSessionIds, config, manual, expandedCategories, expandedWorkspaces],
|
||||
)
|
||||
// While a drag is active, keep the uncategorized bucket visible even when
|
||||
// empty — it is the only way to drag a project OUT of a group when every
|
||||
// project is currently grouped.
|
||||
const displayGroups = useMemo(
|
||||
() => withDraggingUncategorized(groups, dragging),
|
||||
[groups, dragging],
|
||||
)
|
||||
|
||||
// Add workspace flow: self-contained (no directory-flow hole dependency).
|
||||
const [adding, setAdding] = useState(false)
|
||||
|
|
@ -492,7 +502,7 @@ export function GroupsBrowser({
|
|||
|
||||
// Cancel any stale indicator when a drag ends outside a row (or is aborted).
|
||||
useEffect(() => {
|
||||
const clear = () => setDragIndicator(null)
|
||||
const clear = () => { setDragIndicator(null); setDragging(false) }
|
||||
document.addEventListener('dragend', clear)
|
||||
return () => { document.removeEventListener('dragend', clear) }
|
||||
}, [])
|
||||
|
|
@ -567,6 +577,7 @@ export function GroupsBrowser({
|
|||
const onDropRow = (categoryKey: string, row: DropRowRef) => (event: DragEvent): void => {
|
||||
event.preventDefault()
|
||||
setDragIndicator(null)
|
||||
setDragging(false)
|
||||
const draggedCategory = event.dataTransfer.getData(DND_CATEGORY_TYPE)
|
||||
if (draggedCategory !== '') {
|
||||
// Group reorder: only category rows are targets (project rows fold
|
||||
|
|
@ -621,6 +632,7 @@ export function GroupsBrowser({
|
|||
// expansion collapses — the source category stays open so dropping on a
|
||||
// sibling row can reorder inside it.
|
||||
const onDragStartWorkspace = (workspaceId: string) => (): void => {
|
||||
setDragging(true)
|
||||
const workspace = workspaces.find(w => w.workspaceId === workspaceId)
|
||||
const sourceKey = workspace === undefined
|
||||
? undefined
|
||||
|
|
@ -640,6 +652,7 @@ export function GroupsBrowser({
|
|||
const onDragStartCategory = (categoryKey: string) => (event: DragEvent): void => {
|
||||
event.dataTransfer.setData(DND_CATEGORY_TYPE, categoryKey)
|
||||
event.dataTransfer.effectAllowed = 'move'
|
||||
setDragging(true)
|
||||
for (const key of Object.keys(categoryExpansion)) {
|
||||
if (categoryExpansion[key]) actions.setCategoryExpanded(key, false)
|
||||
}
|
||||
|
|
@ -763,7 +776,7 @@ export function GroupsBrowser({
|
|||
{groups.length === 0 && (
|
||||
<div className="wgEmpty">{workspacePhase === 'ready' ? t('empty.noWorkspaces') : t('empty.none')}</div>
|
||||
)}
|
||||
{groups.map((category) => (
|
||||
{displayGroups.map((category) => (
|
||||
<CategorySection
|
||||
key={category.key}
|
||||
category={category}
|
||||
|
|
@ -803,7 +816,16 @@ export function GroupsBrowser({
|
|||
setGroupDeleteError(null)
|
||||
}}
|
||||
onMoveOut={(workspaceId) => { void moveWorkspaceTo(workspaceId, UNCATEGORIZED_KEY) }}
|
||||
hasOverride={(workspaceId) => Object.hasOwn(manual.assignments, workspaceId)}
|
||||
canMoveOut={(workspaceId) => {
|
||||
// The menu "移到未分类" is offered for any project that
|
||||
// currently sits inside a group (rule-classified or manual) —
|
||||
// not just overridden ones. Projects already in the
|
||||
// uncategorized bucket (resolveCategory === undefined) don't
|
||||
// need it.
|
||||
const workspace = workspaces.find(w => w.workspaceId === workspaceId)
|
||||
return workspace !== undefined
|
||||
&& resolveCategory(config, manual, workspace.workspaceId, workspace.path, workspace.title) !== undefined
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -952,7 +974,7 @@ function categoriesForCurrent(
|
|||
}
|
||||
|
||||
/** One category section: header row + expanded workspace folders. */
|
||||
function CategorySection({ category, current, now, t, manageable, dragIndicator, onDragOverRow, onDragLeaveRow, onDropRow, onDragStartCategory, onDragStartWorkspace, onToggleCategory, onToggleWorkspace, onNewSession, onOpen, onRenameRequest, onDeleteRequest, onSessionRename, onSessionArchive, onFork, onGroupRename, onGroupDelete, onMoveOut, hasOverride }: {
|
||||
function CategorySection({ category, current, now, t, manageable, dragIndicator, onDragOverRow, onDragLeaveRow, onDropRow, onDragStartCategory, onDragStartWorkspace, onToggleCategory, onToggleWorkspace, onNewSession, onOpen, onRenameRequest, onDeleteRequest, onSessionRename, onSessionArchive, onFork, onGroupRename, onGroupDelete, onMoveOut, canMoveOut }: {
|
||||
category: CategoryNode
|
||||
current: SessionId | undefined
|
||||
now: number
|
||||
|
|
@ -978,7 +1000,7 @@ function CategorySection({ category, current, now, t, manageable, dragIndicator,
|
|||
onGroupRename: () => void
|
||||
onGroupDelete: () => void
|
||||
onMoveOut: (workspaceId: WorkspaceId) => void
|
||||
hasOverride: (workspaceId: WorkspaceId) => boolean
|
||||
canMoveOut: (workspaceId: WorkspaceId) => boolean
|
||||
}) {
|
||||
const categoryLine = dragIndicator?.mode === 'line' && dragIndicator.row.kind === 'category' && dragIndicator.row.key === category.key
|
||||
? (dragIndicator.before ? 'before' : 'after')
|
||||
|
|
@ -1008,7 +1030,7 @@ function CategorySection({ category, current, now, t, manageable, dragIndicator,
|
|||
onNewSession={() => { onNewSession(workspace.workspaceId) }}
|
||||
onRename={() => { onRenameRequest(workspace.workspaceId, workspace.label) }}
|
||||
onDelete={() => { onDeleteRequest(workspace.workspaceId, workspace.label) }}
|
||||
hasOverride={hasOverride(workspace.workspaceId)}
|
||||
canMoveOut={canMoveOut(workspace.workspaceId)}
|
||||
onMoveOut={() => { onMoveOut(workspace.workspaceId) }}
|
||||
dropActive={false}
|
||||
{...(dragIndicator?.mode === 'line' && dragIndicator.row.kind === 'workspace' && dragIndicator.row.key === workspace.workspaceId
|
||||
|
|
|
|||
|
|
@ -163,22 +163,22 @@ export function CategoryRow({ node, t, onToggle, onRename, onDelete, dropActive
|
|||
}
|
||||
|
||||
/** One workspace folder row inside a category: draggable source + drop target. */
|
||||
export function WorkspaceRow({ node, t, onToggle, onNewSession, onRename, onDelete, hasOverride = false, onMoveOut, dropActive = false, insertLine, onRowDragOver, onRowDragLeave, onRowDrop, onDragStartExtra }: {
|
||||
export function WorkspaceRow({ node, t, onToggle, onNewSession, onRename, onDelete, canMoveOut = false, onMoveOut, dropActive = false, insertLine, onRowDragOver, onRowDragLeave, onRowDrop, onDragStartExtra }: {
|
||||
node: WorkspaceGroupNode
|
||||
t: T
|
||||
onToggle: () => void
|
||||
onNewSession: () => void
|
||||
onRename: () => void
|
||||
onDelete: () => void
|
||||
/** Workspace has a manual group override — offer "move to uncategorized". */
|
||||
hasOverride?: boolean
|
||||
/** Project currently sits inside a group — offer "move to uncategorized". */
|
||||
canMoveOut?: boolean
|
||||
onMoveOut?: () => void
|
||||
/** Extra dragstart hook (e.g. collapse all expanded projects while dragging). */
|
||||
onDragStartExtra?: () => void
|
||||
} & RowDropProps) {
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
const menuItems = [
|
||||
...(hasOverride && onMoveOut !== undefined
|
||||
...(canMoveOut && onMoveOut !== undefined
|
||||
? [{ id: 'moveOut', label: t('workspace.moveToUncategorized'), icon: <IconFolderOpenOutline16 size={16} /> }]
|
||||
: []),
|
||||
{ id: 'rename', label: t('workspace.rename'), icon: <IconEditOutline16 /> },
|
||||
|
|
|
|||
|
|
@ -226,6 +226,25 @@ function byRecency(a: SessionSummary, b: SessionSummary): number {
|
|||
return a.id < b.id ? -1 : 1
|
||||
}
|
||||
|
||||
/**
|
||||
* While a drag is in progress, the empty uncategorized bucket must still
|
||||
* render as a drop target — otherwise a project can never be dragged OUT of a
|
||||
* group when every project is grouped (the bucket hides when empty). Appends
|
||||
* a collapsed empty uncategorized node when the bucket is absent; never
|
||||
* duplicates an existing one. Pure; the caller decides when a drag is active.
|
||||
*/
|
||||
export function withDraggingUncategorized(
|
||||
groups: readonly CategoryNode[],
|
||||
dragging: boolean,
|
||||
): readonly CategoryNode[] {
|
||||
if (!dragging) return groups
|
||||
if (groups.some(g => g.key === UNCATEGORIZED_KEY)) return groups
|
||||
return [
|
||||
...groups,
|
||||
{ key: UNCATEGORIZED_KEY, label: UNCATEGORIZED_LABEL, expanded: false, containsCurrent: false, workspaces: [] },
|
||||
]
|
||||
}
|
||||
|
||||
/** Bounded set of matched sessions plus content snippets (feeds the search tree). */
|
||||
export interface SearchMatchSet {
|
||||
/** Session ids that matched (local metadata hits + Host content hits). */
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ vi.mock('@deepseek-ai/dsh-client-runtime/client', () => ({
|
|||
}))
|
||||
|
||||
import type { SessionListState, SessionSummary, WorkspaceView } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { deriveGroups } from '../src/client/tree.ts'
|
||||
import { deriveGroups, withDraggingUncategorized } from '../src/client/tree.ts'
|
||||
import { UNCATEGORIZED_LABEL, type GroupsConfig, type ManualGroups } from '../src/core/types.ts'
|
||||
|
||||
const CONFIG: GroupsConfig = {
|
||||
|
|
@ -161,3 +161,36 @@ describe('deriveGroups with the manual overlay', () => {
|
|||
expect(byLabel.get(UNCATEGORIZED_LABEL)?.workspaces.map(w => w.workspaceId)).toEqual(['ws-a', 'ws-c'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('withDraggingUncategorized', () => {
|
||||
const ws = [
|
||||
workspace('ws-a', '/Users/zcol/Project/SomePlugin', 'DSH插件Demo'),
|
||||
workspace('ws-b', '/Users/zcol/Project/MyDocs', 'MyDocs'),
|
||||
]
|
||||
const groups = deriveGroups(listState(ws), ws, [], CONFIG, VIEW, { categories: [], assignments: {} })
|
||||
|
||||
it('leaves the tree untouched when no drag is active', () => {
|
||||
expect(withDraggingUncategorized(groups, false)).toBe(groups)
|
||||
})
|
||||
|
||||
it('appends a collapsed empty uncategorized bucket while dragging when absent', () => {
|
||||
// All workspaces are grouped — the idle tree has no uncategorized section.
|
||||
expect(groups.some(g => g.key === UNCATEGORIZED_LABEL)).toBe(false)
|
||||
const during = withDraggingUncategorized(groups, true)
|
||||
expect(during.length).toBe(groups.length + 1)
|
||||
const bucket = during[during.length - 1]
|
||||
expect(bucket?.key).toBe(UNCATEGORIZED_LABEL)
|
||||
expect(bucket?.expanded).toBe(false)
|
||||
expect(bucket?.workspaces).toEqual([])
|
||||
})
|
||||
|
||||
it('never duplicates an existing uncategorized bucket', () => {
|
||||
const withBucket = deriveGroups(listState(ws), ws, [], CONFIG, VIEW, {
|
||||
categories: [], assignments: { 'ws-b': null },
|
||||
})
|
||||
expect(withBucket.some(g => g.key === UNCATEGORIZED_LABEL)).toBe(true)
|
||||
const during = withDraggingUncategorized(withBucket, true)
|
||||
expect(during).toBe(withBucket)
|
||||
expect(during.filter(g => g.key === UNCATEGORIZED_LABEL)).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue