feat: implement provider connection reordering on create, update, and delete

This commit is contained in:
Catalin Stanciu
2026-01-06 22:14:10 +02:00
committed by decolua
parent ed796d2724
commit f2abcc6585
2 changed files with 66 additions and 10 deletions

View File

@@ -158,17 +158,32 @@ export default function ProviderDetailPage() {
const handleSwapPriority = async (conn1, conn2) => {
if (!conn1 || !conn2) return;
try {
// Swap priorities
// If they have the same priority, we need to ensure the one moving up
// gets a lower value than the one moving down.
// We use a small offset which the backend re-indexing will fix.
let p1 = conn2.priority;
let p2 = conn1.priority;
if (p1 === p2) {
// If moving conn1 "up" (index decreases)
const isConn1MovingUp = connections.indexOf(conn1) > connections.indexOf(conn2);
if (isConn1MovingUp) {
p1 = conn2.priority - 0.5;
} else {
p1 = conn2.priority + 0.5;
}
}
await Promise.all([
fetch(`/api/providers/${conn1.id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ priority: conn2.priority }),
body: JSON.stringify({ priority: p1 }),
}),
fetch(`/api/providers/${conn2.id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ priority: conn1.priority }),
body: JSON.stringify({ priority: p2 }),
}),
]);
await fetchConnections();