Skip to content

fix(dashboard): write valid 1-based priorities when reordering connections - #16684

Merged
diegosouzapw merged 3 commits into
release/v3.8.52from
fix/port-pr-4280-connection-reorder-priority
Oct 15, 2026
Merged

diegosouzapw merged 3 commits into
release/v3.8.52from
fix/port-pr-4280-connection-reorder-priority

Conversation

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Summary

  • The ▲/▼ connection swap on tied priorities sent priority ± 0.5, and "Reorder by availability" sent 0-based indices (first row → priority: 0). PUT /api/providers/:id only accepts integers ≥ 1 (updateProviderConnectionSchema), so those writes got a 400 that nothing checked, and the saved order silently drifted from what the operator asked for.
  • Both paths now write valid 1-based integer priorities, send them one at a time, check res.ok, show an error toast when a write fails, and refetch.

Attribution

Thanks to @StevanusPangau for the original implementation.

Changes

  • connectionRowHelpers.ts: buildPriorityUpdates turns a reordered list into 1-based positions and skips rows that are already in place. buildSwapPriorityUpdates swaps the two stored values when they differ (so operator gaps like 10/20/30 survive); on a tie it rewrites the list 1..N with the pair exchanged. persistPriorityUpdates sends the PUTs in sequence and throws on the first non-OK response.
  • useProviderConnections.ts (handleSwapPriority): uses the helpers, shows the existing failedSaveConnectionRetry toast on failure (no new i18n keys) and always refetches. The file gets smaller (1194 → 1176 lines).
  • useReorderByAvailability.ts: writes 1-based priorities in sequence; the existing reorderByAvailabilityError path now actually fires when a write is rejected.
  • tests/unit/provider-connection-priority-updates.test.ts: new.

No API, DB or schema changes.

Test plan

  • node --import tsx/esm --test tests/unit/provider-connection-priority-updates.test.ts: fails before the fix (helpers missing); after the fix, ℹ tests 7 ℹ pass 7 ℹ fail 0
  • Same run plus connection-reorder-by-availability.test.ts and connection-row-last-error-visibility.test.ts: ℹ tests 16 ℹ pass 16 ℹ fail 0
  • Schema probe: updateProviderConnectionSchema.safeParse({priority}) gives 0 → false, 0.5 → false, 1.5 → false, 1 → true (these were the old payloads)
  • vitest UI, one file per run: phase1f 10/10, use-provider-connections-cursor-refresh 5/5, codex-paid-credits-toggle 3/3, connectionsSearchFilter 10/10, batch-delete-click-event 2/2. proxySaveRefresh.test.tsx times out at 30s with and without this change (checked with the base versions of the 3 files restored), so it is not caused by this PR.
  • npx eslint --suppressions-location config/quality/eslint-suppressions.json <changed files>: exit 0
  • npm run typecheck:core: exit 0
  • check-pr-test-policy and check:test-masking pass (0 modificado(s) … sem enfraquecimento)

⚠️ base-red inherited: #15306 — unit/vitest/integration/package-artifact gates on release/v3.8.52

diegosouzapw and others added 2 commits October 15, 2026 08:27
…tions

The ▲/▼ swap sent `priority ± 0.5` on tied rows and "Reorder by
availability" sent 0-based indices (first row → priority 0). The PUT
schema only accepts integers >= 1, so those writes were rejected with a
400 nobody checked and the saved order silently diverged.

- connectionRowHelpers: buildPriorityUpdates (1-based positions, skips
  rows already in place), buildSwapPriorityUpdates (value swap when
  priorities differ, full 1..N rewrite on a tie) and
  persistPriorityUpdates (sequential PUTs, throws on non-OK).
- Both hooks use the helpers, notify on failure and refetch.

Co-authored-by: Stevanus Pangau <stevanuspangau50@gmail.com>
Inspired-by: decolua/9router#4280
@github-actions

Copy link
Copy Markdown
Contributor

CI Coverage Report

  • Coverage job: skipped
  • PR test policy: success

Coverage artifact was not available for this run.

ConnectionRowConnection.id is optional. Emit a PriorityUpdate only after the id is present, so the reorder path typechecks and still writes 1-based integers.
@diegosouzapw
diegosouzapw merged commit 31c5b2c into release/v3.8.52 Oct 15, 2026
8 of 11 checks passed
@diegosouzapw
diegosouzapw deleted the fix/port-pr-4280-connection-reorder-priority branch October 18, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant