feat(issues): build the rich Issues screen (recover yesterday's draft)

Rebuilt IssueManager to match the 403-line draft view that had no companion
component:
- Modal create/edit form (title, description, priority, status, assignee,
  resolution notes shown when resolved/closed)
- Stats bar (open/in_review/resolved/closed/total) and a styled table
- New methods: openForm/closeForm, resolve, close (+ existing save/delete),
  projectUsers for the assignee dropdown, resolved_at kept in sync with status
- render() now points to livewire.issues.issue-manager; deleted the old
  89-line stub livewire/issue-manager.blade.php
The Issue model already had everything (resolution_notes, resolved_at,
priority_color/status_color accessors, reporter/feature/assignee relations).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-17 14:16:14 +02:00
parent 860c502f32
commit 7df6d208d9
2 changed files with 114 additions and 147 deletions
+100 -44
View File
@@ -14,22 +14,29 @@ class IssueManager extends Component
{
public Project $project;
public $editing = false;
public $editingId = null;
public $issues = [];
public $projectUsers = [];
// Form / modal state
public $showForm = false;
public $editingIssue = null; // issue id when editing, null when creating
// Form fields
public $title = '';
public $description = '';
public $status = 'open';
public $priority = 'medium';
public $assignedTo = '';
public $resolutionNotes = '';
// Optional context (e.g. when reporting from a map feature)
public $featureId = null;
public $inspectionId = null;
public $assignedTo = null;
public $issues = [];
public function mount(Project $project)
{
$this->project = $project;
$this->loadProjectUsers();
$this->loadIssues();
}
@@ -41,79 +48,134 @@ class IssueManager extends Component
->get();
}
public function create()
public function loadProjectUsers()
{
$this->reset(['title', 'description', 'status', 'priority', 'featureId', 'inspectionId', 'assignedTo', 'editingId']);
$this->status = 'open';
$this->priority = 'medium';
$this->editing = true;
$this->projectUsers = $this->project->users()->orderBy('name')->get();
}
public function edit($issueId)
protected function rules(): array
{
$issue = Issue::findOrFail($issueId);
$this->editingId = $issue->id;
return [
'title' => 'required|string|max:255',
'description' => 'nullable|string',
'status' => 'required|in:' . implode(',', Issue::STATUSES),
'priority' => 'required|in:' . implode(',', Issue::PRIORITIES),
'assignedTo' => 'nullable|exists:users,id',
'resolutionNotes' => 'nullable|string',
];
}
public function openForm($issueId = null)
{
$this->resetForm();
if ($issueId) {
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
$this->editingIssue = $issue->id;
$this->title = $issue->title;
$this->description = $issue->description ?? '';
$this->status = $issue->status;
$this->priority = $issue->priority;
$this->assignedTo = $issue->assigned_to ?? '';
$this->resolutionNotes = $issue->resolution_notes ?? '';
$this->featureId = $issue->feature_id;
$this->inspectionId = $issue->inspection_id;
$this->assignedTo = $issue->assigned_to;
$this->editing = true;
}
$this->showForm = true;
}
public function closeForm()
{
$this->showForm = false;
$this->resetForm();
}
private function resetForm(): void
{
$this->reset([
'title', 'description', 'assignedTo', 'resolutionNotes',
'featureId', 'inspectionId', 'editingIssue',
]);
$this->status = 'open';
$this->priority = 'medium';
$this->resetErrorBag();
}
public function save()
{
$this->validate([
'title' => 'required|string|max:255',
'status' => 'required|in:' . implode(',', Issue::STATUSES),
'priority' => 'required|in:' . implode(',', Issue::PRIORITIES),
]);
$this->validate();
if ($this->editingId) {
$issue = Issue::findOrFail($this->editingId);
$issue->update([
$payload = [
'title' => $this->title,
'description' => $this->description,
'status' => $this->status,
'priority' => $this->priority,
'feature_id' => $this->featureId,
'inspection_id' => $this->inspectionId,
'assigned_to' => $this->assignedTo,
]);
'assigned_to' => $this->assignedTo ?: null,
'resolution_notes' => $this->resolutionNotes ?: null,
];
// Keep resolved_at in sync with the status
if (in_array($this->status, ['resolved', 'closed'])) {
$payload['resolved_at'] = now();
} else {
$issue = Issue::create([
$payload['resolved_at'] = null;
}
if ($this->editingIssue) {
$issue = Issue::where('project_id', $this->project->id)->findOrFail($this->editingIssue);
// Don't overwrite an existing resolved date if it was already resolved
if ($issue->resolved_at && in_array($this->status, ['resolved', 'closed'])) {
unset($payload['resolved_at']);
}
$issue->update($payload);
} else {
$issue = Issue::create(array_merge($payload, [
'project_id' => $this->project->id,
'title' => $this->title,
'description' => $this->description,
'status' => $this->status,
'priority' => $this->priority,
'feature_id' => $this->featureId,
'inspection_id' => $this->inspectionId,
'reported_by' => Auth::id(),
'assigned_to' => $this->assignedTo,
]);
]));
if ($issue->wasRecentlyCreated) {
$issue->load(['feature', 'assignee']);
$creator = $this->project->creator;
if ($creator && $creator->id !== Auth::id()) {
$creator->notify(new IssueReportedNotification($issue));
}
if ($issue->assignee && $issue->assignee->id !== Auth::id()) {
$issue->assignee->notify(new IssueReportedNotification($issue));
}
}
}
$this->editing = false;
$this->closeForm();
$this->loadIssues();
$this->dispatch('notify', 'Issue guardado correctamente');
}
public function resolve($issueId)
{
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
$issue->update([
'status' => 'resolved',
'resolved_at' => $issue->resolved_at ?? now(),
]);
$this->loadIssues();
$this->dispatch('notify', 'Issue marcado como resuelto');
}
public function close($issueId)
{
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
$issue->update([
'status' => 'closed',
'resolved_at' => $issue->resolved_at ?? now(),
]);
$this->loadIssues();
$this->dispatch('notify', 'Issue cerrado');
}
public function delete($issueId)
{
$issue = Issue::where('project_id', $this->project->id)->findOrFail($issueId);
@@ -122,14 +184,8 @@ class IssueManager extends Component
$this->dispatch('notify', 'Issue eliminado');
}
public function cancel()
{
$this->editing = false;
$this->reset(['title', 'description', 'status', 'priority', 'featureId', 'inspectionId', 'assignedTo', 'editingId']);
}
public function render()
{
return view('livewire.issue-manager');
return view('livewire.issues.issue-manager');
}
}
@@ -1,89 +0,0 @@
<div>
{{-- Issue form --}}
@if($editing)
<div class="card bg-base-100 shadow mb-4">
<div class="card-body">
<h3 class="card-title text-base">
{{ $editingId ? 'Editar Issue' : 'Nuevo Issue' }}
</h3>
<div class="form-control mb-3">
<label class="label"><span class="label-text">Título *</span></label>
<input type="text" wire:model="title" class="input input-bordered" placeholder="Título del issue" />
@error('title') <span class="text-error text-xs mt-1">{{ $message }}</span> @enderror
</div>
<div class="form-control mb-3">
<label class="label"><span class="label-text">Descripción</span></label>
<textarea wire:model="description" class="textarea textarea-bordered" rows="3" placeholder="Descripción..."></textarea>
</div>
<div class="grid grid-cols-2 gap-3 mb-3">
<div class="form-control">
<label class="label"><span class="label-text">Estado</span></label>
<select wire:model="status" class="select select-bordered">
<option value="open">Abierto</option>
<option value="in_review">En revisión</option>
<option value="resolved">Resuelto</option>
<option value="closed">Cerrado</option>
</select>
</div>
<div class="form-control">
<label class="label"><span class="label-text">Prioridad</span></label>
<select wire:model="priority" class="select select-bordered">
<option value="low">Baja</option>
<option value="medium">Media</option>
<option value="high">Alta</option>
<option value="critical">Crítica</option>
</select>
</div>
</div>
<div class="flex gap-2 justify-end mt-2">
<button wire:click="cancel" class="btn btn-ghost btn-sm">Cancelar</button>
<button wire:click="save" class="btn btn-primary btn-sm">Guardar</button>
</div>
</div>
</div>
@else
<div class="flex justify-end mb-3">
<button wire:click="create" class="btn btn-primary btn-sm">
+ Nuevo Issue
</button>
</div>
@endif
{{-- Issue list --}}
<div class="space-y-2">
@forelse($issues as $issue)
<div class="card bg-base-100 shadow-sm border border-base-200">
<div class="card-body py-3 px-4">
<div class="flex items-start justify-between gap-2">
<div class="flex-1">
<p class="font-medium text-sm">{{ $issue->title }}</p>
@if($issue->description)
<p class="text-xs text-base-content/60 mt-0.5 line-clamp-2">{{ $issue->description }}</p>
@endif
<div class="flex gap-2 mt-1">
<span class="badge badge-xs" style="background-color: {{ $issue->priority_color }}; color: #fff;">
{{ ucfirst($issue->priority) }}
</span>
<span class="badge badge-xs badge-outline">
{{ ucfirst(str_replace('_', ' ', $issue->status)) }}
</span>
</div>
</div>
<div class="flex gap-1 shrink-0">
<button wire:click="edit({{ $issue->id }})" class="btn btn-ghost btn-xs">Editar</button>
<button wire:click="delete({{ $issue->id }})"
wire:confirm="¿Eliminar este issue?"
class="btn btn-ghost btn-xs text-error">Eliminar</button>
</div>
</div>
</div>
</div>
@empty
<p class="text-center text-sm text-base-content/50 py-6">No hay issues registrados</p>
@endforelse
</div>
</div>