feat(issues): tipo/categoría de incidencia (defecto/seguridad/calidad/documentación/otro)

- Issue::TYPES + typeLabels() (ES) + accessors type_label/type_color; columna type
  (string, default 'other') + fillable.
- IssueForm: select "Tipo de incidencia" con validación/carga/guardado.
- IssueTable: columna Tipo (badge) + SelectFilter por tipo.
- IssueDetail: badge de tipo en la cabecera.
- Sync offline: issue.create/update aceptan type; bundle (mapIssue) lo incluye.

Tests: IssuesEnhancementsTest (create muestra el campo vía HTTP, edición persiste) +
MobileApiTest (create con type). Suite 61 passing (solo 2 pre-existentes sqlite).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-18 13:30:54 +02:00
parent 19e1f57983
commit 3d0f4d5cad
10 changed files with 114 additions and 2 deletions
@@ -175,6 +175,7 @@ class ProjectApiController extends Controller
return [
'id' => $i->id, 'feature_id' => $i->feature_id, 'title' => $i->title,
'description' => $i->description, 'status' => $i->status, 'priority' => $i->priority,
'type' => $i->type,
'reported_by' => $i->reported_by, 'assigned_to' => $i->assigned_to,
'resolved_at' => $i->resolved_at?->toIso8601String(), 'updated_at' => $i->updated_at?->toIso8601String(),
];
@@ -189,6 +189,7 @@ class SyncController extends Controller
'description' => ['nullable', 'string'],
'priority' => ['nullable', 'in:' . implode(',', Issue::PRIORITIES)],
'status' => ['nullable', 'in:' . implode(',', Issue::STATUSES)],
'type' => ['nullable', 'in:' . implode(',', Issue::TYPES)],
]);
if ($v->fails()) {
return $this->error($uuid, 'validation: ' . $v->errors()->first());
@@ -208,6 +209,7 @@ class SyncController extends Controller
'description' => $d['description'] ?? null,
'priority' => $d['priority'] ?? 'medium',
'status' => $d['status'] ?? 'open',
'type' => $d['type'] ?? 'other',
'reported_by' => $user->id,
'client_updated_at' => $op['client_updated_at'] ?? null,
]);
@@ -223,6 +225,7 @@ class SyncController extends Controller
'description' => ['nullable', 'string'],
'priority' => ['nullable', 'in:' . implode(',', Issue::PRIORITIES)],
'status' => ['nullable', 'in:' . implode(',', Issue::STATUSES)],
'type' => ['nullable', 'in:' . implode(',', Issue::TYPES)],
'assigned_to' => ['nullable', 'integer', 'exists:users,id'],
'resolution_notes' => ['nullable', 'string'],
]);
+4
View File
@@ -23,6 +23,7 @@ class IssueForm extends Component
public $description = '';
public $status = 'open';
public $priority = 'medium';
public $type = 'defect';
public $assignedTo = '';
public $resolutionNotes = '';
@@ -48,6 +49,7 @@ class IssueForm extends Component
$this->description = $issue->description ?? '';
$this->status = $issue->status;
$this->priority = $issue->priority;
$this->type = $issue->type ?? 'defect';
$this->assignedTo = $issue->assigned_to ?? '';
$this->resolutionNotes = $issue->resolution_notes ?? '';
$this->featureId = $issue->feature_id;
@@ -77,6 +79,7 @@ class IssueForm extends Component
'description' => 'nullable|string',
'status' => 'required|in:' . implode(',', Issue::STATUSES),
'priority' => 'required|in:' . implode(',', Issue::PRIORITIES),
'type' => 'required|in:' . implode(',', Issue::TYPES),
'assignedTo' => 'nullable|exists:users,id',
'resolutionNotes' => 'nullable|string',
];
@@ -92,6 +95,7 @@ class IssueForm extends Component
'description' => $this->description,
'status' => $this->status,
'priority' => $this->priority,
'type' => $this->type,
'feature_id' => $this->featureId,
'inspection_id' => $this->inspectionId,
'assigned_to' => $this->assignedTo ?: null,
+10
View File
@@ -91,6 +91,12 @@ class IssueTable extends DataTableComponent
})
->html(),
Column::make('Tipo', 'type')
->sortable()
->format(fn ($value, $row) =>
'<span class="badge badge-sm" style="background-color:'.$row->type_color.';color:#fff;border-color:transparent;">'.e($row->type_label).'</span>')
->html(),
Column::make('Feature')
->label(fn ($row) => $row->feature
? '<span class="badge badge-outline badge-sm">'.e($row->feature->name).'</span>'
@@ -185,6 +191,10 @@ class IssueTable extends DataTableComponent
'low' => 'Baja',
])
->filter(fn (Builder $query, string $value) => $query->where('issues.priority', $value)),
SelectFilter::make('Tipo', 'type')
->options(['' => 'Tipo: todos'] + \App\Models\Issue::typeLabels())
->filter(fn (Builder $query, string $value) => $query->where('issues.type', $value)),
];
}
+30 -1
View File
@@ -12,10 +12,11 @@ class Issue extends Model
const STATUSES = ['open', 'in_review', 'resolved', 'closed'];
const PRIORITIES = ['low', 'medium', 'high', 'critical'];
const TYPES = ['defect', 'safety', 'quality', 'documentation', 'other'];
protected $fillable = [
'project_id', 'feature_id', 'inspection_id',
'title', 'description', 'status', 'priority',
'title', 'description', 'status', 'priority', 'type',
'reported_by', 'assigned_to', 'resolved_at', 'resolution_notes',
'uuid', 'client_updated_at',
];
@@ -71,4 +72,32 @@ class Issue extends Model
default => '#6b7280',
};
}
/** Human label (Spanish) for each issue type. */
public static function typeLabels(): array
{
return [
'defect' => 'Defecto',
'safety' => 'Seguridad',
'quality' => 'Calidad',
'documentation' => 'Documentación',
'other' => 'Otro',
];
}
public function getTypeLabelAttribute(): string
{
return self::typeLabels()[$this->type] ?? ucfirst((string) $this->type);
}
public function getTypeColorAttribute(): string
{
return match($this->type) {
'defect' => '#ef4444',
'safety' => '#f97316',
'quality' => '#0ea5e9',
'documentation' => '#8b5cf6',
default => '#6b7280',
};
}
}
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('issues', function (Blueprint $table) {
$table->string('type', 30)->default('other')->after('priority');
});
}
public function down(): void
{
Schema::table('issues', function (Blueprint $table) {
$table->dropColumn('type');
});
}
};
@@ -26,6 +26,7 @@
<div class="flex flex-wrap items-center gap-2 mt-2">
<span class="badge badge-sm" style="background-color: {{ $issue->status_color }}; color:#fff; border:0;">{{ $statusLabel }}</span>
<span class="badge badge-sm" style="background-color: {{ $issue->priority_color }}; color:#fff; border:0;">Prioridad: {{ $priorityLabel }}</span>
<span class="badge badge-sm" style="background-color: {{ $issue->type_color }}; color:#fff; border:0;">{{ $issue->type_label }}</span>
@if($issue->feature)
<span class="badge badge-outline badge-sm">{{ $issue->feature->name }}</span>
@endif
@@ -80,6 +80,22 @@
</div>
</div>
{{-- Tipo / categoría --}}
<div class="form-control">
<label class="label">
<span class="label-text font-medium">Tipo de incidencia <span class="text-error">*</span></span>
</label>
<select wire:model="type"
class="select select-bordered w-full @error('type') select-error @enderror">
@foreach(\App\Models\Issue::typeLabels() as $value => $label)
<option value="{{ $value }}">{{ $label }}</option>
@endforeach
</select>
@error('type')
<label class="label"><span class="label-text-alt text-error">{{ $message }}</span></label>
@enderror
</div>
{{-- Asignado a --}}
<div class="form-control">
<label class="label"><span class="label-text font-medium">Asignado a</span></label>
+2 -1
View File
@@ -321,11 +321,12 @@ class MobileApiTest extends TestCase
$uuid = (string) Str::uuid();
$this->postJson('/api/v1/sync', ['operations' => [[
'entity' => 'issue', 'op' => 'create', 'uuid' => $uuid,
'data' => ['project_id' => $project->id, 'title' => 'Grieta', 'priority' => 'high'],
'data' => ['project_id' => $project->id, 'title' => 'Grieta', 'priority' => 'high', 'type' => 'safety'],
]]])->assertOk()->assertJsonPath('results.0.status', 'applied');
$issue = Issue::where('uuid', $uuid)->firstOrFail();
$this->assertEquals('open', $issue->status);
$this->assertEquals('safety', $issue->type);
// update (resolve) → resolved_at set
$this->postJson('/api/v1/sync', ['operations' => [[
+25
View File
@@ -183,6 +183,31 @@ class IssuesEnhancementsTest extends TestCase
$this->assertNotNull($task->fresh()->overdue_notified_at);
}
// ── Issue type / category ──────────────────────────────────────────────────────
public function test_create_form_shows_the_type_field(): void
{
$this->actingAs($this->user)
->get(route('projects.issues.create', $this->project))
->assertOk()
->assertSee('Tipo de incidencia')
->assertSee('Defecto')
->assertSee('Seguridad');
}
public function test_editing_an_issue_persists_the_type(): void
{
$issue = $this->makeIssue(['type' => 'defect']);
Livewire::actingAs($this->user)
->test(IssueForm::class, ['project' => $this->project, 'issue' => $issue])
->assertSet('type', 'defect')
->set('type', 'safety')
->call('save');
$this->assertEquals('safety', $issue->fresh()->type);
}
// ── Report issue from a map feature ──────────────────────────────────────────
public function test_issue_form_prelinks_feature_from_query(): void