Refactor site building workflow and context handling; update API response structure for improved clarity and consistency. Adjust frontend components to align with new data structure, including error handling and loading states.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-20 21:50:16 +00:00
parent 781052c719
commit 1b4cd59e5b
24 changed files with 386 additions and 164 deletions

View File

@@ -35,11 +35,13 @@ class WizardContextService:
workflow_payload = self.workflow_service.serialize_state(workflow_state) if workflow_state else None
coverage_data = self._coverage_summary(site_blueprint)
context = {
'workflow': workflow_payload,
'clusters': self._cluster_summary(site_blueprint),
'taxonomies': self._taxonomy_summary(site_blueprint),
'coverage': self._coverage_summary(site_blueprint),
'cluster_summary': self._cluster_summary(site_blueprint),
'taxonomy_summary': self._taxonomy_summary(site_blueprint),
'sitemap_summary': coverage_data, # Frontend expects 'sitemap_summary' not 'coverage'
'coverage': coverage_data, # Keep for backward compatibility
}
context['next_actions'] = self._next_actions(workflow_payload)
return context

View File

@@ -111,13 +111,21 @@ class WorkflowStateService:
metadata: Optional[Dict[str, str]] = None,
) -> Optional[WorkflowState]:
"""Persist explicit step updates coming from the wizard."""
if not self.enabled:
return None
state = self.initialize(site_blueprint)
if not state:
return None
metadata = metadata or {}
timestamp = timezone.now().isoformat()
step_status = state.step_status or {}
# Ensure step_status is a dict (handle None case)
if state.step_status is None:
state.step_status = {}
step_status = dict(state.step_status) # Create a copy to avoid mutation issues
entry = self._build_step_entry(
step=step,
status=status,
@@ -132,8 +140,22 @@ class WorkflowStateService:
state.step_status = step_status
state.blocking_reason = metadata.get('message')
state.completed = all(value.get('status') == 'ready' for value in step_status.values())
state.save(update_fields=['current_step', 'step_status', 'blocking_reason', 'completed', 'updated_at'])
# Calculate completed status - only true if all steps are ready and we have at least one step
if step_status:
state.completed = all(
value.get('status') == 'ready' or value.get('status') == 'complete'
for value in step_status.values()
)
else:
state.completed = False
try:
state.save(update_fields=['current_step', 'step_status', 'blocking_reason', 'completed', 'updated_at'])
except Exception as e:
logger.error(f"Failed to save workflow state for blueprint {site_blueprint.id}: {str(e)}")
raise
self._emit_event(site_blueprint, 'wizard_step_updated', {
'step': step,
'status': status,
@@ -173,7 +195,7 @@ class WorkflowStateService:
'completed': state.completed,
'blocking_reason': state.blocking_reason,
'steps': steps_payload,
'updated_at': state.updated_at,
'updated_at': state.updated_at.isoformat() if hasattr(state.updated_at, 'isoformat') else str(state.updated_at),
}
def _build_step_entry(