feat: implement soft delete, task editing fixes, and UI improvements

Backend:
- Add soft delete for spaces and projects (is_active flag)
- Add status_id and assignee_id to TaskUpdate schema
- Fix task PATCH endpoint to update status and assignee
- Add validation for assignee_id and status_id in task updates
- Fix health service to count tasks with "Blocked" status as blockers
- Filter out deleted spaces/projects from health dashboard
- Add workload cache invalidation on assignee changes

Frontend:
- Add delete confirmation dialogs for spaces and projects
- Fix UserSelect to display selected user name (valueName prop)
- Fix task detail modal to refresh data after save
- Enforce 2-level subtask depth limit in UI
- Fix timezone bug in date formatting (use local timezone)
- Convert NotificationBell from Tailwind to inline styles
- Add i18n translations for health, workload, settings pages
- Add parent_task_id to Task interface across components

OpenSpec:
- Archive add-delete-capability change

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2026-01-10 01:32:13 +08:00
parent 2796cbb42d
commit 55f85d0d3c
44 changed files with 1854 additions and 297 deletions

View File

@@ -52,7 +52,7 @@ async def list_projects_in_space(
detail="Access denied",
)
projects = db.query(Project).filter(Project.space_id == space_id).all()
projects = db.query(Project).filter(Project.space_id == space_id, Project.is_active == True).all()
# Filter by project access
accessible_projects = [p for p in projects if check_project_access(current_user, p)]
@@ -154,7 +154,7 @@ async def get_project(
"""
Get a project by ID.
"""
project = db.query(Project).filter(Project.id == project_id).first()
project = db.query(Project).filter(Project.id == project_id, Project.is_active == True).first()
if not project:
raise HTTPException(
@@ -202,7 +202,7 @@ async def update_project(
"""
Update a project.
"""
project = db.query(Project).filter(Project.id == project_id).first()
project = db.query(Project).filter(Project.id == project_id, Project.is_active == True).first()
if not project:
raise HTTPException(
@@ -317,7 +317,7 @@ async def list_project_statuses(
"""
List all task statuses for a project.
"""
project = db.query(Project).filter(Project.id == project_id).first()
project = db.query(Project).filter(Project.id == project_id, Project.is_active == True).first()
if not project:
raise HTTPException(

View File

@@ -406,6 +406,28 @@ async def update_task(
update_data = task_data.model_dump(exclude_unset=True)
custom_values_data = update_data.pop("custom_values", None)
# Track old assignee for workload cache invalidation
old_assignee_id = task.assignee_id
# Validate assignee_id if provided
if "assignee_id" in update_data and update_data["assignee_id"]:
assignee = db.query(User).filter(User.id == update_data["assignee_id"]).first()
if not assignee:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Assignee not found",
)
# Validate status_id if provided
if "status_id" in update_data and update_data["status_id"]:
from app.models.task_status import TaskStatus
task_status = db.query(TaskStatus).filter(TaskStatus.id == update_data["status_id"]).first()
if not task_status:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Status not found",
)
# Get the proposed start_date and due_date for validation
new_start_date = update_data.get("start_date", task.start_date)
new_due_date = update_data.get("due_date", task.due_date)
@@ -486,6 +508,15 @@ async def update_task(
if "original_estimate" in update_data and task.assignee_id:
invalidate_user_workload_cache(task.assignee_id)
# Invalidate workload cache if assignee changed
if "assignee_id" in update_data:
# Invalidate old assignee's cache
if old_assignee_id and old_assignee_id != task.assignee_id:
invalidate_user_workload_cache(old_assignee_id)
# Invalidate new assignee's cache
if task.assignee_id:
invalidate_user_workload_cache(task.assignee_id)
# Publish real-time event
try:
await publish_task_event(

View File

@@ -101,6 +101,10 @@ async def get_heatmap(
None,
description="Comma-separated list of user IDs to include"
),
hide_empty: bool = Query(
True,
description="Hide users with no tasks assigned for the week"
),
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
@@ -133,8 +137,10 @@ async def get_heatmap(
week_start, week_end = get_week_bounds(week_start)
# Try cache first
cached = get_cached_heatmap(week_start, department_id, accessible_user_ids)
# Try cache first (only use cache for default hide_empty=True)
cached = None
if hide_empty:
cached = get_cached_heatmap(week_start, department_id, accessible_user_ids)
if cached:
return WorkloadHeatmapResponse(
week_start=week_start,
@@ -148,10 +154,12 @@ async def get_heatmap(
week_start=week_start,
department_id=department_id,
user_ids=accessible_user_ids,
hide_empty=hide_empty,
)
# Cache the result
set_cached_heatmap(week_start, summaries, department_id, accessible_user_ids)
# Cache the result (only cache when hide_empty=True, the default)
if hide_empty:
set_cached_heatmap(week_start, summaries, department_id, accessible_user_ids)
return WorkloadHeatmapResponse(
week_start=week_start,

View File

@@ -28,6 +28,7 @@ class Project(Base):
nullable=False
)
status = Column(String(50), default="active", nullable=False)
is_active = Column(Boolean, default=True, nullable=False)
department_id = Column(String(36), ForeignKey("pjctrl_departments.id"), nullable=True)
created_at = Column(DateTime, server_default=func.now(), nullable=False)
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)

View File

@@ -54,9 +54,10 @@ class ProjectHealthWithDetails(ProjectHealthResponse):
class ProjectHealthSummary(BaseModel):
"""Aggregated health metrics across all projects."""
total_projects: int
healthy_count: int # health_score >= 80
at_risk_count: int # health_score 50-79
critical_count: int # health_score < 50
healthy_count: int # health_score >= 80 (low risk)
at_risk_count: int # health_score 60-79 (medium risk)
high_risk_count: int # health_score 40-59 (high risk)
critical_count: int # health_score < 40 (critical risk)
average_health_score: float
projects_with_blockers: int
projects_delayed: int

View File

@@ -47,6 +47,8 @@ class TaskUpdate(BaseModel):
title: Optional[str] = None
description: Optional[str] = None
priority: Optional[Priority] = None
status_id: Optional[str] = None
assignee_id: Optional[str] = None
original_estimate: Optional[Decimal] = None
time_spent: Optional[Decimal] = None
start_date: Optional[datetime] = None

View File

@@ -9,7 +9,7 @@ from typing import List, Optional, Dict, Any
from sqlalchemy.orm import Session
from app.models import Project, Task, TaskStatus, Blocker, ProjectHealth
from app.models import Project, Task, TaskStatus, Blocker, ProjectHealth, Space
from app.schemas.project_health import (
RiskLevel,
ScheduleStatus,
@@ -83,15 +83,25 @@ def calculate_health_metrics(db: Session, project: Project) -> Dict[str, Any]:
and not (task.status and task.status.is_done)
)
# Count unresolved blockers
# Count unresolved blockers from Blocker table
task_ids = [t.id for t in tasks]
blocker_count = 0
blocker_table_count = 0
if task_ids:
blocker_count = db.query(Blocker).filter(
blocker_table_count = db.query(Blocker).filter(
Blocker.task_id.in_(task_ids),
Blocker.resolved_at.is_(None)
).count()
# Also count tasks with "Blocked" status (status name contains 'block', case-insensitive)
blocked_status_count = sum(
1 for task in tasks
if task.status and task.status.name and 'block' in task.status.name.lower()
and not task.status.is_done
)
# Total blocker count = blocker table records + tasks with blocked status
blocker_count = blocker_table_count + blocked_status_count
# Calculate completion rate
completion_rate = 0.0
if task_count > 0:
@@ -234,7 +244,11 @@ def get_project_health(
Returns:
ProjectHealthWithDetails or None if project not found
"""
project = db.query(Project).filter(Project.id == project_id).first()
project = db.query(Project).join(Space, Project.space_id == Space.id).filter(
Project.id == project_id,
Project.is_active == True,
Space.is_active == True
).first()
if not project:
return None
@@ -261,7 +275,10 @@ def get_all_projects_health(
Returns:
ProjectHealthDashboardResponse with projects list and summary
"""
query = db.query(Project)
query = db.query(Project).join(Space, Project.space_id == Space.id).filter(
Project.is_active == True,
Space.is_active == True
)
if status_filter:
query = query.filter(Project.status == status_filter)
@@ -314,12 +331,21 @@ def _build_health_with_details(
def _calculate_summary(
projects_health: List[ProjectHealthWithDetails]
) -> ProjectHealthSummary:
"""Calculate summary statistics for health dashboard."""
"""Calculate summary statistics for health dashboard.
Thresholds match _determine_risk_level():
- healthy (low risk): >= 80
- at_risk (medium risk): 60-79
- high_risk (high risk): 40-59
- critical (critical risk): < 40
"""
total_projects = len(projects_health)
healthy_count = sum(1 for p in projects_health if p.health_score >= 80)
at_risk_count = sum(1 for p in projects_health if 50 <= p.health_score < 80)
critical_count = sum(1 for p in projects_health if p.health_score < 50)
# Use consistent thresholds with risk_level calculation
healthy_count = sum(1 for p in projects_health if p.health_score >= RISK_LOW_THRESHOLD)
at_risk_count = sum(1 for p in projects_health if RISK_MEDIUM_THRESHOLD <= p.health_score < RISK_LOW_THRESHOLD)
high_risk_count = sum(1 for p in projects_health if RISK_HIGH_THRESHOLD <= p.health_score < RISK_MEDIUM_THRESHOLD)
critical_count = sum(1 for p in projects_health if p.health_score < RISK_HIGH_THRESHOLD)
average_health_score = 0.0
if total_projects > 0:
@@ -335,6 +361,7 @@ def _calculate_summary(
total_projects=total_projects,
healthy_count=healthy_count,
at_risk_count=at_risk_count,
high_risk_count=high_risk_count,
critical_count=critical_count,
average_health_score=round(average_health_score, 1),
projects_with_blockers=projects_with_blockers,

View File

@@ -171,6 +171,7 @@ def get_workload_heatmap(
week_start: Optional[date] = None,
department_id: Optional[str] = None,
user_ids: Optional[List[str]] = None,
hide_empty: bool = True,
) -> List[UserWorkloadSummary]:
"""
Get workload heatmap for multiple users.
@@ -180,6 +181,7 @@ def get_workload_heatmap(
week_start: Start of week (defaults to current week)
department_id: Filter by department
user_ids: Filter by specific user IDs
hide_empty: If True, exclude users with no tasks (default: True)
Returns:
List of UserWorkloadSummary objects
@@ -260,6 +262,10 @@ def get_workload_heatmap(
)
results.append(summary)
# Filter out users with no tasks if hide_empty is True
if hide_empty:
results = [r for r in results if r.task_count > 0]
return results

View File

@@ -0,0 +1,26 @@
"""add is_active to projects
Revision ID: a0a0f2710e01
Revises: 013
Create Date: 2026-01-09 21:51:11.802999
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'a0a0f2710e01'
down_revision: Union[str, None] = '013'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column('pjctrl_projects', sa.Column('is_active', sa.Boolean(), nullable=False, server_default='1'))
def downgrade() -> None:
op.drop_column('pjctrl_projects', 'is_active')