✨ feat(vscode): 支持重置回待办并修好待办依赖拖拽
This commit is contained in:
1 parent
75dec8fa90
commit
6c05b7f7e3
12 files changed
+717
-164
No files matched your search
@@ -42,6 +42,7 @@ interface BottomTabsProps {
|
||||
onMergeBranch: (issueNumber: number, branch: string) => void
|
||||
onDeleteIssue?: (issueNumber: number) => void
|
||||
onCloseIssue: (issueNumber: number) => void
|
||||
onResetToTodo: (issueNumber: number) => void
|
||||
onCloseSessionTab: (issueNumber: number, kind: 'brainstorm' | 'implement' | 'review' | 'test') => void
|
||||
onStartBrainstormSession: (issueNumber: number) => void
|
||||
onUpdateAutoReview: (issueNumber: number, value: boolean) => void
|
||||
@@ -128,6 +129,7 @@ export function BottomTabs(props: BottomTabsProps) {
|
||||
onMergeBranch={props.onMergeBranch}
|
||||
onDeleteIssue={props.onDeleteIssue}
|
||||
onCloseIssue={props.onCloseIssue}
|
||||
onResetToTodo={props.onResetToTodo}
|
||||
onCloseSessionTab={props.onCloseSessionTab}
|
||||
onStartBrainstormSession={props.onStartBrainstormSession}
|
||||
onUpdateAutoReview={props.onUpdateAutoReview}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { useMemo, useRef } from 'react'
|
||||
import { CircleSlash, ExternalLink, GitMerge, Play, Terminal, Trash2, X } from 'lucide-react'
|
||||
import { CircleSlash, ExternalLink, GitMerge, Play, RotateCcw, Terminal, Trash2, X } from 'lucide-react'
|
||||
import type { ClaudeProfile } from '../hooks/useIssues'
|
||||
import type { Issue, IssueColumn } from '../types'
|
||||
import { COLUMN_LABELS, COLUMN_ORDER } from '../types'
|
||||
@@ -68,6 +68,8 @@ interface IssueDetailPanelProps {
|
||||
onDeleteIssue?: (issueNumber: number) => void
|
||||
/** 关闭 Gitea 工单,不清理本地会话、worktree、PR 或分支。 */
|
||||
onCloseIssue: (issueNumber: number) => void
|
||||
/** 将实施中 / 审查中的工单重置回待办(清 worktree / 未合并 PR / feature 分支)。 */
|
||||
onResetToTodo: (issueNumber: number) => void
|
||||
/** Close the matching session terminal tab. The extension watches
|
||||
* onDidCloseTerminal and clears the corresponding `*TabOpen` flag, which
|
||||
* makes the X button vanish on its own. */
|
||||
@@ -117,6 +119,7 @@ export function IssueDetailPanel({
|
||||
onMergeBranch,
|
||||
onDeleteIssue,
|
||||
onCloseIssue,
|
||||
onResetToTodo,
|
||||
onCloseSessionTab,
|
||||
onStartBrainstormSession,
|
||||
onUpdateAutoReview,
|
||||
@@ -572,6 +575,17 @@ export function IssueDetailPanel({
|
||||
avoid acting on a gitea issue of the same number. */}
|
||||
{issue.source !== 'youtrack' && (
|
||||
<>
|
||||
{(issue.column === 'in-progress' || issue.column === 'review') && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onResetToTodo(issue.number)}
|
||||
title="重置为待办"
|
||||
aria-label="重置为待办"
|
||||
className="inline-flex shrink-0 items-center justify-center rounded border border-[var(--vscode-panel-border)] p-1 text-xs text-[var(--vscode-foreground)] hover:border-yellow-500/60 hover:bg-yellow-500/10 hover:text-yellow-500"
|
||||
>
|
||||
<RotateCcw className="size-3.5" />
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onCloseIssue(issue.number)}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import type { CollisionDetection, DragEndEvent, DragStartEvent } from '@dnd-kit/core'
|
||||
import type { Issue, IssueColumn } from '../types'
|
||||
import {
|
||||
closestCenter,
|
||||
DndContext,
|
||||
DragOverlay,
|
||||
KeyboardSensor,
|
||||
PointerSensor,
|
||||
pointerWithin,
|
||||
useSensor,
|
||||
useSensors,
|
||||
} from '@dnd-kit/core'
|
||||
import type { DragEndEvent, DragStartEvent } from '@dnd-kit/core'
|
||||
import {
|
||||
SortableContext,
|
||||
arrayMove,
|
||||
SortableContext,
|
||||
sortableKeyboardCoordinates,
|
||||
verticalListSortingStrategy,
|
||||
} from '@dnd-kit/sortable'
|
||||
import { IssueCard } from './IssueCard'
|
||||
import { KanbanColumn } from './KanbanColumn'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { isIssueLocked } from '../lib/dependencies'
|
||||
import { compareIssuesInColumn } from '../lib/issueSort'
|
||||
import type { Issue, IssueColumn } from '../types'
|
||||
import { isColumnId, resolveKanbanDrag } from '../lib/kanbanDrag'
|
||||
import { COLUMN_ORDER } from '../types'
|
||||
import { IssueCard } from './IssueCard'
|
||||
import { KanbanColumn } from './KanbanColumn'
|
||||
|
||||
interface KanbanBoardProps {
|
||||
issues: Issue[]
|
||||
@@ -28,27 +31,18 @@ interface KanbanBoardProps {
|
||||
onCreateIssue?: () => void
|
||||
selectedId?: string | null
|
||||
onSelectIssue?: (id: string | null) => void
|
||||
/**
|
||||
* Called when a card moves to a new column via drag-and-drop, in addition
|
||||
* to the optimistic `onIssuesChange`. Currently only invoked for moves
|
||||
* targeting `done`; other column changes remain client-visual-only.
|
||||
*/
|
||||
onColumnChange?: (issueNumber: number, toColumn: IssueColumn, source?: 'gitea' | 'youtrack', externalId?: string) => void
|
||||
/**
|
||||
* Called when a drag gesture establishes a new prerequisite relationship
|
||||
* (drop onto another todo card's middle 1/3) or moves to a sibling whose
|
||||
* parent differs from the active card's current parent.
|
||||
*/
|
||||
onDependencySet?: (issueNumber: number, prerequisiteNumber: number) => void
|
||||
/**
|
||||
* Called when a drag gesture clears an existing prerequisite (e.g. drop
|
||||
* onto the todo column's empty area, or onto a sibling at root level).
|
||||
*/
|
||||
onDependencyClear?: (issueNumber: number, prerequisiteNumber: number) => void
|
||||
}
|
||||
|
||||
function isColumnId(id: string): id is IssueColumn {
|
||||
return (COLUMN_ORDER as string[]).includes(id)
|
||||
const kanbanCollisionDetection: CollisionDetection = (args) => {
|
||||
const pointerHits = pointerWithin(args)
|
||||
if (pointerHits.length > 0) {
|
||||
const cardHits = pointerHits.filter(c => !isColumnId(String(c.id)))
|
||||
return cardHits.length > 0 ? cardHits : pointerHits
|
||||
}
|
||||
return closestCenter(args)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,174 +146,73 @@ export function KanbanBoard({
|
||||
setActiveId(String(event.active.id))
|
||||
}
|
||||
|
||||
/**
|
||||
* Classify the drop position relative to the `over` card. Middle 1/3
|
||||
* means nest (set prerequisite); the upper/lower 2/3 means sibling reorder.
|
||||
* The 1/3-2/3 split is intentionally wider than 1/4-1/2-1/4 because the
|
||||
* sortable strategy reflows during drag, so the user needs more room.
|
||||
*/
|
||||
function detectDropZone(event: DragEndEvent): 'middle' | 'edge' {
|
||||
const activeRect = event.active.rect.current.translated
|
||||
const overRect = event.over?.rect
|
||||
if (!activeRect || !overRect)
|
||||
return 'edge'
|
||||
const activeCenterY = (activeRect.top + activeRect.bottom) / 2
|
||||
const overHeight = overRect.height
|
||||
// Widen the nest zone to the middle 60% of the over card so user doesn't
|
||||
// need pixel-precision. Edge zone is just the top/bottom 20% slivers,
|
||||
// which are still enough for sibling-reorder gestures.
|
||||
const middleStart = overRect.top + overHeight * 0.2
|
||||
const middleEnd = overRect.top + overHeight * 0.8
|
||||
return activeCenterY >= middleStart && activeCenterY <= middleEnd ? 'middle' : 'edge'
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks up the prerequisite chain from `target`, returning true if
|
||||
* `maybeAncestor` appears anywhere on the way. Uses a visited set so a
|
||||
* pre-existing cycle in the data doesn't spin forever.
|
||||
*/
|
||||
function isDescendant(maybeAncestor: number, target: number, all: Issue[]): boolean {
|
||||
const visited = new Set<number>()
|
||||
let current: Issue | undefined = all.find(i => i.number === target)
|
||||
while (current && current.prerequisite != null) {
|
||||
if (visited.has(current.number))
|
||||
return false
|
||||
visited.add(current.number)
|
||||
if (current.prerequisite === maybeAncestor)
|
||||
return true
|
||||
current = all.find(i => i.number === current!.prerequisite)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function handleDragEnd(event: DragEndEvent): void {
|
||||
const { active, over } = event
|
||||
setActiveId(null)
|
||||
if (!over)
|
||||
return
|
||||
|
||||
const activeIdStr = String(active.id)
|
||||
const overIdStr = String(over.id)
|
||||
if (activeIdStr === overIdStr)
|
||||
const result = resolveKanbanDrag({
|
||||
issues,
|
||||
activeId: String(active.id),
|
||||
overId: String(over.id),
|
||||
})
|
||||
|
||||
if (result.type === 'none')
|
||||
return
|
||||
|
||||
const activeIndex = issues.findIndex(i => i.id === activeIdStr)
|
||||
if (activeIndex < 0)
|
||||
if (result.type === 'reorder') {
|
||||
onIssuesChange(arrayMove(issues, result.fromIndex, result.toIndex))
|
||||
return
|
||||
const activeItem = issues[activeIndex]
|
||||
|
||||
// Lock check: a todo card whose prerequisite is still unfinished must
|
||||
// stay in the todo column. Resolve target column from either the over
|
||||
// column id or the over card's column.
|
||||
const prereqIssue = activeItem.prerequisite != null
|
||||
? issues.find(i => i.number === activeItem.prerequisite)
|
||||
: undefined
|
||||
const isLocked = !!prereqIssue && prereqIssue.column !== 'done'
|
||||
if (isLocked && activeItem.column === 'todo') {
|
||||
const overItemForLock = isColumnId(overIdStr)
|
||||
? undefined
|
||||
: issues.find(i => i.id === overIdStr)
|
||||
const targetColumn: IssueColumn | undefined = isColumnId(overIdStr)
|
||||
? overIdStr
|
||||
: overItemForLock?.column
|
||||
if (targetColumn && targetColumn !== 'todo')
|
||||
return
|
||||
}
|
||||
|
||||
// Dropped onto a column container
|
||||
if (isColumnId(overIdStr)) {
|
||||
// Drop onto the todo column's empty area while the card is already in
|
||||
// todo → clear prerequisite (move to root level, append at column end).
|
||||
if (overIdStr === 'todo' && activeItem.column === 'todo' && activeItem.prerequisite != null) {
|
||||
const prevPrereq = activeItem.prerequisite
|
||||
const next = [...issues]
|
||||
next.splice(activeIndex, 1)
|
||||
next.push({ ...activeItem, prerequisite: undefined })
|
||||
onIssuesChange(next)
|
||||
onDependencyClear?.(activeItem.number, prevPrereq)
|
||||
return
|
||||
}
|
||||
if (activeItem.column === overIdStr)
|
||||
if (result.type === 'column') {
|
||||
const idx = issues.findIndex(i => i.number === result.issueNumber)
|
||||
if (idx < 0)
|
||||
return
|
||||
const item = issues[idx]
|
||||
const next = [...issues]
|
||||
next.splice(activeIndex, 1)
|
||||
next.push({ ...activeItem, column: overIdStr })
|
||||
next.splice(idx, 1)
|
||||
const overIdx = isColumnId(String(over.id))
|
||||
? -1
|
||||
: next.findIndex(i => i.id === String(over.id))
|
||||
const insertAt = overIdx < 0 ? next.length : overIdx
|
||||
next.splice(insertAt, 0, { ...item, column: result.toColumn })
|
||||
onIssuesChange(next)
|
||||
onColumnChange?.(activeItem.number, overIdStr, activeItem.source, activeItem.externalId)
|
||||
onColumnChange?.(result.issueNumber, result.toColumn, result.source, result.externalId)
|
||||
return
|
||||
}
|
||||
|
||||
// Dropped onto another card
|
||||
const overIndex = issues.findIndex(i => i.id === overIdStr)
|
||||
if (overIndex < 0)
|
||||
return
|
||||
const overItem = issues[overIndex]
|
||||
|
||||
// Cross-column or non-todo-to-non-todo: keep the existing semantics.
|
||||
if (activeItem.column !== 'todo' || overItem.column !== 'todo') {
|
||||
if (activeItem.column === overItem.column) {
|
||||
onIssuesChange(arrayMove(issues, activeIndex, overIndex))
|
||||
if (result.type === 'dependency-set') {
|
||||
const idx = issues.findIndex(i => i.number === result.issueNumber)
|
||||
if (idx < 0)
|
||||
return
|
||||
}
|
||||
// Cross-column: drop activeItem at overItem's position in the new column
|
||||
const item = issues[idx]
|
||||
const next = [...issues]
|
||||
next.splice(activeIndex, 1)
|
||||
const newOverIndex = next.findIndex(i => i.id === overIdStr)
|
||||
const insertAt = newOverIndex < 0 ? next.length : newOverIndex
|
||||
next.splice(insertAt, 0, { ...activeItem, column: overItem.column })
|
||||
next.splice(idx, 1)
|
||||
const overIdx = next.findIndex(i => i.number === result.prerequisiteNumber)
|
||||
const insertAt = overIdx < 0 ? next.length : overIdx + 1
|
||||
next.splice(insertAt, 0, { ...item, prerequisite: result.prerequisiteNumber })
|
||||
onIssuesChange(next)
|
||||
onColumnChange?.(activeItem.number, overItem.column, activeItem.source, activeItem.externalId)
|
||||
onDependencySet?.(result.issueNumber, result.prerequisiteNumber)
|
||||
return
|
||||
}
|
||||
|
||||
// Both in todo: distinguish nest (middle 1/3) vs sibling reorder (edge).
|
||||
const zone = detectDropZone(event)
|
||||
if (zone === 'middle') {
|
||||
// Don't allow nesting onto our own descendant (would form a cycle).
|
||||
if (isDescendant(activeItem.number, overItem.number, issues))
|
||||
return
|
||||
// Already nested under this same parent → nothing to do.
|
||||
if (activeItem.prerequisite === overItem.number)
|
||||
return
|
||||
const next = [...issues]
|
||||
next.splice(activeIndex, 1)
|
||||
const newOverIndex = next.findIndex(i => i.id === overIdStr)
|
||||
const insertAt = newOverIndex < 0 ? next.length : newOverIndex + 1
|
||||
next.splice(insertAt, 0, { ...activeItem, prerequisite: overItem.number })
|
||||
onIssuesChange(next)
|
||||
onDependencySet?.(activeItem.number, overItem.number)
|
||||
const idx = issues.findIndex(i => i.number === result.issueNumber)
|
||||
if (idx < 0)
|
||||
return
|
||||
}
|
||||
|
||||
// edge: sibling reorder. Inherit the over card's prerequisite as parent.
|
||||
const newParent = overItem.prerequisite
|
||||
if (newParent === activeItem.prerequisite) {
|
||||
// Same parent (including both undefined): pure reorder.
|
||||
onIssuesChange(arrayMove(issues, activeIndex, overIndex))
|
||||
return
|
||||
}
|
||||
// Cycle guard: refuse to set the new parent if it would put active under
|
||||
// its own descendant. Still reorder visually.
|
||||
const cycle = newParent != null && isDescendant(activeItem.number, newParent, issues)
|
||||
if (cycle) {
|
||||
onIssuesChange(arrayMove(issues, activeIndex, overIndex))
|
||||
return
|
||||
}
|
||||
const item = issues[idx]
|
||||
const next = [...issues]
|
||||
next.splice(activeIndex, 1)
|
||||
const newOverIndex = next.findIndex(i => i.id === overIdStr)
|
||||
const insertAt = newOverIndex < 0 ? next.length : newOverIndex
|
||||
next.splice(insertAt, 0, { ...activeItem, prerequisite: newParent })
|
||||
next.splice(idx, 1)
|
||||
next.push({ ...item, prerequisite: undefined })
|
||||
onIssuesChange(next)
|
||||
if (newParent == null)
|
||||
onDependencyClear?.(activeItem.number, activeItem.prerequisite!)
|
||||
else
|
||||
onDependencySet?.(activeItem.number, newParent)
|
||||
onDependencyClear?.(result.issueNumber, result.prerequisiteNumber)
|
||||
}
|
||||
|
||||
return (
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={kanbanCollisionDetection}
|
||||
onDragStart={handleDragStart}
|
||||
onDragEnd={handleDragEnd}
|
||||
onDragCancel={() => setActiveId(null)}
|
||||
|
||||
Reference in new issue
Block a user