[PR #5214] [CLOSED] [Feature] Sort inbounds by sorting index. #5822

Closed
opened 2026-11-02 04:04:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5214
Author: @Ponywka
Created: 6/11/2026
Status: ❌ Closed

Base: main ← Head: feature/inbound-sorting


📝 Commits (4)

  • 2548041 feat(backend): add sorting index field to inbounds
  • c30756b feat(api): add sorting index field to inbounds
  • c7b305d feat(frontend): add sorting index to inbound edit modal and table
  • cd536db Merge branch 'main' into feature/inbound-sorting

📊 Changes

31 files changed (+419 additions, -9 deletions)

View changed files

📝 frontend/public/openapi.json (+6 -0)
📝 frontend/src/generated/examples.ts (+1 -0)
📝 frontend/src/generated/schemas.ts (+5 -0)
📝 frontend/src/generated/types.ts (+1 -0)
📝 frontend/src/generated/zod.ts (+1 -0)
📝 frontend/src/lib/xray/inbound-form-adapter.ts (+4 -0)
📝 frontend/src/models/dbinbound.ts (+3 -0)
📝 frontend/src/pages/inbounds/form/InboundFormModal.tsx (+8 -0)
📝 frontend/src/pages/inbounds/list/types.ts (+1 -0)
📝 frontend/src/pages/inbounds/list/useInboundColumns.tsx (+7 -0)
📝 frontend/src/schemas/forms/inbound-form.ts (+1 -0)
📝 frontend/src/test/__snapshots__/inbound-form-modal.test.tsx.snap (+10 -0)
📝 frontend/src/test/inbound-form-adapter.test.ts (+46 -1)
📝 internal/database/model/model.go (+1 -0)
📝 internal/sub/service.go (+1 -1)
📝 internal/web/service/inbound.go (+8 -7)
📝 internal/web/service/inbound_node.go (+1 -0)
➕ internal/web/service/inbound_sorting_test.go (+288 -0)
📝 internal/web/translation/ar-EG.json (+2 -0)
📝 internal/web/translation/en-US.json (+2 -0)

...and 11 more files

📄 Description

Summary

Adds a sortingIndex field to inbounds that lets operators control the display order of the inbound list.

Why

The inbound list previously returned results in insertion order, making it hard to keep related inbounds together or promote frequently-used entries to the top. A numeric sort index gives operators explicit control without requiring them recreate inbounds.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Manual UI test - inbound list ordering

I created 10 inbounds through the panel UI.

The first five were added in this order:

Created Remark Sorting index
1st Fourth (100) 100
2nd Second (-100) -100
3rd Third (0) 0
4th First (-200) -200
5th Fifth (200) 200

They were created out of order on purpose, to make sure the list is sorted by sortingIndex, not by creation order.

Then I added five more entries named Spacing, using the same sorting index values:

Remark Sorting index
Spacing -200
Spacing -100
Spacing 0
Spacing 100
Spacing 200

This was done to check the secondary ordering by id ASC when several inbounds have the same sortingIndex.

After saving, the inbound list was shown in this order:

Position Remark Sorting index
1 First (-200) -200
2 Spacing -200
3 Second (-100) -100
4 Spacing -100
5 Third (0) 0
6 Spacing 0
7 Fourth (100) 100
8 Spacing 100
9 Fifth (200) 200
10 Spacing 200

This confirms that inbounds are sorted by sorting_index ASC, and entries with the same value are sorted by id ASC.

Backend unit tests

Added 8 Go tests in internal/web/service/inbound_sorting_test.go.

Covered cases:

  • UpdateInbound saves SortingIndex, including an explicit 0
  • GetInbounds sorts by sorting_index ASC, then by id ASC
  • negative values are shown before 0 and positive values
  • GetAllInbounds, SearchInbounds, GetInboundTags, and GetInboundsByTrafficReset also respect sorting_index ASC

Frontend unit tests

Added 8 Vitest tests in src/test/inbound-form-adapter.test.ts.

Covered cases:

  • rawInboundToFormValues uses 0 when sortingIndex is missing
  • positive and negative sortingIndex values are preserved
  • formValuesToWirePayload includes sortingIndex in the payload
  • raw → values → payload keeps the value unchanged
  • InboundFormBaseSchema rejects values outside the allowed range (> 32767, < -32768)
  • non-integer values are rejected

Screenshots / recordings

Screenshot_20260612_022944

Breaking changes

GORM adds the sorting_index column automatically on first start (auto-migrate). Existing rows get DEFAULT 0, so all current inbounds share the same index and continue to sort by id ASC - identical to previous behavior. No manual migration or config change required.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5214 **Author:** [@Ponywka](https://github.com/Ponywka) **Created:** 6/11/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feature/inbound-sorting` --- ### 📝 Commits (4) - [`2548041`](https://github.com/MHSanaei/3x-ui/commit/25480411118c8efbefde040d856e8aa008338d03) feat(backend): add sorting index field to inbounds - [`c30756b`](https://github.com/MHSanaei/3x-ui/commit/c30756b3f81ab987446d338ab1ba07f4633acd8c) feat(api): add sorting index field to inbounds - [`c7b305d`](https://github.com/MHSanaei/3x-ui/commit/c7b305d725d6d7c635a7a3c03875506e868d31ab) feat(frontend): add sorting index to inbound edit modal and table - [`cd536db`](https://github.com/MHSanaei/3x-ui/commit/cd536dbcaae3903a59c164c2c3dbd538d08aef4b) Merge branch 'main' into feature/inbound-sorting ### 📊 Changes **31 files changed** (+419 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+6 -0) 📝 `frontend/src/generated/examples.ts` (+1 -0) 📝 `frontend/src/generated/schemas.ts` (+5 -0) 📝 `frontend/src/generated/types.ts` (+1 -0) 📝 `frontend/src/generated/zod.ts` (+1 -0) 📝 `frontend/src/lib/xray/inbound-form-adapter.ts` (+4 -0) 📝 `frontend/src/models/dbinbound.ts` (+3 -0) 📝 `frontend/src/pages/inbounds/form/InboundFormModal.tsx` (+8 -0) 📝 `frontend/src/pages/inbounds/list/types.ts` (+1 -0) 📝 `frontend/src/pages/inbounds/list/useInboundColumns.tsx` (+7 -0) 📝 `frontend/src/schemas/forms/inbound-form.ts` (+1 -0) 📝 `frontend/src/test/__snapshots__/inbound-form-modal.test.tsx.snap` (+10 -0) 📝 `frontend/src/test/inbound-form-adapter.test.ts` (+46 -1) 📝 `internal/database/model/model.go` (+1 -0) 📝 `internal/sub/service.go` (+1 -1) 📝 `internal/web/service/inbound.go` (+8 -7) 📝 `internal/web/service/inbound_node.go` (+1 -0) ➕ `internal/web/service/inbound_sorting_test.go` (+288 -0) 📝 `internal/web/translation/ar-EG.json` (+2 -0) 📝 `internal/web/translation/en-US.json` (+2 -0) _...and 11 more files_ </details> ### 📄 Description ## Summary Adds a `sortingIndex` field to inbounds that lets operators control the display order of the inbound list. ## Why The inbound list previously returned results in insertion order, making it hard to keep related inbounds together or promote frequently-used entries to the top. A numeric sort index gives operators explicit control without requiring them recreate inbounds. ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [x] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [x] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [x] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? **Manual UI test - inbound list ordering** I created 10 inbounds through the panel UI. The first five were added in this order: | Created | Remark | Sorting index | | ------- | ------------- | ------------- | | 1st | Fourth (100) | 100 | | 2nd | Second (-100) | -100 | | 3rd | Third (0) | 0 | | 4th | First (-200) | -200 | | 5th | Fifth (200) | 200 | They were created out of order on purpose, to make sure the list is sorted by `sortingIndex`, not by creation order. Then I added five more entries named `Spacing`, using the same sorting index values: | Remark | Sorting index | | ------- | ------------- | | Spacing | -200 | | Spacing | -100 | | Spacing | 0 | | Spacing | 100 | | Spacing | 200 | This was done to check the secondary ordering by `id ASC` when several inbounds have the same `sortingIndex`. After saving, the inbound list was shown in this order: | Position | Remark | Sorting index | | -------- | ------------- | ------------- | | 1 | First (-200) | -200 | | 2 | Spacing | -200 | | 3 | Second (-100) | -100 | | 4 | Spacing | -100 | | 5 | Third (0) | 0 | | 6 | Spacing | 0 | | 7 | Fourth (100) | 100 | | 8 | Spacing | 100 | | 9 | Fifth (200) | 200 | | 10 | Spacing | 200 | This confirms that inbounds are sorted by `sorting_index ASC`, and entries with the same value are sorted by `id ASC`. **Backend unit tests** Added 8 Go tests in `internal/web/service/inbound_sorting_test.go`. Covered cases: * `UpdateInbound` saves `SortingIndex`, including an explicit `0` * `GetInbounds` sorts by `sorting_index ASC`, then by `id ASC` * negative values are shown before `0` and positive values * `GetAllInbounds`, `SearchInbounds`, `GetInboundTags`, and `GetInboundsByTrafficReset` also respect `sorting_index ASC` **Frontend unit tests** Added 8 Vitest tests in `src/test/inbound-form-adapter.test.ts`. Covered cases: * `rawInboundToFormValues` uses `0` when `sortingIndex` is missing * positive and negative `sortingIndex` values are preserved * `formValuesToWirePayload` includes `sortingIndex` in the payload * `raw → values → payload` keeps the value unchanged * `InboundFormBaseSchema` rejects values outside the allowed range (`> 32767`, `< -32768`) * non-integer values are rejected ## Screenshots / recordings <img width="1833" height="611" alt="Screenshot_20260612_022944" src="https://github.com/user-attachments/assets/0ffca218-1bbf-46cf-a63e-fff1bce3f1d3" /> ## Breaking changes GORM adds the `sorting_index` column automatically on first start (auto-migrate). Existing rows get `DEFAULT 0`, so all current inbounds share the same index and continue to sort by id ASC - identical to previous behavior. No manual migration or config change required. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:20 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5822
No description provided.