Repository navigation
fix(dashboard): write valid 1-based priorities when reordering connections - #16684
Merged
diegosouzapw merged 3 commits intoOct 15, 2026
Merged
Conversation
…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
Contributor
CI Coverage Report
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
priority ± 0.5, and "Reorder by availability" sent 0-based indices (first row →priority: 0).PUT /api/providers/:idonly 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.res.ok, show an error toast when a write fails, and refetch.Attribution
Thanks to @StevanusPangau for the original implementation.
Changes
connectionRowHelpers.ts:buildPriorityUpdatesturns a reordered list into 1-based positions and skips rows that are already in place.buildSwapPriorityUpdatesswaps 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.persistPriorityUpdatessends the PUTs in sequence and throws on the first non-OK response.useProviderConnections.ts(handleSwapPriority): uses the helpers, shows the existingfailedSaveConnectionRetrytoast 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 existingreorderByAvailabilityErrorpath 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 0connection-reorder-by-availability.test.tsandconnection-row-last-error-visibility.test.ts:ℹ tests 16 ℹ pass 16 ℹ fail 0updateProviderConnectionSchema.safeParse({priority})gives0 → false,0.5 → false,1.5 → false,1 → true(these were the old payloads)phase1f10/10,use-provider-connections-cursor-refresh5/5,codex-paid-credits-toggle3/3,connectionsSearchFilter10/10,batch-delete-click-event2/2.proxySaveRefresh.test.tsxtimes 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 0npm run typecheck:core: exit 0check-pr-test-policyandcheck:test-maskingpass (0 modificado(s) … sem enfraquecimento)