Fix trip delete button: layout and click handler

- text-nowrap on action cell so Replay+trash stay on same line
- Delete button inline with Replay (no whitespace between)
- Explicit deletable guard in click handler

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 04:45:05 -04:00
co-authored by Copilot
parent 7aa9ffda16
commit 72e4c1b1d7
+22 -20
View File
@@ -203,34 +203,36 @@
<td>${formatDuration(trip.duration_seconds)}</td> <td>${formatDuration(trip.duration_seconds)}</td>
<td>${formatSpeed(trip.max_speed_kmh)}</td> <td>${formatSpeed(trip.max_speed_kmh)}</td>
<td class="text-muted small">${trip.odo_start_km != null ? trip.odo_start_km.toFixed(0) + ' → ' + trip.odo_end_km.toFixed(0) + ' km' : '—'}</td> <td class="text-muted small">${trip.odo_start_km != null ? trip.odo_start_km.toFixed(0) + ' → ' + trip.odo_end_km.toFixed(0) + ' km' : '—'}</td>
<td class="text-end d-none d-sm-table-cell"> <td class="text-end text-nowrap d-none d-sm-table-cell">
<button class="btn btn-sm btn-primary" type="button" data-trip-id="${trip.id}"> <button class="btn btn-sm btn-primary" type="button" data-trip-id="${trip.id}">
Replay Replay
</button> </button>${deleteBtn}
${deleteBtn}
</td>`; </td>`;
body.appendChild(row); body.appendChild(row);
}); });
} }
body.addEventListener("click", function (event) { body.addEventListener("click", function (event) {
// Delete button // Delete button — must check before replay to prevent row click triggering replay
const deleteBtn = event.target.closest("[data-delete-trip-id]"); if (deletable) {
if (deleteBtn) { const deleteBtn = event.target.closest("[data-delete-trip-id]");
event.stopPropagation(); if (deleteBtn) {
const tripId = deleteBtn.dataset.deleteTripId; event.stopPropagation();
const date = deleteBtn.closest("tr").querySelector("td").textContent; event.preventDefault();
window.confirmDelete(`Delete trip from ${date}? The raw GPS data is kept — only the computed trip record is removed.`) const tripId = deleteBtn.dataset.deleteTripId;
.then(function(confirmed) { const date = deleteBtn.closest("tr").querySelector("td").textContent.trim();
if (!confirmed) return; window.confirmDelete(`Delete trip from ${date}?\n\nThe raw GPS data is kept — only this computed trip record is removed.`)
return fetch(`/api/v1/portal/trip/${tripId}`, { method: "DELETE" }) .then(function(confirmed) {
.then(function(res) { if (!confirmed) return;
if (!res.ok) throw new Error("Delete failed"); return fetch(`/api/v1/portal/trip/${tripId}`, { method: "DELETE" })
deleteBtn.closest("tr").remove(); .then(function(res) {
}) if (!res.ok) throw new Error("Delete failed");
.catch(function(e) { showError(e.message); }); deleteBtn.closest("tr").remove();
}); })
return; .catch(function(e) { showError(e.message); });
});
return;
}
} }
// Replay button click (desktop) or row click (mobile) // Replay button click (desktop) or row click (mobile)