Compare commits

...

4 Commits

4 changed files with 69 additions and 32 deletions

View File

@@ -3,11 +3,11 @@ import api from '@/services/api'
import type { Milestone, Project, Task } from '@/types'
const TASK_TYPES = [
{ value: 'story', label: 'Story', subtypes: ['feature', 'improvement', 'refactor'] },
{ value: 'story', label: 'Story', subtypes: ['improvement', 'refactor'] }, // P9.6: 'feature' removed — must come from propose accept
{ value: 'issue', label: 'Issue', subtypes: ['infrastructure', 'performance', 'regression', 'security', 'user_experience', 'defect'] },
{ value: 'task', label: 'Task', subtypes: ['defect'] },
{ value: 'test', label: 'Test', subtypes: ['regression', 'security', 'smoke', 'stress'] },
{ value: 'maintenance', label: 'Maintenance', subtypes: ['deploy', 'release'] },
{ value: 'maintenance', label: 'Maintenance', subtypes: ['deploy'] }, // P9.6: 'release' removed — controlled via milestone flow
{ value: 'research', label: 'Research', subtypes: [] },
{ value: 'review', label: 'Review', subtypes: ['code_review', 'decision_review', 'function_review'] },
{ value: 'resolution', label: 'Resolution', subtypes: [] },

View File

@@ -4,11 +4,11 @@ import api from '@/services/api'
import type { Project, Milestone } from '@/types'
const TASK_TYPES = [
{ value: 'story', label: 'Story', subtypes: ['feature', 'improvement', 'refactor'] },
{ value: 'story', label: 'Story', subtypes: ['improvement', 'refactor'] }, // P9.6: 'feature' removed — must come from propose accept
{ value: 'issue', label: 'Issue', subtypes: ['infrastructure', 'performance', 'regression', 'security', 'user_experience', 'defect'] },
{ value: 'task', label: 'Task', subtypes: ['defect'] },
{ value: 'test', label: 'Test', subtypes: ['regression', 'security', 'smoke', 'stress'] },
{ value: 'maintenance', label: 'Maintenance', subtypes: ['deploy', 'release'] },
{ value: 'maintenance', label: 'Maintenance', subtypes: ['deploy'] }, // P9.6: 'release' removed — controlled via milestone flow
{ value: 'research', label: 'Research', subtypes: [] },
{ value: 'review', label: 'Review', subtypes: ['code_review', 'decision_review', 'function_review'] },
{ value: 'resolution', label: 'Resolution', subtypes: [] },

View File

@@ -45,6 +45,7 @@ export default function MilestoneDetailPage() {
const [actionError, setActionError] = useState<string | null>(null)
const [showCloseConfirm, setShowCloseConfirm] = useState(false)
const [closeReason, setCloseReason] = useState('')
const [preflight, setPreflight] = useState<{ freeze?: { allowed: boolean; reason: string | null }; start?: { allowed: boolean; reason: string | null } } | null>(null)
const fetchMilestone = () => {
api.get<Milestone>(`/milestones/${id}`).then(({ data }) => {
@@ -55,11 +56,18 @@ export default function MilestoneDetailPage() {
setProjectCode(proj.project_code || '')
})
api.get<ProjectMember[]>(`/projects/${data.project_id}/members`).then(({ data }) => setMembers(data)).catch(() => {})
fetchPreflight(data.project_id)
}
})
api.get<MilestoneProgress>(`/milestones/${id}/progress`).then(({ data }) => setProgress(data)).catch(() => {})
}
const fetchPreflight = (projectId: number) => {
api.get(`/projects/${projectId}/milestones/${id}/actions/preflight`)
.then(({ data }) => setPreflight(data))
.catch(() => setPreflight(null))
}
useEffect(() => {
fetchMilestone()
}, [id])
@@ -113,6 +121,7 @@ export default function MilestoneDetailPage() {
await api.post(`/projects/${project.id}/milestones/${milestone.id}/actions/${action}`, body ?? {})
fetchMilestone()
refreshMilestoneItems()
fetchPreflight(project.id)
} catch (err: any) {
const detail = err?.response?.data?.detail
setActionError(typeof detail === 'string' ? detail : `${action} failed`)
@@ -164,22 +173,38 @@ export default function MilestoneDetailPage() {
{!isTerminal && (
<div style={{ display: 'flex', gap: 8, marginTop: 8, flexWrap: 'wrap', alignItems: 'center' }}>
{msStatus === 'open' && (
<button
className="btn-primary"
disabled={actionLoading === 'freeze'}
onClick={handleFreeze}
>
{actionLoading === 'freeze' ? '⏳ Freezing...' : '🧊 Freeze'}
</button>
<span title={preflight?.freeze?.allowed === false ? preflight.freeze.reason ?? '' : ''}>
<button
className="btn-primary"
disabled={actionLoading === 'freeze' || preflight?.freeze?.allowed === false}
onClick={handleFreeze}
style={preflight?.freeze?.allowed === false ? { opacity: 0.5, cursor: 'not-allowed' } : {}}
>
{actionLoading === 'freeze' ? '⏳ Freezing...' : '🧊 Freeze'}
</button>
{preflight?.freeze?.allowed === false && (
<span className="text-dim" style={{ marginLeft: 8, fontSize: '0.85em' }}>
{preflight.freeze.reason}
</span>
)}
</span>
)}
{msStatus === 'freeze' && (
<button
className="btn-primary"
disabled={actionLoading === 'start'}
onClick={handleStart}
>
{actionLoading === 'start' ? '⏳ Starting...' : '▶️ Start'}
</button>
<span title={preflight?.start?.allowed === false ? preflight.start.reason ?? '' : ''}>
<button
className="btn-primary"
disabled={actionLoading === 'start' || preflight?.start?.allowed === false}
onClick={handleStart}
style={preflight?.start?.allowed === false ? { opacity: 0.5, cursor: 'not-allowed' } : {}}
>
{actionLoading === 'start' ? '⏳ Starting...' : '▶️ Start'}
</button>
{preflight?.start?.allowed === false && (
<span className="text-dim" style={{ marginLeft: 8, fontSize: '0.85em' }}>
{preflight.start.reason}
</span>
)}
</span>
)}
{(msStatus === 'open' || msStatus === 'freeze' || msStatus === 'undergoing') && (
<>

View File

@@ -49,14 +49,13 @@ export default function TaskDetailPage() {
setComments(data)
}
const doAction = async (actionName: string, newStatus: string, extra?: () => Promise<void>) => {
const doAction = async (actionName: string, newStatus: string, body?: Record<string, any>) => {
setActionLoading(actionName)
setActionError(null)
try {
if (extra) await extra()
await api.post(`/tasks/${id}/transition?new_status=${newStatus}`)
await api.post(`/tasks/${id}/transition?new_status=${newStatus}`, body || {})
await refreshTask()
// refresh comments too (finish adds one)
// refresh comments too (finish adds one via backend)
const { data } = await api.get<Comment[]>(`/tasks/${id}/comments`)
setComments(data)
} catch (err: any) {
@@ -70,17 +69,16 @@ export default function TaskDetailPage() {
const handleStart = () => doAction('start', 'undergoing')
const handleFinishConfirm = async () => {
if (!finishComment.trim()) return
await doAction('finish', 'completed', async () => {
await api.post('/comments', { content: finishComment, task_id: task!.id, author_id: user?.id || 1 })
})
await doAction('finish', 'completed', { comment: finishComment })
setShowFinishModal(false)
setFinishComment('')
}
const handleCloseConfirm = async () => {
const body: Record<string, any> = {}
if (closeReason.trim()) {
await api.post('/comments', { content: `[Close reason] ${closeReason}`, task_id: task!.id, author_id: user?.id || 1 }).catch(() => {})
body.comment = `[Close reason] ${closeReason}`
}
await doAction('close', 'closed')
await doAction('close', 'closed', body)
setShowCloseModal(false)
setCloseReason('')
}
@@ -90,13 +88,27 @@ export default function TaskDetailPage() {
() => members.find((m) => m.user_id === user?.id)?.role,
[members, user?.id]
)
const canEditTask = Boolean(task && project && user && (
const isAdmin = Boolean(user && (
user.is_admin ||
user.id === project.owner_id ||
user.id === task.created_by_id ||
user.id === milestone?.created_by_id ||
(project && user.id === project.owner_id) ||
currentMemberRole === 'admin'
))
// P5.7/P9.3: assignee-aware edit permission
const canEditTask = Boolean(task && project && user && (() => {
const st = task.status
// undergoing/completed/closed: no body edits
if (st === 'undergoing' || st === 'completed' || st === 'closed') return false
// open + assignee set: only assignee or admin
if (st === 'open' && task.assignee_id != null) {
return user.id === task.assignee_id || isAdmin
}
// open + no assignee, or pending: general permission
return (
isAdmin ||
user.id === task.created_by_id ||
user.id === milestone?.created_by_id
)
})())
if (!task) return <div className="loading">Loading...</div>
@@ -115,7 +127,7 @@ export default function TaskDetailPage() {
<span className="badge">{task.task_type}</span>{task.task_subtype && <span className="badge">{task.task_subtype}</span>}
{task.tags && <span className="tags">{task.tags}</span>}
</div>
{canEditTask && !isTerminal && task.status !== 'undergoing' && (
{canEditTask && (
<button className="btn-transition" style={{ marginTop: 8 }} onClick={() => setShowEditTask(true)}>Edit Task</button>
)}
</div>